Merge branch 'jk/printf-format'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Jul 2016 20:22:22 +0000 (13:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Jul 2016 20:22:22 +0000 (13:22 -0700)
Code clean-up to avoid using a variable string that compilers may
feel untrustable as printf-style format given to write_file()
helper function.

* jk/printf-format:
commit.c: remove print_commit_list()
avoid using sha1_to_hex output as printf format
walker: let walker_say take arbitrary formats

bisect.c
builtin/worktree.c
commit.c
commit.h
walker.c
walker.h
index 47cccdfb0dae4a4a4bc09461c00f0d46db9c3c81..6f512c20638718df91ed4a29aae3518f985c0d30 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -646,7 +646,10 @@ static void exit_if_skipped_commits(struct commit_list *tried,
 
        printf("There are only 'skip'ped commits left to test.\n"
               "The first %s commit could be any of:\n", term_bad);
-       print_commit_list(tried, "%s\n", "%s\n");
+
+       for ( ; tried; tried = tried->next)
+               printf("%s\n", oid_to_hex(&tried->item->object.oid));
+
        if (bad)
                printf("%s\n", oid_to_hex(bad));
        printf(_("We cannot bisect more!\n"));
index e866844685d519e2406c050da497c42506077f7d..cce555cbbc8a58b41789990402d756d7d4aa337a 100644 (file)
@@ -262,7 +262,7 @@ static int add_worktree(const char *path, const char *refname,
         */
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
-       write_file(sb.buf, sha1_to_hex(null_sha1));
+       write_file(sb.buf, "%s", sha1_to_hex(null_sha1));
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
        write_file(sb.buf, "../..");
index 2a90e37519f0b6e9de6e30ed57afe91822441ca3..71a360dad384f33b7b6a6c29ed16d7823fc53961 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1622,16 +1622,6 @@ struct commit_list **commit_list_append(struct commit *commit,
        return &new->next;
 }
 
-void print_commit_list(struct commit_list *list,
-                      const char *format_cur,
-                      const char *format_last)
-{
-       for ( ; list; list = list->next) {
-               const char *format = list->next ? format_cur : format_last;
-               printf(format, oid_to_hex(&list->item->object.oid));
-       }
-}
-
 const char *find_commit_header(const char *msg, const char *key, size_t *out_len)
 {
        int key_len = strlen(key);
index 3b88c8889db0f1b0e1f6ba2b6d504bb18fed13a2..23ae0c1d642c1b83ed0af383625e48bce710b10b 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -377,10 +377,6 @@ extern int parse_signed_commit(const struct commit *commit,
                               struct strbuf *message, struct strbuf *signature);
 extern int remove_signature(struct strbuf *buf);
 
-extern void print_commit_list(struct commit_list *list,
-                             const char *format_cur,
-                             const char *format_last);
-
 /*
  * Check the signature of the given commit. The result of the check is stored
  * in sig->check_result, 'G' for a good signature, 'U' for a good signature
index d95b007294c84dafcc391edb7813c15523b03633..2c86e406f92d9bf0063e6be4f9d76fdbbac17c89 100644 (file)
--- a/walker.c
+++ b/walker.c
@@ -9,10 +9,14 @@
 
 static unsigned char current_commit_sha1[20];
 
-void walker_say(struct walker *walker, const char *fmt, const char *hex)
+void walker_say(struct walker *walker, const char *fmt, ...)
 {
-       if (walker->get_verbosely)
-               fprintf(stderr, fmt, hex);
+       if (walker->get_verbosely) {
+               va_list ap;
+               va_start(ap, fmt);
+               vfprintf(stderr, fmt, ap);
+               va_end(ap);
+       }
 }
 
 static void report_missing(const struct object *obj)
index 95e576548474e942addcf1978f215720dd2f6e96..a869013e85110a0b64d8fe344c8bd67f5e8f7f09 100644 (file)
--- a/walker.h
+++ b/walker.h
@@ -19,7 +19,8 @@ struct walker {
 };
 
 /* Report what we got under get_verbosely */
-void walker_say(struct walker *walker, const char *, const char *);
+__attribute__((format (printf, 2, 3)))
+void walker_say(struct walker *walker, const char *fmt, ...);
 
 /* Load pull targets from stdin */
 int walker_targets_stdin(char ***target, const char ***write_ref);