shallow: convert shallow registration functions to object_id

Convert register_shallow and unregister_shallow to take struct object_id. register_shallow is a caller of lookup_commit, which we will convert later. It doesn't make sense for the registration and unregistration functions to have incompatible interfaces, so convert them both. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed May 6, 2017 at 22:10 UTC e92b848cb6a77172d2fbd2bda39a32e371d40eea
7 files changed +20 -20
builtin/pack-objects.c
+3 -3
@@ -2777,10 +2777,10 @@ static void get_object_list(int ac, const char **av)
2777 continue;
2778 }
2779 if (starts_with(line, "--shallow ")) {
2780 - unsigned char sha1[20];
2781 - if (get_sha1_hex(line + 10, sha1))
2780 + struct object_id oid;
2781 + if (get_oid_hex(line + 10, &oid))
2782 die("not an SHA-1 '%s'", line + 10);
2783 - register_shallow(sha1);
2783 + register_shallow(&oid);
2784 use_bitmap_index = 0;
2785 continue;
2786 }
builtin/receive-pack.c
+1 -1
@@ -858,7 +858,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
858 * not lose these new roots..
859 */
860 for (i = 0; i < extra.nr; i++)
861 - register_shallow(extra.oid[i].hash);
861 + register_shallow(&extra.oid[i]);
862
863 si->shallow_ref[cmd->index] = 0;
864 oid_array_clear(&extra);
commit.c
+2 -2
@@ -216,9 +216,9 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
216 return ret;
217 }
218
219 -int unregister_shallow(const unsigned char *sha1)
219 +int unregister_shallow(const struct object_id *oid)
220 {
221 - int pos = commit_graft_pos(sha1);
221 + int pos = commit_graft_pos(oid->hash);
222 if (pos < 0)
223 return -1;
224 if (pos + 1 < commit_graft_nr)
commit.h
+2 -2
@@ -263,8 +263,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
263
264 struct oid_array;
265 struct ref;
266 -extern int register_shallow(const unsigned char *sha1);
267 -extern int unregister_shallow(const unsigned char *sha1);
266 +extern int register_shallow(const struct object_id *oid);
267 +extern int unregister_shallow(const struct object_id *oid);
268 extern int for_each_commit_graft(each_commit_graft_fn, void *);
269 extern int is_repository_shallow(void);
270 extern struct commit_list *get_shallow_commits(struct object_array *heads,
fetch-pack.c
+2 -2
@@ -417,7 +417,7 @@ static int find_common(struct fetch_pack_args *args,
417 if (skip_prefix(line, "shallow ", &arg)) {
418 if (get_oid_hex(arg, &oid))
419 die(_("invalid shallow line: %s"), line);
420 - register_shallow(oid.hash);
420 + register_shallow(&oid);
421 continue;
422 }
423 if (skip_prefix(line, "unshallow ", &arg)) {
@@ -428,7 +428,7 @@ static int find_common(struct fetch_pack_args *args,
428 /* make sure that it is parsed as shallow */
429 if (!parse_object(oid.hash))
430 die(_("error in object: %s"), line);
431 - if (unregister_shallow(oid.hash))
431 + if (unregister_shallow(&oid))
432 die(_("no shallow found: %s"), line);
433 continue;
434 }
shallow.c
+6 -6
@@ -27,13 +27,13 @@ void set_alternate_shallow_file(const char *path, int override)
27 alternate_shallow_file = xstrdup_or_null(path);
28 }
29
30 -int register_shallow(const unsigned char *sha1)
30 +int register_shallow(const struct object_id *oid)
31 {
32 struct commit_graft *graft =
33 xmalloc(sizeof(struct commit_graft));
34 - struct commit *commit = lookup_commit(sha1);
34 + struct commit *commit = lookup_commit(oid->hash);
35
36 - hashcpy(graft->oid.hash, sha1);
36 + oidcpy(&graft->oid, oid);
37 graft->nr_parent = -1;
38 if (commit && commit->object.parsed)
39 commit->parents = NULL;
@@ -65,10 +65,10 @@ int is_repository_shallow(void)
65 is_shallow = 1;
66
67 while (fgets(buf, sizeof(buf), fp)) {
68 - unsigned char sha1[20];
69 - if (get_sha1_hex(buf, sha1))
68 + struct object_id oid;
69 + if (get_oid_hex(buf, &oid))
70 die("bad shallow line: %s", buf);
71 - register_shallow(sha1);
71 + register_shallow(&oid);
72 }
73 fclose(fp);
74 return is_shallow;
upload-pack.c
+4 -4
@@ -642,7 +642,7 @@ static void send_shallow(struct commit_list *result)
642 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
643 packet_write_fmt(1, "shallow %s",
644 oid_to_hex(&object->oid));
645 - register_shallow(object->oid.hash);
645 + register_shallow(&object->oid);
646 shallow_nr++;
647 }
648 result = result->next;
@@ -667,7 +667,7 @@ static void send_unshallow(const struct object_array *shallows)
667 * parse and add the parents to the want list, then
668 * re-register it.
669 */
670 - unregister_shallow(object->oid.hash);
670 + unregister_shallow(&object->oid);
671 object->parsed = 0;
672 parse_commit_or_die((struct commit *)object);
673 parents = ((struct commit *)object)->parents;
@@ -679,7 +679,7 @@ static void send_unshallow(const struct object_array *shallows)
679 add_object_array(object, NULL, &extra_edge_obj);
680 }
681 /* make sure commit traversal conforms to client */
682 - register_shallow(object->oid.hash);
682 + register_shallow(&object->oid);
683 }
684 }
685
@@ -883,7 +883,7 @@ static void receive_needs(void)
883 if (shallows.nr > 0) {
884 int i;
885 for (i = 0; i < shallows.nr; i++)
886 - register_shallow(shallows.objects[i].item->oid.hash);
886 + register_shallow(&shallows.objects[i].item->oid);
887 }
888
889 shallow_nr += shallows.nr;