X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=bisect.c;h=aaab6ada2b620e10af5dff2ea894ecf3d44ac9ea;hb=cf8899d285d2648013040ec7196ffd3de0606664;hp=041a13d093a21597c60d799c0f6943998f2d6a8a;hpb=ab37a18b60b4f061de8239256589faeaab630ff8;p=git-core%2Fgit.git diff --git a/bisect.c b/bisect.c index 041a13d09..aaab6ada2 100644 --- a/bisect.c +++ b/bisect.c @@ -12,8 +12,8 @@ #include "sha1-array.h" #include "argv-array.h" -static struct sha1_array good_revs; -static struct sha1_array skipped_revs; +static struct oid_array good_revs; +static struct oid_array skipped_revs; static struct object_id *current_bad_oid; @@ -193,13 +193,14 @@ static int compare_commit_dist(const void *a_, const void *b_) b = (struct commit_dist *)b_; if (a->distance != b->distance) return b->distance - a->distance; /* desc sort */ - return hashcmp(a->commit->object.sha1, b->commit->object.sha1); + return oidcmp(&a->commit->object.oid, &b->commit->object.oid); } static struct commit_list *best_bisection_sorted(struct commit_list *list, int nr) { struct commit_list *p; struct commit_dist *array = xcalloc(nr, sizeof(*array)); + struct strbuf buf = STRBUF_INIT; int cnt, i; for (p = list, cnt = 0; p; p = p->next) { @@ -215,19 +216,20 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n array[cnt].distance = distance; cnt++; } - qsort(array, cnt, sizeof(*array), compare_commit_dist); + QSORT(array, cnt, compare_commit_dist); for (p = list, i = 0; i < cnt; i++) { - char buf[100]; /* enough for dist=%d */ struct object *obj = &(array[i].commit->object); - snprintf(buf, sizeof(buf), "dist=%d", array[i].distance); - add_name_decoration(DECORATION_NONE, buf, obj); + strbuf_reset(&buf); + strbuf_addf(&buf, "dist=%d", array[i].distance); + add_name_decoration(DECORATION_NONE, buf.buf, obj); p->item = array[i].commit; p = p->next; } if (p) p->next = NULL; + strbuf_release(&buf); free(array); return list; } @@ -413,9 +415,9 @@ static int register_ref(const char *refname, const struct object_id *oid, current_bad_oid = xmalloc(sizeof(*current_bad_oid)); oidcpy(current_bad_oid, oid); } else if (starts_with(refname, good_prefix.buf)) { - sha1_array_append(&good_revs, oid->hash); + oid_array_append(&good_revs, oid); } else if (starts_with(refname, "skip-")) { - sha1_array_append(&skipped_revs, oid->hash); + oid_array_append(&skipped_revs, oid); } strbuf_release(&good_prefix); @@ -430,6 +432,7 @@ static int read_bisect_refs(void) static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") +static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static void read_bisect_paths(struct argv_array *array) { @@ -438,12 +441,12 @@ static void read_bisect_paths(struct argv_array *array) 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(&str, fp, '\n') != EOF) { + 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); } @@ -451,13 +454,13 @@ static void read_bisect_paths(struct argv_array *array) fclose(fp); } -static char *join_sha1_array_hex(struct sha1_array *array, char delim) +static char *join_sha1_array_hex(struct oid_array *array, char delim) { struct strbuf joined_hexs = STRBUF_INIT; int i; for (i = 0; i < array->nr; i++) { - strbuf_addstr(&joined_hexs, sha1_to_hex(array->sha1[i])); + strbuf_addstr(&joined_hexs, oid_to_hex(array->oid + i)); if (i + 1 < array->nr) strbuf_addch(&joined_hexs, delim); } @@ -499,8 +502,7 @@ struct commit_list *filter_skipped(struct commit_list *list, while (list) { struct commit_list *next = list->next; list->next = NULL; - if (0 <= sha1_array_lookup(&skipped_revs, - list->item->object.sha1)) { + if (0 <= oid_array_lookup(&skipped_revs, &list->item->object.oid)) { if (skipped_first && !*skipped_first) *skipped_first = 1; /* Move current to tried list */ @@ -544,7 +546,7 @@ static unsigned get_prn(unsigned count) { /* * Custom integer square root from - * http://en.wikipedia.org/wiki/Integer_square_root + * https://en.wikipedia.org/wiki/Integer_square_root */ static int sqrti(int val) { @@ -575,7 +577,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count) for (i = 0; cur; cur = cur->next, i++) { if (i == index) { - if (hashcmp(cur->item->object.sha1, current_bad_oid->hash)) + if (oidcmp(&cur->item->object.oid, current_bad_oid)) return cur; if (previous) return previous; @@ -621,7 +623,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix, argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid)); for (i = 0; i < good_revs.nr; i++) argv_array_pushf(&rev_argv, good_format, - sha1_to_hex(good_revs.sha1[i])); + oid_to_hex(good_revs.oid + i)); argv_array_push(&rev_argv, "--"); if (read_paths) read_bisect_paths(&rev_argv); @@ -646,10 +648,13 @@ 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"); + printf(_("We cannot bisect more!\n")); exit(2); } @@ -668,7 +673,7 @@ static int is_expected_rev(const struct object_id *oid) if (!fp) return 0; - if (strbuf_getline(&str, fp, '\n') != EOF) + if (strbuf_getline_lf(&str, fp) != EOF) res = !strcmp(str.buf, oid_to_hex(oid)); strbuf_release(&str); @@ -679,7 +684,7 @@ static int is_expected_rev(const struct object_id *oid) static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout) { - char bisect_rev_hex[GIT_SHA1_HEXSZ + 1]; + char bisect_rev_hex[GIT_MAX_HEXSZ + 1]; memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1); update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR); @@ -698,23 +703,23 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout) return run_command_v_opt(argv_show_branch, RUN_GIT_CMD); } -static struct commit *get_commit_reference(const unsigned char *sha1) +static struct commit *get_commit_reference(const struct object_id *oid) { - struct commit *r = lookup_commit_reference(sha1); + struct commit *r = lookup_commit_reference(oid->hash); if (!r) - die("Not a valid commit name %s", sha1_to_hex(sha1)); + die(_("Not a valid commit name %s"), oid_to_hex(oid)); return r; } static struct commit **get_bad_and_good_commits(int *rev_nr) { - int len = 1 + good_revs.nr; - struct commit **rev = xmalloc(len * sizeof(*rev)); + struct commit **rev; int i, n = 0; - rev[n++] = get_commit_reference(current_bad_oid->hash); + ALLOC_ARRAY(rev, 1 + good_revs.nr); + rev[n++] = get_commit_reference(current_bad_oid); for (i = 0; i < good_revs.nr; i++) - rev[n++] = get_commit_reference(good_revs.sha1[i]); + rev[n++] = get_commit_reference(good_revs.oid + i); *rev_nr = n; return rev; @@ -726,47 +731,52 @@ 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" + "The property has changed " + "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 ancestors 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) +static void handle_skipped_merge_base(const struct object_id *mb) { - char *mb_hex = sha1_to_hex(mb); - char *bad_hex = sha1_to_hex(current_bad_oid->hash); + char *mb_hex = oid_to_hex(mb); + 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); } /* - * "check_merge_bases" checks that merge bases are not "bad". + * "check_merge_bases" checks that merge bases are not "bad" (or "new"). * - * - If one is "bad", it means the user assumed something wrong + * - If one is "bad" (or "new"), it means the user assumed something wrong * and we must exit with a non 0 error code. - * - If one is "good", that's good, we have nothing to do. + * - If one is "good" (or "old"), that's good, we have nothing to do. * - If one is "skipped", we can't know but we should warn. * - If we don't know, we should check it out and ask the user to test. */ @@ -779,16 +789,16 @@ static void check_merge_bases(int no_checkout) result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1); for (; result; result = result->next) { - const unsigned char *mb = result->item->object.sha1; - if (!hashcmp(mb, current_bad_oid->hash)) { + const struct object_id *mb = &result->item->object.oid; + if (!oidcmp(mb, current_bad_oid)) { handle_bad_merge_base(); - } else if (0 <= sha1_array_lookup(&good_revs, mb)) { + } else if (0 <= oid_array_lookup(&good_revs, mb)) { continue; - } else if (0 <= sha1_array_lookup(&skipped_revs, mb)) { + } else if (0 <= oid_array_lookup(&skipped_revs, mb)) { handle_skipped_merge_base(mb); } else { - printf("Bisecting: a merge base must be tested\n"); - exit(bisect_checkout(mb, no_checkout)); + printf(_("Bisecting: a merge base must be tested\n")); + exit(bisect_checkout(mb->hash, no_checkout)); } } @@ -838,7 +848,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout) 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)) @@ -855,8 +865,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout) /* Create file BISECT_ANCESTORS_OK. */ fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (fd < 0) - warning("could not create file '%s': %s", - filename, strerror(errno)); + warning_errno(_("could not create file '%s'"), + filename); else close(fd); done: @@ -885,6 +895,7 @@ static void show_diff_tree(const char *prefix, struct commit *commit) if (!opt.diffopt.output_format) opt.diffopt.output_format = DIFF_FORMAT_RAW; + setup_revisions(0, NULL, &opt, NULL); log_tree_commit(&opt, commit); } @@ -896,7 +907,7 @@ static void show_diff_tree(const char *prefix, struct commit *commit) void read_bisect_terms(const char **read_bad, const char **read_good) { struct strbuf str = STRBUF_INIT; - const char *filename = git_path("BISECT_TERMS"); + const char *filename = git_path_bisect_terms(); FILE *fp = fopen(filename, "r"); if (!fp) { @@ -905,13 +916,12 @@ void read_bisect_terms(const char **read_bad, const char **read_good) *read_good = "good"; return; } else { - die("could not read file '%s': %s", filename, - strerror(errno)); + die_errno(_("could not read file '%s'"), filename); } } else { - strbuf_getline(&str, fp, '\n'); + strbuf_getline_lf(&str, fp); *read_bad = strbuf_detach(&str, NULL); - strbuf_getline(&str, fp, '\n'); + strbuf_getline_lf(&str, fp); *read_good = strbuf_detach(&str, NULL); } strbuf_release(&str); @@ -932,10 +942,11 @@ int bisect_next_all(const char *prefix, int no_checkout) struct commit_list *tried; int reaches = 0, all = 0, nr, steps; const unsigned char *bisect_rev; + char *steps_msg; 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); @@ -955,7 +966,7 @@ int bisect_next_all(const char *prefix, int 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); @@ -963,12 +974,12 @@ int bisect_next_all(const char *prefix, int no_checkout) } 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); } - bisect_rev = revs.commits->item->object.sha1; + bisect_rev = revs.commits->item->object.oid.hash; if (!hashcmp(bisect_rev, current_bad_oid->hash)) { exit_if_skipped_commits(tried, current_bad_oid); @@ -981,9 +992,17 @@ int bisect_next_all(const char *prefix, int no_checkout) 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")); + + steps_msg = xstrfmt(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); + free(steps_msg); return bisect_checkout(bisect_rev, no_checkout); }