Skip to content

Commit e92b848

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68ab61d commit e92b848

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,10 +2777,10 @@ static void get_object_list(int ac, const char **av)
27772777
continue;
27782778
}
27792779
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))
27822782
die("not an SHA-1 '%s'", line + 10);
2783-
register_shallow(sha1);
2783+
register_shallow(&oid);
27842784
use_bitmap_index = 0;
27852785
continue;
27862786
}

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
858858
* not lose these new roots..
859859
*/
860860
for (i = 0; i < extra.nr; i++)
861-
register_shallow(extra.oid[i].hash);
861+
register_shallow(&extra.oid[i]);
862862

863863
si->shallow_ref[cmd->index] = 0;
864864
oid_array_clear(&extra);

commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data)
216216
return ret;
217217
}
218218

219-
int unregister_shallow(const unsigned char *sha1)
219+
int unregister_shallow(const struct object_id *oid)
220220
{
221-
int pos = commit_graft_pos(sha1);
221+
int pos = commit_graft_pos(oid->hash);
222222
if (pos < 0)
223223
return -1;
224224
if (pos + 1 < commit_graft_nr)

commit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n,
263263

264264
struct oid_array;
265265
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);
268268
extern int for_each_commit_graft(each_commit_graft_fn, void *);
269269
extern int is_repository_shallow(void);
270270
extern struct commit_list *get_shallow_commits(struct object_array *heads,

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static int find_common(struct fetch_pack_args *args,
417417
if (skip_prefix(line, "shallow ", &arg)) {
418418
if (get_oid_hex(arg, &oid))
419419
die(_("invalid shallow line: %s"), line);
420-
register_shallow(oid.hash);
420+
register_shallow(&oid);
421421
continue;
422422
}
423423
if (skip_prefix(line, "unshallow ", &arg)) {
@@ -428,7 +428,7 @@ static int find_common(struct fetch_pack_args *args,
428428
/* make sure that it is parsed as shallow */
429429
if (!parse_object(oid.hash))
430430
die(_("error in object: %s"), line);
431-
if (unregister_shallow(oid.hash))
431+
if (unregister_shallow(&oid))
432432
die(_("no shallow found: %s"), line);
433433
continue;
434434
}

shallow.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ void set_alternate_shallow_file(const char *path, int override)
2727
alternate_shallow_file = xstrdup_or_null(path);
2828
}
2929

30-
int register_shallow(const unsigned char *sha1)
30+
int register_shallow(const struct object_id *oid)
3131
{
3232
struct commit_graft *graft =
3333
xmalloc(sizeof(struct commit_graft));
34-
struct commit *commit = lookup_commit(sha1);
34+
struct commit *commit = lookup_commit(oid->hash);
3535

36-
hashcpy(graft->oid.hash, sha1);
36+
oidcpy(&graft->oid, oid);
3737
graft->nr_parent = -1;
3838
if (commit && commit->object.parsed)
3939
commit->parents = NULL;
@@ -65,10 +65,10 @@ int is_repository_shallow(void)
6565
is_shallow = 1;
6666

6767
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))
7070
die("bad shallow line: %s", buf);
71-
register_shallow(sha1);
71+
register_shallow(&oid);
7272
}
7373
fclose(fp);
7474
return is_shallow;

upload-pack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ static void send_shallow(struct commit_list *result)
642642
if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
643643
packet_write_fmt(1, "shallow %s",
644644
oid_to_hex(&object->oid));
645-
register_shallow(object->oid.hash);
645+
register_shallow(&object->oid);
646646
shallow_nr++;
647647
}
648648
result = result->next;
@@ -667,7 +667,7 @@ static void send_unshallow(const struct object_array *shallows)
667667
* parse and add the parents to the want list, then
668668
* re-register it.
669669
*/
670-
unregister_shallow(object->oid.hash);
670+
unregister_shallow(&object->oid);
671671
object->parsed = 0;
672672
parse_commit_or_die((struct commit *)object);
673673
parents = ((struct commit *)object)->parents;
@@ -679,7 +679,7 @@ static void send_unshallow(const struct object_array *shallows)
679679
add_object_array(object, NULL, &extra_edge_obj);
680680
}
681681
/* make sure commit traversal conforms to client */
682-
register_shallow(object->oid.hash);
682+
register_shallow(&object->oid);
683683
}
684684
}
685685

@@ -883,7 +883,7 @@ static void receive_needs(void)
883883
if (shallows.nr > 0) {
884884
int i;
885885
for (i = 0; i < shallows.nr; i++)
886-
register_shallow(shallows.objects[i].item->oid.hash);
886+
register_shallow(&shallows.objects[i].item->oid);
887887
}
888888

889889
shallow_nr += shallows.nr;

0 commit comments

Comments
 (0)