From fa262cac766d383c51e0ead04c62e114a79bd738 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 8 Jul 2016 05:25:23 -0400 Subject: walker: let walker_say take arbitrary formats We take a printf-style format and a single "char *" parameter, and the format must therefore have at most one "%s" in it. Besides being error-prone (and tickling -Wformat-nonliteral), this is unnecessarily restrictive. We can just provide the usual varargs interface. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/walker.c b/walker.c index d95b007..2c86e40 100644 --- 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) diff --git a/walker.h b/walker.h index 95e5765..a869013 100644 --- 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); -- cgit v0.10.2-6-g49f6 From dabd35f4cdd8bcfa502d082da5a3e4b927a2b329 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 8 Jul 2016 06:35:15 -0400 Subject: avoid using sha1_to_hex output as printf format We know that it should not contain any percent-signs, but it's a good habit not to feed non-literals to printf formatters. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/builtin/worktree.c b/builtin/worktree.c index e866844..cce555c 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -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, "../.."); -- cgit v0.10.2-6-g49f6 From 54307ea7c3ced760ee375483a786ec7180798aed Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jul 2016 10:09:28 -0700 Subject: commit.c: remove print_commit_list() The helper function tries to offer a way to conveniently show the last one differently from others, presumably to allow you to say something like A, B, and C. while iterating over a list that has these three elements. However, there is only one caller, and it passes the same format string "%s\n" for both the last one and the other ones. Retire the helper function and update the caller with a simplified version. Signed-off-by: Junio C Hamano diff --git a/bisect.c b/bisect.c index dc13319..02f76f0 100644 --- 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"); diff --git a/commit.c b/commit.c index 3f4f371..bf27972 100644 --- a/commit.c +++ b/commit.c @@ -1617,16 +1617,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); diff --git a/commit.h b/commit.h index 78ed513..71693ce 100644 --- a/commit.h +++ b/commit.h @@ -376,10 +376,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 -- cgit v0.10.2-6-g49f6