sha1-array: convert internal storage for struct sha1_array to object_id
Make the internal storage for struct sha1_array use an array of struct object_id internally. Update the users of this struct which inspect its internals. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 26, 2017 at 16:01 UTC
ee3051bd2307cdc0145aa9ed9dcacb8acfc08c40
11 files changed
+58
-58
bisect.c
+7
-7
@@ -457,7 +457,7 @@ static char *join_sha1_array_hex(struct sha1_array *array, char delim)
457
int i;
458
459
for (i = 0; i < array->nr; i++) {
460
- strbuf_addstr(&joined_hexs, sha1_to_hex(array->sha1[i]));
460
+ strbuf_addstr(&joined_hexs, oid_to_hex(array->oid + i));
461
if (i + 1 < array->nr)
462
strbuf_addch(&joined_hexs, delim);
463
}
@@ -621,7 +621,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
621
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
622
for (i = 0; i < good_revs.nr; i++)
623
argv_array_pushf(&rev_argv, good_format,
624
- sha1_to_hex(good_revs.sha1[i]));
624
+ oid_to_hex(good_revs.oid + i));
625
argv_array_push(&rev_argv, "--");
626
if (read_paths)
627
read_bisect_paths(&rev_argv);
@@ -701,11 +701,11 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
701
return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
702
}
703
704
-static struct commit *get_commit_reference(const unsigned char *sha1)
704
+static struct commit *get_commit_reference(const struct object_id *oid)
705
{
706
- struct commit *r = lookup_commit_reference(sha1);
706
+ struct commit *r = lookup_commit_reference(oid->hash);
707
if (!r)
708
- die(_("Not a valid commit name %s"), sha1_to_hex(sha1));
708
+ die(_("Not a valid commit name %s"), oid_to_hex(oid));
709
return r;
710
}
711
@@ -715,9 +715,9 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
715
int i, n = 0;
716
717
ALLOC_ARRAY(rev, 1 + good_revs.nr);
718
- rev[n++] = get_commit_reference(current_bad_oid->hash);
718
+ rev[n++] = get_commit_reference(current_bad_oid);
719
for (i = 0; i < good_revs.nr; i++)
720
- rev[n++] = get_commit_reference(good_revs.sha1[i]);
720
+ rev[n++] = get_commit_reference(good_revs.oid + i);
721
*rev_nr = n;
722
723
return rev;
builtin/pull.c
+11
-11
@@ -514,7 +514,7 @@ static int run_fetch(const char *repo, const char **refspecs)
514
/**
515
* "Pulls into void" by branching off merge_head.
516
*/
517
-static int pull_into_void(const unsigned char *merge_head,
517
+static int pull_into_void(const struct object_id *merge_head,
518
const struct object_id *curr_head)
519
{
520
/*
@@ -523,10 +523,10 @@ static int pull_into_void(const unsigned char *merge_head,
523
* index/worktree changes that the user already made on the unborn
524
* branch.
525
*/
526
- if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head, 0))
526
+ if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head->hash, 0))
527
return 1;
528
529
- if (update_ref("initial pull", "HEAD", merge_head, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
529
+ if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR))
530
return 1;
531
532
return 0;
@@ -693,13 +693,13 @@ cleanup:
693
*/
694
static int get_octopus_merge_base(struct object_id *merge_base,
695
const struct object_id *curr_head,
696
- const unsigned char *merge_head,
696
+ const struct object_id *merge_head,
697
const struct object_id *fork_point)
698
{
699
struct commit_list *revs = NULL, *result;
700
701
commit_list_insert(lookup_commit_reference(curr_head->hash), &revs);
702
- commit_list_insert(lookup_commit_reference(merge_head), &revs);
702
+ commit_list_insert(lookup_commit_reference(merge_head->hash), &revs);
703
if (!is_null_oid(fork_point))
704
commit_list_insert(lookup_commit_reference(fork_point->hash), &revs);
705
@@ -718,7 +718,7 @@ static int get_octopus_merge_base(struct object_id *merge_base,
718
* appropriate arguments and returns its exit status.
719
*/
720
static int run_rebase(const struct object_id *curr_head,
721
- const unsigned char *merge_head,
721
+ const struct object_id *merge_head,
722
const struct object_id *fork_point)
723
{
724
int ret;
@@ -754,12 +754,12 @@ static int run_rebase(const struct object_id *curr_head,
754
warning(_("ignoring --verify-signatures for rebase"));
755
756
argv_array_push(&args, "--onto");
757
- argv_array_push(&args, sha1_to_hex(merge_head));
757
+ argv_array_push(&args, oid_to_hex(merge_head));
758
759
if (fork_point && !is_null_oid(fork_point))
760
argv_array_push(&args, oid_to_hex(fork_point));
761
else
762
- argv_array_push(&args, sha1_to_hex(merge_head));
762
+ argv_array_push(&args, oid_to_hex(merge_head));
763
764
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
765
argv_array_clear(&args);
@@ -856,7 +856,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
856
if (is_null_oid(&orig_head)) {
857
if (merge_heads.nr > 1)
858
die(_("Cannot merge multiple branches into empty head."));
859
- return pull_into_void(*merge_heads.sha1, &curr_head);
859
+ return pull_into_void(merge_heads.oid, &curr_head);
860
}
861
if (opt_rebase && merge_heads.nr > 1)
862
die(_("Cannot rebase onto multiple branches."));
@@ -867,13 +867,13 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
867
868
head = lookup_commit_reference(orig_head.hash);
869
commit_list_insert(head, &list);
870
- merge_head = lookup_commit_reference(merge_heads.sha1[0]);
870
+ merge_head = lookup_commit_reference(merge_heads.oid[0].hash);
871
if (is_descendant_of(merge_head, list)) {
872
/* we can fast-forward this without invoking rebase */
873
opt_ff = "--ff-only";
874
return run_merge();
875
}
876
- return run_rebase(&curr_head, *merge_heads.sha1, &rebase_fork_point);
876
+ return run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point);
877
} else {
878
return run_merge();
879
}
builtin/receive-pack.c
+2
-2
@@ -842,7 +842,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
842
if (si->used_shallow[i] &&
843
(si->used_shallow[i][cmd->index / 32] & mask) &&
844
!delayed_reachability_test(si, i))
845
- sha1_array_append(&extra, si->shallow->sha1[i]);
845
+ sha1_array_append(&extra, si->shallow->oid[i].hash);
846
847
opt.env = tmp_objdir_env(tmp_objdir);
848
setup_alternate_shallow(&shallow_lock, &opt.shallow_file, &extra);
@@ -859,7 +859,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
859
* not lose these new roots..
860
*/
861
for (i = 0; i < extra.nr; i++)
862
- register_shallow(extra.sha1[i]);
862
+ register_shallow(extra.oid[i].hash);
863
864
si->shallow_ref[cmd->index] = 0;
865
sha1_array_clear(&extra);
combine-diff.c
+3
-3
@@ -1335,7 +1335,7 @@ static struct combine_diff_path *find_paths_generic(const unsigned char *sha1,
1335
opt->output_format = stat_opt;
1336
else
1337
opt->output_format = DIFF_FORMAT_NO_OUTPUT;
1338
- diff_tree_sha1(parents->sha1[i], sha1, "", opt);
1338
+ diff_tree_sha1(parents->oid[i].hash, sha1, "", opt);
1339
diffcore_std(opt);
1340
paths = intersect_paths(paths, i, num_parent);
1341
@@ -1369,7 +1369,7 @@ static struct combine_diff_path *find_paths_multitree(
1369
1370
ALLOC_ARRAY(parents_sha1, nparent);
1371
for (i = 0; i < nparent; i++)
1372
- parents_sha1[i] = parents->sha1[i];
1372
+ parents_sha1[i] = parents->oid[i].hash;
1373
1374
/* fake list head, so worker can assume it is non-NULL */
1375
paths_head.next = NULL;
@@ -1462,7 +1462,7 @@ void diff_tree_combined(const unsigned char *sha1,
1462
if (stat_opt) {
1463
diffopts.output_format = stat_opt;
1464
1465
- diff_tree_sha1(parents->sha1[0], sha1, "", &diffopts);
1465
+ diff_tree_sha1(parents->oid[0].hash, sha1, "", &diffopts);
1466
diffcore_std(&diffopts);
1467
if (opt->orderfile)
1468
diffcore_order(opt->orderfile);
fetch-pack.c
+6
-6
@@ -1039,10 +1039,10 @@ static void update_shallow(struct fetch_pack_args *args,
1039
* after get_pack() and reprepare_packed_git())
1040
*/
1041
struct sha1_array extra = SHA1_ARRAY_INIT;
1042
- unsigned char (*sha1)[20] = si->shallow->sha1;
1042
+ struct object_id *oid = si->shallow->oid;
1043
for (i = 0; i < si->shallow->nr; i++)
1044
- if (has_sha1_file(sha1[i]))
1045
- sha1_array_append(&extra, sha1[i]);
1044
+ if (has_object_file(&oid[i]))
1045
+ sha1_array_append(&extra, oid[i].hash);
1046
if (extra.nr) {
1047
setup_alternate_shallow(&shallow_lock,
1048
&alternate_shallow_file,
@@ -1071,16 +1071,16 @@ static void update_shallow(struct fetch_pack_args *args,
1071
* refs.
1072
*/
1073
struct sha1_array extra = SHA1_ARRAY_INIT;
1074
- unsigned char (*sha1)[20] = si->shallow->sha1;
1074
+ struct object_id *oid = si->shallow->oid;
1075
assign_shallow_commits_to_refs(si, NULL, NULL);
1076
if (!si->nr_ours && !si->nr_theirs) {
1077
sha1_array_clear(&ref);
1078
return;
1079
}
1080
for (i = 0; i < si->nr_ours; i++)
1081
- sha1_array_append(&extra, sha1[si->ours[i]]);
1081
+ sha1_array_append(&extra, oid[si->ours[i]].hash);
1082
for (i = 0; i < si->nr_theirs; i++)
1083
- sha1_array_append(&extra, sha1[si->theirs[i]]);
1083
+ sha1_array_append(&extra, oid[si->theirs[i]].hash);
1084
setup_alternate_shallow(&shallow_lock,
1085
&alternate_shallow_file,
1086
&extra);
fsck.c
+2
-2
@@ -158,8 +158,8 @@ static void init_skiplist(struct fsck_options *options, const char *path)
158
die("Invalid SHA-1: %s", buffer);
159
sha1_array_append(&skiplist, oid.hash);
160
if (sorted && skiplist.nr > 1 &&
161
- hashcmp(skiplist.sha1[skiplist.nr - 2],
162
- oid.hash) > 0)
161
+ oidcmp(&skiplist.oid[skiplist.nr - 2],
162
+ &oid) > 0)
163
sorted = 0;
164
}
165
close(fd);
remote-curl.c
+1
-1
@@ -230,7 +230,7 @@ static void free_discovery(struct discovery *d)
230
if (d) {
231
if (d == last_discovery)
232
last_discovery = NULL;
233
- free(d->shallow.sha1);
233
+ free(d->shallow.oid);
234
free(d->buf_alloc);
235
free_refs(d->refs);
236
free(d);
send-pack.c
+1
-1
@@ -98,7 +98,7 @@ static int pack_objects(int fd, struct ref *refs, struct sha1_array *extra, stru
98
*/
99
po_in = xfdopen(po.in, "w");
100
for (i = 0; i < extra->nr; i++)
101
- feed_object(extra->sha1[i], po_in, 1);
101
+ feed_object(extra->oid[i].hash, po_in, 1);
102
103
while (refs) {
104
if (!is_null_oid(&refs->old_oid))
sha1-array.c
+11
-11
@@ -4,39 +4,39 @@
4
5
void sha1_array_append(struct sha1_array *array, const unsigned char *sha1)
6
{
7
- ALLOC_GROW(array->sha1, array->nr + 1, array->alloc);
8
- hashcpy(array->sha1[array->nr++], sha1);
7
+ ALLOC_GROW(array->oid, array->nr + 1, array->alloc);
8
+ hashcpy(array->oid[array->nr++].hash, sha1);
9
array->sorted = 0;
10
}
11
12
static int void_hashcmp(const void *a, const void *b)
13
{
14
- return hashcmp(a, b);
14
+ return oidcmp(a, b);
15
}
16
17
static void sha1_array_sort(struct sha1_array *array)
18
{
19
- QSORT(array->sha1, array->nr, void_hashcmp);
19
+ QSORT(array->oid, array->nr, void_hashcmp);
20
array->sorted = 1;
21
}
22
23
static const unsigned char *sha1_access(size_t index, void *table)
24
{
25
- unsigned char (*array)[20] = table;
26
- return array[index];
25
+ struct object_id *array = table;
26
+ return array[index].hash;
27
}
28
29
int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1)
30
{
31
if (!array->sorted)
32
sha1_array_sort(array);
33
- return sha1_pos(sha1, array->sha1, array->nr, sha1_access);
33
+ return sha1_pos(sha1, array->oid, array->nr, sha1_access);
34
}
35
36
void sha1_array_clear(struct sha1_array *array)
37
{
38
- free(array->sha1);
39
- array->sha1 = NULL;
38
+ free(array->oid);
39
+ array->oid = NULL;
40
array->nr = 0;
41
array->alloc = 0;
42
array->sorted = 0;
@@ -53,9 +53,9 @@ int sha1_array_for_each_unique(struct sha1_array *array,
53
54
for (i = 0; i < array->nr; i++) {
55
int ret;
56
- if (i > 0 && !hashcmp(array->sha1[i], array->sha1[i-1]))
56
+ if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
57
continue;
58
- ret = fn(array->sha1[i], data);
58
+ ret = fn(array->oid[i].hash, data);
59
if (ret)
60
return ret;
61
}
sha1-array.h
+1
-1
@@ -2,7 +2,7 @@
2
#define SHA1_ARRAY_H
3
4
struct sha1_array {
5
- unsigned char (*sha1)[20];
5
+ struct object_id *oid;
6
int nr;
7
int alloc;
8
int sorted;
shallow.c
+13
-13
@@ -273,7 +273,7 @@ static int write_shallow_commits_1(struct strbuf *out, int use_pack_protocol,
273
if (!extra)
274
return data.count;
275
for (i = 0; i < extra->nr; i++) {
276
- strbuf_addstr(out, sha1_to_hex(extra->sha1[i]));
276
+ strbuf_addstr(out, oid_to_hex(extra->oid + i));
277
strbuf_addch(out, '\n');
278
data.count++;
279
}
@@ -396,9 +396,9 @@ void prepare_shallow_info(struct shallow_info *info, struct sha1_array *sa)
396
ALLOC_ARRAY(info->ours, sa->nr);
397
ALLOC_ARRAY(info->theirs, sa->nr);
398
for (i = 0; i < sa->nr; i++) {
399
- if (has_sha1_file(sa->sha1[i])) {
399
+ if (has_object_file(sa->oid + i)) {
400
struct commit_graft *graft;
401
- graft = lookup_commit_graft(sa->sha1[i]);
401
+ graft = lookup_commit_graft(sa->oid[i].hash);
402
if (graft && graft->nr_parent < 0)
403
continue;
404
info->ours[info->nr_ours++] = i;
@@ -417,13 +417,13 @@ void clear_shallow_info(struct shallow_info *info)
417
418
void remove_nonexistent_theirs_shallow(struct shallow_info *info)
419
{
420
- unsigned char (*sha1)[20] = info->shallow->sha1;
420
+ struct object_id *oid = info->shallow->oid;
421
int i, dst;
422
trace_printf_key(&trace_shallow, "shallow: remove_nonexistent_theirs_shallow\n");
423
for (i = dst = 0; i < info->nr_theirs; i++) {
424
if (i != dst)
425
info->theirs[dst] = info->theirs[i];
426
- if (has_sha1_file(sha1[info->theirs[i]]))
426
+ if (has_object_file(oid + info->theirs[i]))
427
dst++;
428
}
429
info->nr_theirs = dst;
@@ -559,7 +559,7 @@ static void post_assign_shallow(struct shallow_info *info,
559
void assign_shallow_commits_to_refs(struct shallow_info *info,
560
uint32_t **used, int *ref_status)
561
{
562
- unsigned char (*sha1)[20] = info->shallow->sha1;
562
+ struct object_id *oid = info->shallow->oid;
563
struct sha1_array *ref = info->ref;
564
unsigned int i, nr;
565
int *shallow, nr_shallow = 0;
@@ -599,18 +599,18 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,
599
600
/* Mark potential bottoms so we won't go out of bound */
601
for (i = 0; i < nr_shallow; i++) {
602
- struct commit *c = lookup_commit(sha1[shallow[i]]);
602
+ struct commit *c = lookup_commit(oid[shallow[i]].hash);
603
c->object.flags |= BOTTOM;
604
}
605
606
for (i = 0; i < ref->nr; i++)
607
- paint_down(&pi, ref->sha1[i], i);
607
+ paint_down(&pi, ref->oid[i].hash, i);
608
609
if (used) {
610
int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t);
611
memset(used, 0, sizeof(*used) * info->shallow->nr);
612
for (i = 0; i < nr_shallow; i++) {
613
- const struct commit *c = lookup_commit(sha1[shallow[i]]);
613
+ const struct commit *c = lookup_commit(oid[shallow[i]].hash);
614
uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c);
615
if (*map)
616
used[shallow[i]] = xmemdupz(*map, bitmap_size);
@@ -664,7 +664,7 @@ static void post_assign_shallow(struct shallow_info *info,
664
struct ref_bitmap *ref_bitmap,
665
int *ref_status)
666
{
667
- unsigned char (*sha1)[20] = info->shallow->sha1;
667
+ struct object_id *oid = info->shallow->oid;
668
struct commit *c;
669
uint32_t **bitmap;
670
int dst, i, j;
@@ -679,7 +679,7 @@ static void post_assign_shallow(struct shallow_info *info,
679
for (i = dst = 0; i < info->nr_theirs; i++) {
680
if (i != dst)
681
info->theirs[dst] = info->theirs[i];
682
- c = lookup_commit(sha1[info->theirs[i]]);
682
+ c = lookup_commit(oid[info->theirs[i]].hash);
683
bitmap = ref_bitmap_at(ref_bitmap, c);
684
if (!*bitmap)
685
continue;
@@ -700,7 +700,7 @@ static void post_assign_shallow(struct shallow_info *info,
700
for (i = dst = 0; i < info->nr_ours; i++) {
701
if (i != dst)
702
info->ours[dst] = info->ours[i];
703
- c = lookup_commit(sha1[info->ours[i]]);
703
+ c = lookup_commit(oid[info->ours[i]].hash);
704
bitmap = ref_bitmap_at(ref_bitmap, c);
705
if (!*bitmap)
706
continue;
@@ -722,7 +722,7 @@ static void post_assign_shallow(struct shallow_info *info,
722
int delayed_reachability_test(struct shallow_info *si, int c)
723
{
724
if (si->need_reachability_test[c]) {
725
- struct commit *commit = lookup_commit(si->shallow->sha1[c]);
725
+ struct commit *commit = lookup_commit(si->shallow->oid[c].hash);
726
727
if (!si->commits) {
728
struct commit_array ca;