Make sha1_array_append take a struct object_id *

Convert the callers to pass struct object_id by changing the function declaration and definition and applying the following semantic patch: @@ expression E1, E2; @@ - sha1_array_append(E1, E2.hash) + sha1_array_append(E1, &E2) @@ expression E1, E2; @@ - sha1_array_append(E1, E2->hash) + sha1_array_append(E1, E2) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Mar 31, 2017 at 01:39 UTC 98a72ddc12e13231537150607f4a6a8ff8b43854
17 files changed +32 -30
bisect.c
+2 -2
@@ -413,9 +413,9 @@ static int register_ref(const char *refname, const struct object_id *oid,
413 current_bad_oid = xmalloc(sizeof(*current_bad_oid));
414 oidcpy(current_bad_oid, oid);
415 } else if (starts_with(refname, good_prefix.buf)) {
416 - sha1_array_append(&good_revs, oid->hash);
416 + sha1_array_append(&good_revs, oid);
417 } else if (starts_with(refname, "skip-")) {
418 - sha1_array_append(&skipped_revs, oid->hash);
418 + sha1_array_append(&skipped_revs, oid);
419 }
420
421 strbuf_release(&good_prefix);
builtin/cat-file.c
+2 -2
@@ -413,7 +413,7 @@ static int batch_loose_object(const struct object_id *oid,
413 const char *path,
414 void *data)
415 {
416 - sha1_array_append(data, oid->hash);
416 + sha1_array_append(data, oid);
417 return 0;
418 }
419
@@ -422,7 +422,7 @@ static int batch_packed_object(const struct object_id *oid,
422 uint32_t pos,
423 void *data)
424 {
425 - sha1_array_append(data, oid->hash);
425 + sha1_array_append(data, oid);
426 return 0;
427 }
428
builtin/diff.c
+1 -1
@@ -193,7 +193,7 @@ static int builtin_diff_combined(struct rev_info *revs,
193 if (!revs->dense_combined_merges && !revs->combine_merges)
194 revs->dense_combined_merges = revs->combine_merges = 1;
195 for (i = 1; i < ents; i++)
196 - sha1_array_append(&parents, ent[i].item->oid.hash);
196 + sha1_array_append(&parents, &ent[i].item->oid);
197 diff_tree_combined(ent[0].item->oid.hash, &parents,
198 revs->dense_combined_merges, revs);
199 sha1_array_clear(&parents);
builtin/pack-objects.c
+2 -2
@@ -2739,12 +2739,12 @@ static void record_recent_object(struct object *obj,
2739 const char *name,
2740 void *data)
2741 {
2742 - sha1_array_append(&recent_objects, obj->oid.hash);
2742 + sha1_array_append(&recent_objects, &obj->oid);
2743 }
2744
2745 static void record_recent_commit(struct commit *commit, void *data)
2746 {
2747 - sha1_array_append(&recent_objects, commit->object.oid.hash);
2747 + sha1_array_append(&recent_objects, &commit->object.oid);
2748 }
2749
2750 static void get_object_list(int ac, const char **av)
builtin/pull.c
+1 -1
@@ -344,7 +344,7 @@ static void get_merge_heads(struct sha1_array *merge_heads)
344 continue; /* invalid line: does not start with SHA1 */
345 if (starts_with(sb.buf + GIT_SHA1_HEXSZ, "\tnot-for-merge\t"))
346 continue; /* ref is not-for-merge */
347 - sha1_array_append(merge_heads, oid.hash);
347 + sha1_array_append(merge_heads, &oid);
348 }
349 fclose(fp);
350 strbuf_release(&sb);
builtin/receive-pack.c
+3 -3
@@ -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->oid[i].hash);
845 + sha1_array_append(&extra, &si->shallow->oid[i]);
846
847 opt.env = tmp_objdir_env(tmp_objdir);
848 setup_alternate_shallow(&shallow_lock, &opt.shallow_file, &extra);
@@ -1546,7 +1546,7 @@ static struct command *read_head_info(struct sha1_array *shallow)
1546 if (get_oid_hex(line + 8, &oid))
1547 die("protocol error: expected shallow sha, got '%s'",
1548 line + 8);
1549 - sha1_array_append(shallow, oid.hash);
1549 + sha1_array_append(shallow, &oid);
1550 continue;
1551 }
1552
@@ -1817,7 +1817,7 @@ static void update_shallow_info(struct command *commands,
1817 for (cmd = commands; cmd; cmd = cmd->next) {
1818 if (is_null_oid(&cmd->new_oid))
1819 continue;
1820 - sha1_array_append(ref, cmd->new_oid.hash);
1820 + sha1_array_append(ref, &cmd->new_oid);
1821 cmd->index = ref->nr - 1;
1822 }
1823 si->ref = ref;
combine-diff.c
+1 -1
@@ -1535,7 +1535,7 @@ void diff_tree_combined_merge(const struct commit *commit, int dense,
1535 struct sha1_array parents = SHA1_ARRAY_INIT;
1536
1537 while (parent) {
1538 - sha1_array_append(&parents, parent->item->object.oid.hash);
1538 + sha1_array_append(&parents, &parent->item->object.oid);
1539 parent = parent->next;
1540 }
1541 diff_tree_combined(commit->object.oid.hash, &parents, dense, rev);
connect.c
+2 -2
@@ -153,7 +153,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
153 die("protocol error: expected shallow sha-1, got '%s'", arg);
154 if (!shallow_points)
155 die("repository on the other end cannot be shallow");
156 - sha1_array_append(shallow_points, old_oid.hash);
156 + sha1_array_append(shallow_points, &old_oid);
157 continue;
158 }
159
@@ -169,7 +169,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
169 }
170
171 if (extra_have && !strcmp(name, ".have")) {
172 - sha1_array_append(extra_have, old_oid.hash);
172 + sha1_array_append(extra_have, &old_oid);
173 continue;
174 }
175
fetch-pack.c
+4 -4
@@ -1042,7 +1042,7 @@ static void update_shallow(struct fetch_pack_args *args,
1042 struct object_id *oid = si->shallow->oid;
1043 for (i = 0; i < si->shallow->nr; i++)
1044 if (has_object_file(&oid[i]))
1045 - sha1_array_append(&extra, oid[i].hash);
1045 + sha1_array_append(&extra, &oid[i]);
1046 if (extra.nr) {
1047 setup_alternate_shallow(&shallow_lock,
1048 &alternate_shallow_file,
@@ -1060,7 +1060,7 @@ static void update_shallow(struct fetch_pack_args *args,
1060 if (!si->nr_ours && !si->nr_theirs)
1061 return;
1062 for (i = 0; i < nr_sought; i++)
1063 - sha1_array_append(&ref, sought[i]->old_oid.hash);
1063 + sha1_array_append(&ref, &sought[i]->old_oid);
1064 si->ref = &ref;
1065
1066 if (args->update_shallow) {
@@ -1078,9 +1078,9 @@ static void update_shallow(struct fetch_pack_args *args,
1078 return;
1079 }
1080 for (i = 0; i < si->nr_ours; i++)
1081 - sha1_array_append(&extra, oid[si->ours[i]].hash);
1081 + sha1_array_append(&extra, &oid[si->ours[i]]);
1082 for (i = 0; i < si->nr_theirs; i++)
1083 - sha1_array_append(&extra, oid[si->theirs[i]].hash);
1083 + sha1_array_append(&extra, &oid[si->theirs[i]]);
1084 setup_alternate_shallow(&shallow_lock,
1085 &alternate_shallow_file,
1086 &extra);
fsck.c
+1 -1
@@ -156,7 +156,7 @@ static void init_skiplist(struct fsck_options *options, const char *path)
156 break;
157 if (parse_oid_hex(buffer, &oid, &p) || *p != '\n')
158 die("Invalid SHA-1: %s", buffer);
159 - sha1_array_append(&skiplist, oid.hash);
159 + sha1_array_append(&skiplist, &oid);
160 if (sorted && skiplist.nr > 1 &&
161 oidcmp(&skiplist.oid[skiplist.nr - 2],
162 &oid) > 0)
parse-options-cb.c
+1 -1
@@ -106,7 +106,7 @@ int parse_opt_object_name(const struct option *opt, const char *arg, int unset)
106 return -1;
107 if (get_oid(arg, &oid))
108 return error(_("malformed object name '%s'"), arg);
109 - sha1_array_append(opt->value, oid.hash);
109 + sha1_array_append(opt->value, &oid);
110 return 0;
111 }
112
sha1-array.c
+2 -2
@@ -2,10 +2,10 @@
2 #include "sha1-array.h"
3 #include "sha1-lookup.h"
4
5 -void sha1_array_append(struct sha1_array *array, const unsigned char *sha1)
5 +void sha1_array_append(struct sha1_array *array, const struct object_id *oid)
6 {
7 ALLOC_GROW(array->oid, array->nr + 1, array->alloc);
8 - hashcpy(array->oid[array->nr++].hash, sha1);
8 + oidcpy(&array->oid[array->nr++], oid);
9 array->sorted = 0;
10 }
11
sha1-array.h
+1 -1
@@ -10,7 +10,7 @@ struct sha1_array {
10
11 #define SHA1_ARRAY_INIT { NULL, 0, 0, 0 }
12
13 -void sha1_array_append(struct sha1_array *array, const unsigned char *sha1);
13 +void sha1_array_append(struct sha1_array *array, const struct object_id *oid);
14 int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1);
15 void sha1_array_clear(struct sha1_array *array);
16
sha1_name.c
+1 -1
@@ -428,7 +428,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
428
429 static int collect_ambiguous(const struct object_id *oid, void *data)
430 {
431 - sha1_array_append(data, oid->hash);
431 + sha1_array_append(data, oid);
432 return 0;
433 }
434
submodule.c
+3 -3
@@ -650,7 +650,7 @@ static void collect_submodules_from_diff(struct diff_queue_struct *q,
650 if (!S_ISGITLINK(p->two->mode))
651 continue;
652 commits = submodule_commits(submodules, p->two->path);
653 - sha1_array_append(commits, p->two->oid.hash);
653 + sha1_array_append(commits, &p->two->oid);
654 }
655 }
656
@@ -817,7 +817,7 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,
817 static int add_sha1_to_array(const char *ref, const struct object_id *oid,
818 int flags, void *data)
819 {
820 - sha1_array_append(data, oid->hash);
820 + sha1_array_append(data, oid);
821 return 0;
822 }
823
@@ -828,7 +828,7 @@ void check_for_new_submodule_commits(struct object_id *oid)
828 initialized_fetch_ref_tips = 1;
829 }
830
831 - sha1_array_append(&ref_tips_after_fetch, oid->hash);
831 + sha1_array_append(&ref_tips_after_fetch, oid);
832 }
833
834 static int add_sha1_to_argv(const unsigned char sha1[20], void *data)
t/helper/test-sha1-array.c
+1 -1
@@ -19,7 +19,7 @@ int cmd_main(int argc, const char **argv)
19 if (skip_prefix(line.buf, "append ", &arg)) {
20 if (get_oid_hex(arg, &oid))
21 die("not a hexadecimal SHA1: %s", arg);
22 - sha1_array_append(&array, oid.hash);
22 + sha1_array_append(&array, &oid);
23 } else if (skip_prefix(line.buf, "lookup ", &arg)) {
24 if (get_oid_hex(arg, &oid))
25 die("not a hexadecimal SHA1: %s", arg);
transport.c
+4 -2
@@ -1027,7 +1027,8 @@ int transport_push(struct transport *transport,
1027
1028 for (; ref; ref = ref->next)
1029 if (!is_null_oid(&ref->new_oid))
1030 - sha1_array_append(&commits, ref->new_oid.hash);
1030 + sha1_array_append(&commits,
1031 + &ref->new_oid);
1032
1033 if (!push_unpushed_submodules(&commits,
1034 transport->remote->name,
@@ -1048,7 +1049,8 @@ int transport_push(struct transport *transport,
1049
1050 for (; ref; ref = ref->next)
1051 if (!is_null_oid(&ref->new_oid))
1051 - sha1_array_append(&commits, ref->new_oid.hash);
1052 + sha1_array_append(&commits,
1053 + &ref->new_oid);
1054
1055 if (find_unpushed_submodules(&commits, transport->remote->name,
1056 &needs_pushing)) {