aboutsummaryrefslogtreecommitdiff
path: root/bisect.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-04-19 21:37:13 -0700
committerJunio C Hamano <gitster@pobox.com>2017-04-19 21:37:13 -0700
commitb1081e4004091947b6c6a806625addd1cbba61b7 (patch)
tree2cf8dfc6a5e33499b5dbcc8b3e94dbe311e2acfa /bisect.c
parentc703555cc89cf6aedf549a1233b242d8cb8e0f20 (diff)
parente239dabb1465d3ff927840b4fff15150a2170b4e (diff)
downloadgit-b1081e4004091947b6c6a806625addd1cbba61b7.tar.gz
git-b1081e4004091947b6c6a806625addd1cbba61b7.tar.xz
Merge branch 'bc/object-id'
Conversion from unsigned char [40] to struct object_id continues. * bc/object-id: Documentation: update and rename api-sha1-array.txt Rename sha1_array to oid_array Convert sha1_array_for_each_unique and for_each_abbrev to object_id Convert sha1_array_lookup to take struct object_id Convert remaining callers of sha1_array_lookup to object_id Make sha1_array_append take a struct object_id * sha1-array: convert internal storage for struct sha1_array to object_id builtin/pull: convert to struct object_id submodule: convert check_for_new_submodule_commits to object_id sha1_name: convert disambiguate_hint_fn to take object_id sha1_name: convert struct disambiguate_state to object_id test-sha1-array: convert most code to struct object_id parse-options-cb: convert sha1_array_append caller to struct object_id fsck: convert init_skiplist to struct object_id builtin/receive-pack: convert portions to struct object_id builtin/pull: convert portions to struct object_id builtin/diff: convert to struct object_id Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ Define new hash-size constants for allocating memory
Diffstat (limited to 'bisect.c')
-rw-r--r--bisect.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/bisect.c b/bisect.c
index d12583eaa..03af06c66 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;
@@ -415,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);
@@ -453,13 +453,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);
}
@@ -501,8 +501,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.oid.hash)) {
+ if (0 <= oid_array_lookup(&skipped_revs, &list->item->object.oid)) {
if (skipped_first && !*skipped_first)
*skipped_first = 1;
/* Move current to tried list */
@@ -623,7 +622,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);
@@ -684,7 +683,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);
@@ -703,11 +702,11 @@ 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;
}
@@ -717,9 +716,9 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
int i, n = 0;
ALLOC_ARRAY(rev, 1 + good_revs.nr);
- rev[n++] = get_commit_reference(current_bad_oid->hash);
+ 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;
@@ -756,9 +755,9 @@ static void handle_bad_merge_base(void)
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 *mb_hex = oid_to_hex(mb);
char *bad_hex = oid_to_hex(current_bad_oid);
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
@@ -789,16 +788,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.oid.hash;
- 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));
+ exit(bisect_checkout(mb->hash, no_checkout));
}
}