builtin/show-branch: rewrite functions to take object_id arguments
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
May 25, 2015 at 18:38 UTC
2e253a4a12a63e7c3e807e555641539dd19ae2fa
1 file changed
+17
-18
builtin/show-branch.c
+17
-18
@@ -394,39 +394,42 @@ static int append_ref(const char *refname, const unsigned char *sha1,
394
return 0;
395
}
396
397
-static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
397
+static int append_head_ref(const char *refname, const struct object_id *oid,
398
+ int flag, void *cb_data)
399
{
399
- unsigned char tmp[20];
400
+ struct object_id tmp;
401
int ofs = 11;
402
if (!starts_with(refname, "refs/heads/"))
403
return 0;
404
/* If both heads/foo and tags/foo exists, get_sha1 would
405
* get confused.
406
*/
406
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
407
+ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
408
ofs = 5;
408
- return append_ref(refname + ofs, sha1, 0);
409
+ return append_ref(refname + ofs, oid->hash, 0);
410
}
411
411
-static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
412
+static int append_remote_ref(const char *refname, const struct object_id *oid,
413
+ int flag, void *cb_data)
414
{
413
- unsigned char tmp[20];
415
+ struct object_id tmp;
416
int ofs = 13;
417
if (!starts_with(refname, "refs/remotes/"))
418
return 0;
419
/* If both heads/foo and tags/foo exists, get_sha1 would
420
* get confused.
421
*/
420
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
422
+ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
423
ofs = 5;
422
- return append_ref(refname + ofs, sha1, 0);
424
+ return append_ref(refname + ofs, oid->hash, 0);
425
}
426
425
-static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
427
+static int append_tag_ref(const char *refname, const struct object_id *oid,
428
+ int flag, void *cb_data)
429
{
430
if (!starts_with(refname, "refs/tags/"))
431
return 0;
429
- return append_ref(refname + 5, sha1, 0);
432
+ return append_ref(refname + 5, oid->hash, 0);
433
}
434
435
static const char *match_ref_pattern = NULL;
@@ -457,9 +460,9 @@ static int append_matching_ref(const char *refname, const struct object_id *oid,
460
if (wildmatch(match_ref_pattern, tail, 0, NULL))
461
return 0;
462
if (starts_with(refname, "refs/heads/"))
460
- return append_head_ref(refname, oid->hash, flag, cb_data);
463
+ return append_head_ref(refname, oid, flag, cb_data);
464
if (starts_with(refname, "refs/tags/"))
462
- return append_tag_ref(refname, oid->hash, flag, cb_data);
465
+ return append_tag_ref(refname, oid, flag, cb_data);
466
return append_ref(refname, oid->hash, 0);
467
}
468
@@ -467,18 +470,14 @@ static void snarf_refs(int head, int remotes)
470
{
471
if (head) {
472
int orig_cnt = ref_name_cnt;
470
- struct each_ref_fn_sha1_adapter wrapped_append_head_ref =
471
- {append_head_ref, NULL};
473
473
- for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref);
474
+ for_each_ref(append_head_ref, NULL);
475
sort_ref_range(orig_cnt, ref_name_cnt);
476
}
477
if (remotes) {
478
int orig_cnt = ref_name_cnt;
478
- struct each_ref_fn_sha1_adapter wrapped_append_remote_ref =
479
- {append_remote_ref, NULL};
479
481
- for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref);
480
+ for_each_ref(append_remote_ref, NULL);
481
sort_ref_range(orig_cnt, ref_name_cnt);
482
}
483
}