Skip to content

Commit 5455ee0

Browse files
committed
Merge branch 'bc/object-id'
for_each_ref() callback functions were taught to name the objects not with "unsigned char sha1[20]" but with "struct object_id". * bc/object-id: (56 commits) struct ref_lock: convert old_sha1 member to object_id warn_if_dangling_symref(): convert local variable "junk" to object_id each_ref_fn_adapter(): remove adapter rev_list_insert_ref(): remove unneeded arguments rev_list_insert_ref_oid(): new function, taking an object_oid mark_complete(): remove unneeded arguments mark_complete_oid(): new function, taking an object_oid clear_marks(): rewrite to take an object_id argument mark_complete(): rewrite to take an object_id argument send_ref(): convert local variable "peeled" to object_id upload-pack: rewrite functions to take object_id arguments find_symref(): convert local variable "unused" to object_id find_symref(): rewrite to take an object_id argument write_one_ref(): rewrite to take an object_id argument write_refs_to_temp_dir(): convert local variable sha1 to object_id submodule: rewrite to take an object_id argument shallow: rewrite functions to take object_id arguments handle_one_ref(): rewrite to take an object_id argument add_info_ref(): rewrite to take an object_id argument handle_one_reflog(): rewrite to take an object_id argument ...
2 parents c4a8354 + 5cb901a commit 5455ee0

36 files changed

+300
-255
lines changed

Documentation/technical/api-ref-iteration.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Iteration of refs is done by using an iterate function which will call a
66
callback function for every ref. The callback function has this
77
signature:
88

9-
int handle_one_ref(const char *refname, const unsigned char *sha1,
9+
int handle_one_ref(const char *refname, const struct object_id *oid,
1010
int flags, void *cb_data);
1111

1212
There are different kinds of iterate functions which all take a

bisect.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,16 @@ struct commit_list *find_bisection(struct commit_list *list,
400400
return best;
401401
}
402402

403-
static int register_ref(const char *refname, const unsigned char *sha1,
403+
static int register_ref(const char *refname, const struct object_id *oid,
404404
int flags, void *cb_data)
405405
{
406406
if (!strcmp(refname, "bad")) {
407407
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
408-
hashcpy(current_bad_oid->hash, sha1);
408+
oidcpy(current_bad_oid, oid);
409409
} else if (starts_with(refname, "good-")) {
410-
sha1_array_append(&good_revs, sha1);
410+
sha1_array_append(&good_revs, oid->hash);
411411
} else if (starts_with(refname, "skip-")) {
412-
sha1_array_append(&skipped_revs, sha1);
412+
sha1_array_append(&skipped_revs, oid->hash);
413413
}
414414

415415
return 0;

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int match_patterns(const char **pattern, const char *refname)
326326
return 0;
327327
}
328328

329-
static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
329+
static int append_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data)
330330
{
331331
struct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);
332332
struct ref_list *ref_list = cb->ref_list;
@@ -363,7 +363,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
363363

364364
commit = NULL;
365365
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
366-
commit = lookup_commit_reference_gently(sha1, 1);
366+
commit = lookup_commit_reference_gently(oid->hash, 1);
367367
if (!commit) {
368368
cb->ret = error(_("branch '%s' does not point at a commit"), refname);
369369
return 0;

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
702702
}
703703

704704
static int add_pending_uninteresting_ref(const char *refname,
705-
const unsigned char *sha1,
705+
const struct object_id *oid,
706706
int flags, void *cb_data)
707707
{
708-
add_pending_sha1(cb_data, refname, sha1, UNINTERESTING);
708+
add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING);
709709
return 0;
710710
}
711711

builtin/describe.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ static void add_to_known_names(const char *path,
119119
}
120120
}
121121

122-
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
122+
static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)
123123
{
124124
int is_tag = starts_with(path, "refs/tags/");
125-
unsigned char peeled[20];
125+
struct object_id peeled;
126126
int is_annotated, prio;
127127

128128
/* Reject anything outside refs/tags/ unless --all */
@@ -134,10 +134,10 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
134134
return 0;
135135

136136
/* Is it annotated? */
137-
if (!peel_ref(path, peeled)) {
138-
is_annotated = !!hashcmp(sha1, peeled);
137+
if (!peel_ref(path, peeled.hash)) {
138+
is_annotated = !!oidcmp(oid, &peeled);
139139
} else {
140-
hashcpy(peeled, sha1);
140+
oidcpy(&peeled, oid);
141141
is_annotated = 0;
142142
}
143143

@@ -154,7 +154,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
154154
else
155155
prio = 0;
156156

157-
add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
157+
add_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);
158158
return 0;
159159
}
160160

builtin/fetch.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ static void add_merge_config(struct ref **head,
179179
}
180180
}
181181

182-
static int add_existing(const char *refname, const unsigned char *sha1,
182+
static int add_existing(const char *refname, const struct object_id *oid,
183183
int flag, void *cbdata)
184184
{
185185
struct string_list *list = (struct string_list *)cbdata;
186186
struct string_list_item *item = string_list_insert(list, refname);
187-
item->util = xmalloc(20);
188-
hashcpy(item->util, sha1);
187+
struct object_id *old_oid = xmalloc(sizeof(*old_oid));
188+
189+
oidcpy(old_oid, oid);
190+
item->util = old_oid;
189191
return 0;
190192
}
191193

@@ -913,9 +915,10 @@ static int do_fetch(struct transport *transport,
913915
struct string_list_item *peer_item =
914916
string_list_lookup(&existing_refs,
915917
rm->peer_ref->name);
916-
if (peer_item)
917-
hashcpy(rm->peer_ref->old_sha1,
918-
peer_item->util);
918+
if (peer_item) {
919+
struct object_id *old_oid = peer_item->util;
920+
hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
921+
}
919922
}
920923
}
921924

builtin/for-each-ref.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,8 @@ struct grab_ref_cbdata {
854854
* A call-back given to for_each_ref(). Filter refs and keep them for
855855
* later object processing.
856856
*/
857-
static int grab_single_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
857+
static int grab_single_ref(const char *refname, const struct object_id *oid,
858+
int flag, void *cb_data)
858859
{
859860
struct grab_ref_cbdata *cb = cb_data;
860861
struct refinfo *ref;
@@ -892,7 +893,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
892893
*/
893894
ref = xcalloc(1, sizeof(*ref));
894895
ref->refname = xstrdup(refname);
895-
hashcpy(ref->objectname, sha1);
896+
hashcpy(ref->objectname, oid->hash);
896897
ref->flag = flag;
897898

898899
cnt = cb->grab_cnt;

builtin/fsck.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static int include_reflogs = 1;
2525
static int check_full = 1;
2626
static int check_strict;
2727
static int keep_cache_objects;
28-
static unsigned char head_sha1[20];
28+
static struct object_id head_oid;
2929
static const char *head_points_at;
3030
static int errors_found;
3131
static int write_lost_and_found;
@@ -476,19 +476,21 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
476476
return 0;
477477
}
478478

479-
static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)
479+
static int fsck_handle_reflog(const char *logname, const struct object_id *oid,
480+
int flag, void *cb_data)
480481
{
481482
for_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);
482483
return 0;
483484
}
484485

485-
static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
486+
static int fsck_handle_ref(const char *refname, const struct object_id *oid,
487+
int flag, void *cb_data)
486488
{
487489
struct object *obj;
488490

489-
obj = parse_object(sha1);
491+
obj = parse_object(oid->hash);
490492
if (!obj) {
491-
error("%s: invalid sha1 pointer %s", refname, sha1_to_hex(sha1));
493+
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
492494
errors_found |= ERROR_REACHABLE;
493495
/* We'll continue with the rest despite the error.. */
494496
return 0;
@@ -504,8 +506,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
504506

505507
static void get_default_heads(void)
506508
{
507-
if (head_points_at && !is_null_sha1(head_sha1))
508-
fsck_handle_ref("HEAD", head_sha1, 0, NULL);
509+
if (head_points_at && !is_null_oid(&head_oid))
510+
fsck_handle_ref("HEAD", &head_oid, 0, NULL);
509511
for_each_rawref(fsck_handle_ref, NULL);
510512
if (include_reflogs)
511513
for_each_reflog(fsck_handle_reflog, NULL);
@@ -556,7 +558,7 @@ static int fsck_head_link(void)
556558
if (verbose)
557559
fprintf(stderr, "Checking HEAD link\n");
558560

559-
head_points_at = resolve_ref_unsafe("HEAD", 0, head_sha1, &flag);
561+
head_points_at = resolve_ref_unsafe("HEAD", 0, head_oid.hash, &flag);
560562
if (!head_points_at)
561563
return error("Invalid HEAD");
562564
if (!strcmp(head_points_at, "HEAD"))
@@ -565,7 +567,7 @@ static int fsck_head_link(void)
565567
else if (!starts_with(head_points_at, "refs/heads/"))
566568
return error("HEAD points to something strange (%s)",
567569
head_points_at);
568-
if (is_null_sha1(head_sha1)) {
570+
if (is_null_oid(&head_oid)) {
569571
if (null_is_error)
570572
return error("HEAD: detached HEAD points at nothing");
571573
fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",

builtin/name-rev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ static int tipcmp(const void *a_, const void *b_)
138138
return hashcmp(a->sha1, b->sha1);
139139
}
140140

141-
static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
141+
static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
142142
{
143-
struct object *o = parse_object(sha1);
143+
struct object *o = parse_object(oid->hash);
144144
struct name_ref_data *data = cb_data;
145145
int can_abbreviate_output = data->tags_only && data->name_only;
146146
int deref = 0;
@@ -160,7 +160,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
160160
}
161161
}
162162

163-
add_to_tip_table(sha1, path, can_abbreviate_output);
163+
add_to_tip_table(oid->hash, path, can_abbreviate_output);
164164

165165
while (o && o->type == OBJ_TAG) {
166166
struct tag *t = (struct tag *) o;

builtin/pack-objects.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ static enum write_one_status write_one(struct sha1file *f,
540540
return WRITE_ONE_WRITTEN;
541541
}
542542

543-
static int mark_tagged(const char *path, const unsigned char *sha1, int flag,
543+
static int mark_tagged(const char *path, const struct object_id *oid, int flag,
544544
void *cb_data)
545545
{
546546
unsigned char peeled[20];
547-
struct object_entry *entry = packlist_find(&to_pack, sha1, NULL);
547+
struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);
548548

549549
if (entry)
550550
entry->tagged = 1;
@@ -2097,14 +2097,14 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
20972097
#define ll_find_deltas(l, s, w, d, p) find_deltas(l, &s, w, d, p)
20982098
#endif
20992099

2100-
static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, void *cb_data)
2100+
static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data)
21012101
{
2102-
unsigned char peeled[20];
2102+
struct object_id peeled;
21032103

21042104
if (starts_with(path, "refs/tags/") && /* is a tag? */
2105-
!peel_ref(path, peeled) && /* peelable? */
2106-
packlist_find(&to_pack, peeled, NULL)) /* object packed? */
2107-
add_object_entry(sha1, OBJ_TAG, NULL, 0);
2105+
!peel_ref(path, peeled.hash) && /* peelable? */
2106+
packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */
2107+
add_object_entry(oid->hash, OBJ_TAG, NULL, 0);
21082108
return 0;
21092109
}
21102110

builtin/receive-pack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
197197
}
198198
}
199199

200-
static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)
200+
static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused)
201201
{
202202
path = strip_namespace(path);
203203
/*
@@ -210,7 +210,7 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo
210210
*/
211211
if (!path)
212212
path = ".have";
213-
show_ref(path, sha1);
213+
show_ref(path, oid->hash);
214214
return 0;
215215
}
216216

@@ -228,6 +228,7 @@ static void collect_one_alternate_ref(const struct ref *ref, void *data)
228228
static void write_head_info(void)
229229
{
230230
struct sha1_array sa = SHA1_ARRAY_INIT;
231+
231232
for_each_alternate_ref(collect_one_alternate_ref, &sa);
232233
sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
233234
sha1_array_clear(&sa);

builtin/reflog.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
313313
return 0;
314314
}
315315

316-
static int push_tip_to_list(const char *refname, const unsigned char *sha1,
316+
static int push_tip_to_list(const char *refname, const struct object_id *oid,
317317
int flags, void *cb_data)
318318
{
319319
struct commit_list **list = cb_data;
320320
struct commit *tip_commit;
321321
if (flags & REF_ISSYMREF)
322322
return 0;
323-
tip_commit = lookup_commit_reference_gently(sha1, 1);
323+
tip_commit = lookup_commit_reference_gently(oid->hash, 1);
324324
if (!tip_commit)
325325
return 0;
326326
commit_list_insert(tip_commit, list);
@@ -352,6 +352,7 @@ static void reflog_expiry_prepare(const char *refname,
352352
if (cb->unreachable_expire_kind != UE_ALWAYS) {
353353
if (cb->unreachable_expire_kind == UE_HEAD) {
354354
struct commit_list *elem;
355+
355356
for_each_ref(push_tip_to_list, &cb->tips);
356357
for (elem = cb->tips; elem; elem = elem->next)
357358
commit_list_insert(elem->item, &cb->mark_list);
@@ -379,14 +380,14 @@ static void reflog_expiry_cleanup(void *cb_data)
379380
}
380381
}
381382

382-
static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data)
383+
static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data)
383384
{
384385
struct collected_reflog *e;
385386
struct collect_reflog_cb *cb = cb_data;
386387
size_t namelen = strlen(ref);
387388

388389
e = xmalloc(sizeof(*e) + namelen + 1);
389-
hashcpy(e->sha1, sha1);
390+
hashcpy(e->sha1, oid->hash);
390391
memcpy(e->reflog, ref, namelen + 1);
391392
ALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);
392393
cb->e[cb->nr++] = e;

0 commit comments

Comments
 (0)