builtin/show-branch: rewrite functions to work with object_id
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
d1516bf4629cf2b4382a307ea0b3d7c26d2bfdca
1 file changed
+21
-21
builtin/show-branch.c
+21
-21
@@ -369,10 +369,10 @@ static void sort_ref_range(int bottom, int top)
369
compare_ref_name);
370
}
371
372
-static int append_ref(const char *refname, const unsigned char *sha1,
372
+static int append_ref(const char *refname, const struct object_id *oid,
373
int allow_dups)
374
{
375
- struct commit *commit = lookup_commit_reference_gently(sha1, 1);
375
+ struct commit *commit = lookup_commit_reference_gently(oid->hash, 1);
376
int i;
377
378
if (!commit)
@@ -406,7 +406,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
406
*/
407
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
408
ofs = 5;
409
- return append_ref(refname + ofs, oid->hash, 0);
409
+ return append_ref(refname + ofs, oid, 0);
410
}
411
412
static int append_remote_ref(const char *refname, const struct object_id *oid,
@@ -421,7 +421,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
421
*/
422
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
423
ofs = 5;
424
- return append_ref(refname + ofs, oid->hash, 0);
424
+ return append_ref(refname + ofs, oid, 0);
425
}
426
427
static int append_tag_ref(const char *refname, const struct object_id *oid,
@@ -429,7 +429,7 @@ static int append_tag_ref(const char *refname, const struct object_id *oid,
429
{
430
if (!starts_with(refname, "refs/tags/"))
431
return 0;
432
- return append_ref(refname + 5, oid->hash, 0);
432
+ return append_ref(refname + 5, oid, 0);
433
}
434
435
static const char *match_ref_pattern = NULL;
@@ -463,7 +463,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid,
463
return append_head_ref(refname, oid, flag, cb_data);
464
if (starts_with(refname, "refs/tags/"))
465
return append_tag_ref(refname, oid, flag, cb_data);
466
- return append_ref(refname, oid->hash, 0);
466
+ return append_ref(refname, oid, 0);
467
}
468
469
static void snarf_refs(int head, int remotes)
@@ -538,7 +538,7 @@ static void append_one_rev(const char *av)
538
{
539
struct object_id revkey;
540
if (!get_sha1(av, revkey.hash)) {
541
- append_ref(av, revkey.hash, 0);
541
+ append_ref(av, &revkey, 0);
542
return;
543
}
544
if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
@@ -643,7 +643,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
643
char head[128];
644
const char *head_p;
645
int head_len;
646
- unsigned char head_sha1[20];
646
+ struct object_id head_oid;
647
int merge_base = 0;
648
int independent = 0;
649
int no_name = 0;
@@ -729,7 +729,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
729
all_heads = 1;
730
731
if (reflog) {
732
- unsigned char sha1[20];
732
+ struct object_id oid;
733
char nth_desc[256];
734
char *ref;
735
int base = 0;
@@ -740,7 +740,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
740
741
fake_av[0] = resolve_refdup("HEAD",
742
RESOLVE_REF_READING,
743
- sha1, NULL);
743
+ oid.hash, NULL);
744
fake_av[1] = NULL;
745
av = fake_av;
746
ac = 1;
@@ -751,7 +751,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
751
if (MAX_REVS < reflog)
752
die("Only %d entries can be shown at one time.",
753
MAX_REVS);
754
- if (!dwim_ref(*av, strlen(*av), sha1, &ref))
754
+ if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
755
die("No such ref %s", *av);
756
757
/* Has the base been specified? */
@@ -762,7 +762,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
762
/* Ah, that is a date spec... */
763
unsigned long at;
764
at = approxidate(reflog_base);
765
- read_ref_at(ref, flags, at, -1, sha1, NULL,
765
+ read_ref_at(ref, flags, at, -1, oid.hash, NULL,
766
NULL, NULL, &base);
767
}
768
}
@@ -773,7 +773,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
773
unsigned long timestamp;
774
int tz;
775
776
- if (read_ref_at(ref, flags, 0, base+i, sha1, &logmsg,
776
+ if (read_ref_at(ref, flags, 0, base+i, oid.hash, &logmsg,
777
×tamp, &tz, NULL)) {
778
reflog = i;
779
break;
@@ -788,7 +788,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
788
msg);
789
free(logmsg);
790
sprintf(nth_desc, "%s@{%d}", *av, base+i);
791
- append_ref(nth_desc, sha1, 1);
791
+ append_ref(nth_desc, &oid, 1);
792
}
793
free(ref);
794
}
@@ -802,7 +802,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
802
}
803
804
head_p = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
805
- head_sha1, NULL);
805
+ head_oid.hash, NULL);
806
if (head_p) {
807
head_len = strlen(head_p);
808
memcpy(head, head_p, head_len + 1);
@@ -821,7 +821,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
821
if (rev_is_head(head,
822
head_len,
823
ref_name[i],
824
- head_sha1, NULL))
824
+ head_oid.hash, NULL))
825
has_head++;
826
}
827
if (!has_head) {
@@ -836,17 +836,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
836
}
837
838
for (num_rev = 0; ref_name[num_rev]; num_rev++) {
839
- unsigned char revkey[20];
839
+ struct object_id revkey;
840
unsigned int flag = 1u << (num_rev + REV_SHIFT);
841
842
if (MAX_REVS <= num_rev)
843
die("cannot handle more than %d revs.", MAX_REVS);
844
- if (get_sha1(ref_name[num_rev], revkey))
844
+ if (get_sha1(ref_name[num_rev], revkey.hash))
845
die("'%s' is not a valid ref.", ref_name[num_rev]);
846
- commit = lookup_commit_reference(revkey);
846
+ commit = lookup_commit_reference(revkey.hash);
847
if (!commit)
848
die("cannot find commit %s (%s)",
849
- ref_name[num_rev], revkey);
849
+ ref_name[num_rev], revkey.hash);
850
parse_commit(commit);
851
mark_seen(commit, &seen);
852
@@ -880,7 +880,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
880
int is_head = rev_is_head(head,
881
head_len,
882
ref_name[i],
883
- head_sha1,
883
+ head_oid.hash,
884
rev[i]->object.sha1);
885
if (extra < 0)
886
printf("%c [%s] ",