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

1  2 
bisect.c
commit.c
commit.h
diff --combined bisect.c
index 47cccdfb0dae4a4a4bc09461c00f0d46db9c3c81,02f76f0f5df9e3156be037578c79ab2acc15592f..6f512c20638718df91ed4a29aae3518f985c0d30
+++ b/bisect.c
@@@ -438,12 -438,12 +438,12 @@@ static void read_bisect_paths(struct ar
        FILE *fp = fopen(filename, "r");
  
        if (!fp)
 -              die_errno("Could not open file '%s'", filename);
 +              die_errno(_("Could not open file '%s'"), filename);
  
        while (strbuf_getline_lf(&str, fp) != EOF) {
                strbuf_trim(&str);
                if (sq_dequote_to_argv_array(str.buf, array))
 -                      die("Badly quoted content in file '%s': %s",
 +                      die(_("Badly quoted content in file '%s': %s"),
                            filename, str.buf);
        }
  
@@@ -646,10 -646,13 +646,13 @@@ static void exit_if_skipped_commits(str
  
        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");
 +      printf(_("We cannot bisect more!\n"));
        exit(2);
  }
  
@@@ -702,7 -705,7 +705,7 @@@ static struct commit *get_commit_refere
  {
        struct commit *r = lookup_commit_reference(sha1);
        if (!r)
 -              die("Not a valid commit name %s", sha1_to_hex(sha1));
 +              die(_("Not a valid commit name %s"), sha1_to_hex(sha1));
        return r;
  }
  
@@@ -726,27 -729,27 +729,27 @@@ static void handle_bad_merge_base(void
                char *bad_hex = oid_to_hex(current_bad_oid);
                char *good_hex = join_sha1_array_hex(&good_revs, ' ');
                if (!strcmp(term_bad, "bad") && !strcmp(term_good, "good")) {
 -                      fprintf(stderr, "The merge base %s is bad.\n"
 +                      fprintf(stderr, _("The merge base %s is bad.\n"
                                "This means the bug has been fixed "
 -                              "between %s and [%s].\n",
 +                              "between %s and [%s].\n"),
                                bad_hex, bad_hex, good_hex);
                } else if (!strcmp(term_bad, "new") && !strcmp(term_good, "old")) {
 -                      fprintf(stderr, "The merge base %s is new.\n"
 +                      fprintf(stderr, _("The merge base %s is new.\n"
                                "The property has changed "
 -                              "between %s and [%s].\n",
 +                              "between %s and [%s].\n"),
                                bad_hex, bad_hex, good_hex);
                } else {
 -                      fprintf(stderr, "The merge base %s is %s.\n"
 +                      fprintf(stderr, _("The merge base %s is %s.\n"
                                "This means the first '%s' commit is "
 -                              "between %s and [%s].\n",
 +                              "between %s and [%s].\n"),
                                bad_hex, term_bad, term_good, bad_hex, good_hex);
                }
                exit(3);
        }
  
 -      fprintf(stderr, "Some %s revs are not ancestor of the %s rev.\n"
 +      fprintf(stderr, _("Some %s revs are not ancestor of the %s rev.\n"
                "git bisect cannot work properly in this case.\n"
 -              "Maybe you mistook %s and %s revs?\n",
 +              "Maybe you mistook %s and %s revs?\n"),
                term_good, term_bad, term_good, term_bad);
        exit(1);
  }
  static void handle_skipped_merge_base(const unsigned char *mb)
  {
        char *mb_hex = sha1_to_hex(mb);
 -      char *bad_hex = sha1_to_hex(current_bad_oid->hash);
 +      char *bad_hex = oid_to_hex(current_bad_oid);
        char *good_hex = join_sha1_array_hex(&good_revs, ' ');
  
 -      warning("the merge base between %s and [%s] "
 +      warning(_("the merge base between %s and [%s] "
                "must be skipped.\n"
                "So we cannot be sure the first %s commit is "
                "between %s and %s.\n"
 -              "We continue anyway.",
 +              "We continue anyway."),
                bad_hex, good_hex, term_bad, mb_hex, bad_hex);
        free(good_hex);
  }
@@@ -792,7 -795,7 +795,7 @@@ static void check_merge_bases(int no_ch
                } else if (0 <= sha1_array_lookup(&skipped_revs, mb)) {
                        handle_skipped_merge_base(mb);
                } else {
 -                      printf("Bisecting: a merge base must be tested\n");
 +                      printf(_("Bisecting: a merge base must be tested\n"));
                        exit(bisect_checkout(mb, no_checkout));
                }
        }
@@@ -843,7 -846,7 +846,7 @@@ static void check_good_are_ancestors_of
        int fd;
  
        if (!current_bad_oid)
 -              die("a %s revision is needed", term_bad);
 +              die(_("a %s revision is needed"), term_bad);
  
        /* Check if file BISECT_ANCESTORS_OK exists. */
        if (!stat(filename, &st) && S_ISREG(st.st_mode))
        /* Create file BISECT_ANCESTORS_OK. */
        fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600);
        if (fd < 0)
 -              warning_errno("could not create file '%s'",
 +              warning_errno(_("could not create file '%s'"),
                              filename);
        else
                close(fd);
@@@ -911,7 -914,7 +914,7 @@@ void read_bisect_terms(const char **rea
                        *read_good = "good";
                        return;
                } else {
 -                      die_errno("could not read file '%s'", filename);
 +                      die_errno(_("could not read file '%s'"), filename);
                }
        } else {
                strbuf_getline_lf(&str, fp);
@@@ -937,11 -940,10 +940,11 @@@ int bisect_next_all(const char *prefix
        struct commit_list *tried;
        int reaches = 0, all = 0, nr, steps;
        const unsigned char *bisect_rev;
 +      char steps_msg[32];
  
        read_bisect_terms(&term_bad, &term_good);
        if (read_bisect_refs())
 -              die("reading bisect refs failed");
 +              die(_("reading bisect refs failed"));
  
        check_good_are_ancestors_of_bad(prefix, no_checkout);
  
                 */
                exit_if_skipped_commits(tried, NULL);
  
 -              printf("%s was both %s and %s\n",
 +              printf(_("%s was both %s and %s\n"),
                       oid_to_hex(current_bad_oid),
                       term_good,
                       term_bad);
        }
  
        if (!all) {
 -              fprintf(stderr, "No testable commit found.\n"
 -                      "Maybe you started with bad path parameters?\n");
 +              fprintf(stderr, _("No testable commit found.\n"
 +                      "Maybe you started with bad path parameters?\n"));
                exit(4);
        }
  
  
        nr = all - reaches - 1;
        steps = estimate_bisect_steps(all);
 -      printf("Bisecting: %d revision%s left to test after this "
 -             "(roughly %d step%s)\n", nr, (nr == 1 ? "" : "s"),
 -             steps, (steps == 1 ? "" : "s"));
 +      xsnprintf(steps_msg, sizeof(steps_msg),
 +                Q_("(roughly %d step)", "(roughly %d steps)", steps),
 +                steps);
 +      /* TRANSLATORS: the last %s will be replaced with
 +         "(roughly %d steps)" translation */
 +      printf(Q_("Bisecting: %d revision left to test after this %s\n",
 +                "Bisecting: %d revisions left to test after this %s\n",
 +                nr), nr, steps_msg);
  
        return bisect_checkout(bisect_rev, no_checkout);
  }
diff --combined commit.c
index 2a90e37519f0b6e9de6e30ed57afe91822441ca3,bf279725339fe9778042d596d09ad984ad9be2d0..71a360dad384f33b7b6a6c29ed16d7823fc53961
+++ b/commit.c
@@@ -414,7 -414,7 +414,7 @@@ int find_commit_subject(const char *com
        while (*p && (*p != '\n' || p[1] != '\n'))
                p++;
        if (*p) {
 -              p += 2;
 +              p = skip_blank_lines(p + 2);
                for (eol = p; *eol && *eol != '\n'; eol++)
                        ; /* do nothing */
        } else
@@@ -1092,14 -1092,9 +1092,14 @@@ static int do_sign_commit(struct strbu
  {
        struct strbuf sig = STRBUF_INIT;
        int inspos, copypos;
 +      const char *eoh;
  
        /* find the end of the header */
 -      inspos = strstr(buf->buf, "\n\n") - buf->buf + 1;
 +      eoh = strstr(buf->buf, "\n\n");
 +      if (!eoh)
 +              inspos = buf->len;
 +      else
 +              inspos = eoh - buf->buf + 1;
  
        if (!keyid || !*keyid)
                keyid = get_signing_key();
@@@ -1622,16 -1617,6 +1622,6 @@@ struct commit_list **commit_list_append
        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 --combined commit.h
index 3b88c8889db0f1b0e1f6ba2b6d504bb18fed13a2,71693ce0fd9613320114586a3c23d309e8427368..23ae0c1d642c1b83ed0af383625e48bce710b10b
+++ b/commit.h
@@@ -184,7 -184,6 +184,7 @@@ extern const char *format_subject(struc
                                  const char *line_separator);
  extern void userformat_find_requirements(const char *fmt, struct userformat_want *w);
  extern int commit_format_is_empty(enum cmit_fmt);
 +extern const char *skip_blank_lines(const char *msg);
  extern void format_commit_message(const struct commit *commit,
                                  const char *format, struct strbuf *sb,
                                  const struct pretty_print_context *context);
@@@ -377,10 -376,6 +377,6 @@@ extern int parse_signed_commit(const st
                               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