summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Michael Haggerty <mhagger@alum.mit.edu>2015-05-25 18:38:46 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-05-25 12:19:31 -0700
commit2e253a4a12a63e7c3e807e555641539dd19ae2fa (patch)
tree0b0e66ef9f41b8c348f904c796392698a0d510b1
parentappend_matching_ref(): rewrite to take an object_id argument (diff)
downloadtgif-2e253a4a12a63e7c3e807e555641539dd19ae2fa.tar.xz
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>
-rw-r--r--builtin/show-branch.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index b06f9668ee..7e006577e2 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -394,39 +394,42 @@ static int append_ref(const char *refname, const unsigned char *sha1,
return 0;
}
-static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+static int append_head_ref(const char *refname, const struct object_id *oid,
+ int flag, void *cb_data)
{
- unsigned char tmp[20];
+ struct object_id tmp;
int ofs = 11;
if (!starts_with(refname, "refs/heads/"))
return 0;
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
+ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
ofs = 5;
- return append_ref(refname + ofs, sha1, 0);
+ return append_ref(refname + ofs, oid->hash, 0);
}
-static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+static int append_remote_ref(const char *refname, const struct object_id *oid,
+ int flag, void *cb_data)
{
- unsigned char tmp[20];
+ struct object_id tmp;
int ofs = 13;
if (!starts_with(refname, "refs/remotes/"))
return 0;
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
- if (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))
+ if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
ofs = 5;
- return append_ref(refname + ofs, sha1, 0);
+ return append_ref(refname + ofs, oid->hash, 0);
}
-static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+static int append_tag_ref(const char *refname, const struct object_id *oid,
+ int flag, void *cb_data)
{
if (!starts_with(refname, "refs/tags/"))
return 0;
- return append_ref(refname + 5, sha1, 0);
+ return append_ref(refname + 5, oid->hash, 0);
}
static const char *match_ref_pattern = NULL;
@@ -457,9 +460,9 @@ static int append_matching_ref(const char *refname, const struct object_id *oid,
if (wildmatch(match_ref_pattern, tail, 0, NULL))
return 0;
if (starts_with(refname, "refs/heads/"))
- return append_head_ref(refname, oid->hash, flag, cb_data);
+ return append_head_ref(refname, oid, flag, cb_data);
if (starts_with(refname, "refs/tags/"))
- return append_tag_ref(refname, oid->hash, flag, cb_data);
+ return append_tag_ref(refname, oid, flag, cb_data);
return append_ref(refname, oid->hash, 0);
}
@@ -467,18 +470,14 @@ static void snarf_refs(int head, int remotes)
{
if (head) {
int orig_cnt = ref_name_cnt;
- struct each_ref_fn_sha1_adapter wrapped_append_head_ref =
- {append_head_ref, NULL};
- for_each_ref(each_ref_fn_adapter, &wrapped_append_head_ref);
+ for_each_ref(append_head_ref, NULL);
sort_ref_range(orig_cnt, ref_name_cnt);
}
if (remotes) {
int orig_cnt = ref_name_cnt;
- struct each_ref_fn_sha1_adapter wrapped_append_remote_ref =
- {append_remote_ref, NULL};
- for_each_ref(each_ref_fn_adapter, &wrapped_append_remote_ref);
+ for_each_ref(append_remote_ref, NULL);
sort_ref_range(orig_cnt, ref_name_cnt);
}
}