pkt-line: rename packet_write() to packet_write_fmt()

packet_write() should be called packet_write_fmt() because it is a printf-like function that takes a format string as first parameter. packet_write_fmt() should be used for text strings only. Arbitrary binary data should use a new packet_write() function that is introduced in a subsequent patch. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Schneider committed Oct 16, 2016 at 16:20 UTC 81c634e94f2fef0cec295f7554080c82bd6aeeb7
11 files changed +29 -29
builtin/archive.c
+2 -2
@@ -47,10 +47,10 @@ static int run_remote_archiver(int argc, const char **argv,
47 if (name_hint) {
48 const char *format = archive_format_from_filename(name_hint);
49 if (format)
50 - packet_write(fd[1], "argument --format=%s\n", format);
50 + packet_write_fmt(fd[1], "argument --format=%s\n", format);
51 }
52 for (i = 1; i < argc; i++)
53 - packet_write(fd[1], "argument %s\n", argv[i]);
53 + packet_write_fmt(fd[1], "argument %s\n", argv[i]);
54 packet_flush(fd[1]);
55
56 buf = packet_read_line(fd[0], NULL);
builtin/receive-pack.c
+2 -2
@@ -224,7 +224,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
224 static void show_ref(const char *path, const unsigned char *sha1)
225 {
226 if (sent_capabilities) {
227 - packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
227 + packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path);
228 } else {
229 struct strbuf cap = STRBUF_INIT;
230
@@ -239,7 +239,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
239 if (advertise_push_options)
240 strbuf_addstr(&cap, " push-options");
241 strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
242 - packet_write(1, "%s %s%c%s\n",
242 + packet_write_fmt(1, "%s %s%c%s\n",
243 sha1_to_hex(sha1), path, 0, cap.buf);
244 strbuf_release(&cap);
245 sent_capabilities = 1;
builtin/remote-ext.c
+2 -2
@@ -128,9 +128,9 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
128 const char *vhost)
129 {
130 if (!vhost)
131 - packet_write(stdin_fd, "%s %s%c", serv, repo, 0);
131 + packet_write_fmt(stdin_fd, "%s %s%c", serv, repo, 0);
132 else
133 - packet_write(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
133 + packet_write_fmt(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
134 vhost, 0);
135 }
136
builtin/upload-archive.c
+2 -2
@@ -88,11 +88,11 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
88 writer.git_cmd = 1;
89 if (start_command(&writer)) {
90 int err = errno;
91 - packet_write(1, "NACK unable to spawn subprocess\n");
91 + packet_write_fmt(1, "NACK unable to spawn subprocess\n");
92 die("upload-archive: %s", strerror(err));
93 }
94
95 - packet_write(1, "ACK\n");
95 + packet_write_fmt(1, "ACK\n");
96 packet_flush(1);
97
98 while (1) {
connect.c
+1 -1
@@ -730,7 +730,7 @@ struct child_process *git_connect(int fd[2], const char *url,
730 * Note: Do not add any other headers here! Doing so
731 * will cause older git-daemon servers to crash.
732 */
733 - packet_write(fd[1],
733 + packet_write_fmt(fd[1],
734 "%s %s%chost=%s%c",
735 prog, path, 0,
736 target_host, 0);
daemon.c
+1 -1
@@ -281,7 +281,7 @@ static int daemon_error(const char *dir, const char *msg)
281 {
282 if (!informative_errors)
283 msg = "access denied or repository not exported";
284 - packet_write(1, "ERR %s: %s", msg, dir);
284 + packet_write_fmt(1, "ERR %s: %s", msg, dir);
285 return -1;
286 }
287
http-backend.c
+1 -1
@@ -464,7 +464,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg)
464 hdr_str(hdr, content_type, buf.buf);
465 end_headers(hdr);
466
467 - packet_write(1, "# service=git-%s\n", svc->name);
467 + packet_write_fmt(1, "# service=git-%s\n", svc->name);
468 packet_flush(1);
469
470 argv[0] = svc->name;
pkt-line.c
+1 -1
@@ -118,7 +118,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
118 packet_trace(out->buf + orig_len + 4, n - 4, 1);
119 }
120
121 -void packet_write(int fd, const char *fmt, ...)
121 +void packet_write_fmt(int fd, const char *fmt, ...)
122 {
123 static struct strbuf buf = STRBUF_INIT;
124 va_list args;
pkt-line.h
+1 -1
@@ -20,7 +20,7 @@
20 * side can't, we stay with pure read/write interfaces.
21 */
22 void packet_flush(int fd);
23 -void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
23 +void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
24 void packet_buf_flush(struct strbuf *buf);
25 void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
26
shallow.c
+1 -1
@@ -260,7 +260,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
260 {
261 int fd = *(int *)cb;
262 if (graft->nr_parent == -1)
263 - packet_write(fd, "shallow %s\n", oid_to_hex(&graft->oid));
263 + packet_write_fmt(fd, "shallow %s\n", oid_to_hex(&graft->oid));
264 return 0;
265 }
266
upload-pack.c
+15 -15
@@ -393,13 +393,13 @@ static int get_common_commits(void)
393 if (multi_ack == 2 && got_common
394 && !got_other && ok_to_give_up()) {
395 sent_ready = 1;
396 - packet_write(1, "ACK %s ready\n", last_hex);
396 + packet_write_fmt(1, "ACK %s ready\n", last_hex);
397 }
398 if (have_obj.nr == 0 || multi_ack)
399 - packet_write(1, "NAK\n");
399 + packet_write_fmt(1, "NAK\n");
400
401 if (no_done && sent_ready) {
402 - packet_write(1, "ACK %s\n", last_hex);
402 + packet_write_fmt(1, "ACK %s\n", last_hex);
403 return 0;
404 }
405 if (stateless_rpc)
@@ -416,20 +416,20 @@ static int get_common_commits(void)
416 const char *hex = sha1_to_hex(sha1);
417 if (multi_ack == 2) {
418 sent_ready = 1;
419 - packet_write(1, "ACK %s ready\n", hex);
419 + packet_write_fmt(1, "ACK %s ready\n", hex);
420 } else
421 - packet_write(1, "ACK %s continue\n", hex);
421 + packet_write_fmt(1, "ACK %s continue\n", hex);
422 }
423 break;
424 default:
425 got_common = 1;
426 memcpy(last_hex, sha1_to_hex(sha1), 41);
427 if (multi_ack == 2)
428 - packet_write(1, "ACK %s common\n", last_hex);
428 + packet_write_fmt(1, "ACK %s common\n", last_hex);
429 else if (multi_ack)
430 - packet_write(1, "ACK %s continue\n", last_hex);
430 + packet_write_fmt(1, "ACK %s continue\n", last_hex);
431 else if (have_obj.nr == 1)
432 - packet_write(1, "ACK %s\n", last_hex);
432 + packet_write_fmt(1, "ACK %s\n", last_hex);
433 break;
434 }
435 continue;
@@ -437,10 +437,10 @@ static int get_common_commits(void)
437 if (!strcmp(line, "done")) {
438 if (have_obj.nr > 0) {
439 if (multi_ack)
440 - packet_write(1, "ACK %s\n", last_hex);
440 + packet_write_fmt(1, "ACK %s\n", last_hex);
441 return 0;
442 }
443 - packet_write(1, "NAK\n");
443 + packet_write_fmt(1, "NAK\n");
444 return -1;
445 }
446 die("git upload-pack: expected SHA1 list, got '%s'", line);
@@ -650,7 +650,7 @@ static void receive_needs(void)
650 while (result) {
651 struct object *object = &result->item->object;
652 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
653 - packet_write(1, "shallow %s",
653 + packet_write_fmt(1, "shallow %s",
654 oid_to_hex(&object->oid));
655 register_shallow(object->oid.hash);
656 shallow_nr++;
@@ -662,7 +662,7 @@ static void receive_needs(void)
662 struct object *object = shallows.objects[i].item;
663 if (object->flags & NOT_SHALLOW) {
664 struct commit_list *parents;
665 - packet_write(1, "unshallow %s",
665 + packet_write_fmt(1, "unshallow %s",
666 oid_to_hex(&object->oid));
667 object->flags &= ~CLIENT_SHALLOW;
668 /* make sure the real parents are parsed */
@@ -741,7 +741,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
741 struct strbuf symref_info = STRBUF_INIT;
742
743 format_symref_info(&symref_info, cb_data);
744 - packet_write(1, "%s %s%c%s%s%s%s%s agent=%s\n",
744 + packet_write_fmt(1, "%s %s%c%s%s%s%s%s agent=%s\n",
745 oid_to_hex(oid), refname_nons,
746 0, capabilities,
747 (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
@@ -753,11 +753,11 @@ static int send_ref(const char *refname, const struct object_id *oid,
753 git_user_agent_sanitized());
754 strbuf_release(&symref_info);
755 } else {
756 - packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons);
756 + packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
757 }
758 capabilities = NULL;
759 if (!peel_ref(refname, peeled.hash))
760 - packet_write(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
760 + packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
761 return 0;
762 }
763