]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pkt-line: rename packet_write() to packet_write_fmt()
authorLars Schneider <larsxschneider@gmail.com>
Sun, 16 Oct 2016 23:20:29 +0000 (16:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Oct 2016 18:36:50 +0000 (11:36 -0700)
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>
builtin/archive.c
builtin/receive-pack.c
builtin/remote-ext.c
builtin/upload-archive.c
connect.c
daemon.c
http-backend.c
pkt-line.c
pkt-line.h
shallow.c
upload-pack.c

index a1e3b940c25ac20927d4daefa417d5b626e38a24..49f491413a172b3fa21e1f21f7cbdfedba785084 100644 (file)
@@ -47,10 +47,10 @@ static int run_remote_archiver(int argc, const char **argv,
        if (name_hint) {
                const char *format = archive_format_from_filename(name_hint);
                if (format)
-                       packet_write(fd[1], "argument --format=%s\n", format);
+                       packet_write_fmt(fd[1], "argument --format=%s\n", format);
        }
        for (i = 1; i < argc; i++)
-               packet_write(fd[1], "argument %s\n", argv[i]);
+               packet_write_fmt(fd[1], "argument %s\n", argv[i]);
        packet_flush(fd[1]);
 
        buf = packet_read_line(fd[0], NULL);
index f1ce05ce282361d8c49b1a447db90c13d5186674..173d081647cc699bb17657176d730dc6b5139ea7 100644 (file)
@@ -224,7 +224,7 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 static void show_ref(const char *path, const unsigned char *sha1)
 {
        if (sent_capabilities) {
-               packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
+               packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path);
        } else {
                struct strbuf cap = STRBUF_INIT;
 
@@ -239,7 +239,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
                if (advertise_push_options)
                        strbuf_addstr(&cap, " push-options");
                strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
-               packet_write(1, "%s %s%c%s\n",
+               packet_write_fmt(1, "%s %s%c%s\n",
                             sha1_to_hex(sha1), path, 0, cap.buf);
                strbuf_release(&cap);
                sent_capabilities = 1;
index 88eb8f901367aceffa008cf33b35ca8bee848626..11b48bfb41193387d53588c879ee50431f77b9cd 100644 (file)
@@ -128,9 +128,9 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
        const char *vhost)
 {
        if (!vhost)
-               packet_write(stdin_fd, "%s %s%c", serv, repo, 0);
+               packet_write_fmt(stdin_fd, "%s %s%c", serv, repo, 0);
        else
-               packet_write(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
+               packet_write_fmt(stdin_fd, "%s %s%chost=%s%c", serv, repo, 0,
                             vhost, 0);
 }
 
index 2caedf184959e2120d8e30a02f885925ceb412b4..dc872f6a94c09f4390b5898aa499885d7700c737 100644 (file)
@@ -88,11 +88,11 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
        writer.git_cmd = 1;
        if (start_command(&writer)) {
                int err = errno;
-               packet_write(1, "NACK unable to spawn subprocess\n");
+               packet_write_fmt(1, "NACK unable to spawn subprocess\n");
                die("upload-archive: %s", strerror(err));
        }
 
-       packet_write(1, "ACK\n");
+       packet_write_fmt(1, "ACK\n");
        packet_flush(1);
 
        while (1) {
index 722dc3fc546056be199f5d6a59c556833be58286..5330d9c1629607e335e056180794ab27b5b42277 100644 (file)
--- a/connect.c
+++ b/connect.c
@@ -730,7 +730,7 @@ struct child_process *git_connect(int fd[2], const char *url,
                 * Note: Do not add any other headers here!  Doing so
                 * will cause older git-daemon servers to crash.
                 */
-               packet_write(fd[1],
+               packet_write_fmt(fd[1],
                             "%s %s%chost=%s%c",
                             prog, path, 0,
                             target_host, 0);
index 425aad0507f48ca07b11faa05828ea841bdd302f..afce1b9b7f8d2846a8c99855f1e20d0398a31c47 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -281,7 +281,7 @@ static int daemon_error(const char *dir, const char *msg)
 {
        if (!informative_errors)
                msg = "access denied or repository not exported";
-       packet_write(1, "ERR %s: %s", msg, dir);
+       packet_write_fmt(1, "ERR %s: %s", msg, dir);
        return -1;
 }
 
index adc8c8c3da6aaabe9f279b2a9841fc924ae39c1d..eef0a361f4f9bcc7f8fb278268334cb40a32fcb3 100644 (file)
@@ -464,7 +464,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg)
                hdr_str(hdr, content_type, buf.buf);
                end_headers(hdr);
 
-               packet_write(1, "# service=git-%s\n", svc->name);
+               packet_write_fmt(1, "# service=git-%s\n", svc->name);
                packet_flush(1);
 
                argv[0] = svc->name;
index 30489c60b1d3f8acc002fad31aa68b528757c8da..eeb8046aca88c2c7b664f24035135947718e96f9 100644 (file)
@@ -118,7 +118,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
        packet_trace(out->buf + orig_len + 4, n - 4, 1);
 }
 
-void packet_write(int fd, const char *fmt, ...)
+void packet_write_fmt(int fd, const char *fmt, ...)
 {
        static struct strbuf buf = STRBUF_INIT;
        va_list args;
index 3cb9d91baaa5bbd09e1ca55e8754e1c4edb6bd97..1902fb37bb187c2e10d4fd54e2dc379d155f13e3 100644 (file)
@@ -20,7 +20,7 @@
  * side can't, we stay with pure read/write interfaces.
  */
 void packet_flush(int fd);
-void packet_write(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
+void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 void packet_buf_flush(struct strbuf *buf);
 void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 
index 54e2db73349ef22d644552c6b122ae5ed6ba2ce1..d666e24f1255738670d3251c82595e133a9c19ff 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -260,7 +260,7 @@ static int advertise_shallow_grafts_cb(const struct commit_graft *graft, void *c
 {
        int fd = *(int *)cb;
        if (graft->nr_parent == -1)
-               packet_write(fd, "shallow %s\n", oid_to_hex(&graft->oid));
+               packet_write_fmt(fd, "shallow %s\n", oid_to_hex(&graft->oid));
        return 0;
 }
 
index ca7f9417800bfb27a7dbc0559df8bec772c267fa..cd47de69ab4da0cdb82fe71cda9a82ff0334561a 100644 (file)
@@ -393,13 +393,13 @@ static int get_common_commits(void)
                        if (multi_ack == 2 && got_common
                            && !got_other && ok_to_give_up()) {
                                sent_ready = 1;
-                               packet_write(1, "ACK %s ready\n", last_hex);
+                               packet_write_fmt(1, "ACK %s ready\n", last_hex);
                        }
                        if (have_obj.nr == 0 || multi_ack)
-                               packet_write(1, "NAK\n");
+                               packet_write_fmt(1, "NAK\n");
 
                        if (no_done && sent_ready) {
-                               packet_write(1, "ACK %s\n", last_hex);
+                               packet_write_fmt(1, "ACK %s\n", last_hex);
                                return 0;
                        }
                        if (stateless_rpc)
@@ -416,20 +416,20 @@ static int get_common_commits(void)
                                        const char *hex = sha1_to_hex(sha1);
                                        if (multi_ack == 2) {
                                                sent_ready = 1;
-                                               packet_write(1, "ACK %s ready\n", hex);
+                                               packet_write_fmt(1, "ACK %s ready\n", hex);
                                        } else
-                                               packet_write(1, "ACK %s continue\n", hex);
+                                               packet_write_fmt(1, "ACK %s continue\n", hex);
                                }
                                break;
                        default:
                                got_common = 1;
                                memcpy(last_hex, sha1_to_hex(sha1), 41);
                                if (multi_ack == 2)
-                                       packet_write(1, "ACK %s common\n", last_hex);
+                                       packet_write_fmt(1, "ACK %s common\n", last_hex);
                                else if (multi_ack)
-                                       packet_write(1, "ACK %s continue\n", last_hex);
+                                       packet_write_fmt(1, "ACK %s continue\n", last_hex);
                                else if (have_obj.nr == 1)
-                                       packet_write(1, "ACK %s\n", last_hex);
+                                       packet_write_fmt(1, "ACK %s\n", last_hex);
                                break;
                        }
                        continue;
@@ -437,10 +437,10 @@ static int get_common_commits(void)
                if (!strcmp(line, "done")) {
                        if (have_obj.nr > 0) {
                                if (multi_ack)
-                                       packet_write(1, "ACK %s\n", last_hex);
+                                       packet_write_fmt(1, "ACK %s\n", last_hex);
                                return 0;
                        }
-                       packet_write(1, "NAK\n");
+                       packet_write_fmt(1, "NAK\n");
                        return -1;
                }
                die("git upload-pack: expected SHA1 list, got '%s'", line);
@@ -650,7 +650,7 @@ static void receive_needs(void)
                while (result) {
                        struct object *object = &result->item->object;
                        if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
-                               packet_write(1, "shallow %s",
+                               packet_write_fmt(1, "shallow %s",
                                                oid_to_hex(&object->oid));
                                register_shallow(object->oid.hash);
                                shallow_nr++;
@@ -662,7 +662,7 @@ static void receive_needs(void)
                        struct object *object = shallows.objects[i].item;
                        if (object->flags & NOT_SHALLOW) {
                                struct commit_list *parents;
-                               packet_write(1, "unshallow %s",
+                               packet_write_fmt(1, "unshallow %s",
                                        oid_to_hex(&object->oid));
                                object->flags &= ~CLIENT_SHALLOW;
                                /* make sure the real parents are parsed */
@@ -741,7 +741,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
                struct strbuf symref_info = STRBUF_INIT;
 
                format_symref_info(&symref_info, cb_data);
-               packet_write(1, "%s %s%c%s%s%s%s%s agent=%s\n",
+               packet_write_fmt(1, "%s %s%c%s%s%s%s%s agent=%s\n",
                             oid_to_hex(oid), refname_nons,
                             0, capabilities,
                             (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
@@ -753,11 +753,11 @@ static int send_ref(const char *refname, const struct object_id *oid,
                             git_user_agent_sanitized());
                strbuf_release(&symref_info);
        } else {
-               packet_write(1, "%s %s\n", oid_to_hex(oid), refname_nons);
+               packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
        }
        capabilities = NULL;
        if (!peel_ref(refname, peeled.hash))
-               packet_write(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
+               packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
        return 0;
 }