aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2017-10-15 22:06:57 +0000
committerJunio C Hamano <gitster@pobox.com>2017-10-16 11:05:51 +0900
commitcca5fa6406046c19ab5a8117fe71bf4402c00d88 (patch)
treeb7305cc09752a86366cb4695cd504adec207e022 /refs.c
parent34c290a6fc8b1f6705d2646d726df2260927da0f (diff)
downloadgit-cca5fa6406046c19ab5a8117fe71bf4402c00d88.tar.gz
git-cca5fa6406046c19ab5a8117fe71bf4402c00d88.tar.xz
refs: convert dwim_ref and expand_ref to struct object_id
All of the callers of these functions just pass the hash member of a struct object_id, so convert them to use a pointer to struct object_id directly. Insert a check for NULL in expand_ref on a temporary basis; this check can be removed when resolve_ref_unsafe is converted as well. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/refs.c b/refs.c
index 9c1f88132..9bb555e7f 100644
--- a/refs.c
+++ b/refs.c
@@ -456,15 +456,15 @@ static char *substitute_branch_name(const char **string, int *len)
return NULL;
}
-int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
{
char *last_branch = substitute_branch_name(&str, &len);
- int refs_found = expand_ref(str, len, sha1, ref);
+ int refs_found = expand_ref(str, len, oid, ref);
free(last_branch);
return refs_found;
}
-int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
+int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
{
const char **p, *r;
int refs_found = 0;
@@ -472,15 +472,16 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
*ref = NULL;
for (p = ref_rev_parse_rules; *p; p++) {
- unsigned char sha1_from_ref[20];
- unsigned char *this_result;
+ struct object_id oid_from_ref;
+ struct object_id *this_result;
int flag;
- this_result = refs_found ? sha1_from_ref : sha1;
+ this_result = refs_found ? &oid_from_ref : oid;
strbuf_reset(&fullref);
strbuf_addf(&fullref, *p, len, str);
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
- this_result, &flag);
+ this_result ? this_result->hash : NULL,
+ &flag);
if (r) {
if (!refs_found++)
*ref = xstrdup(r);