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>
brian m. carlson committed
Oct 15, 2017 at 22:06 UTC
cca5fa6406046c19ab5a8117fe71bf4402c00d88
15 files changed
+25
-24
archive.c
+1
-1
@@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
371
const char *colon = strchrnul(name, ':');
372
int refnamelen = colon - name;
373
374
- if (!dwim_ref(name, refnamelen, oid.hash, &ref))
374
+ if (!dwim_ref(name, refnamelen, &oid, &ref))
375
die("no such ref: %.*s", refnamelen, name);
376
free(ref);
377
}
branch.c
+1
-1
@@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
264
die(_("Not a valid object name: '%s'."), start_name);
265
}
266
267
- switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) {
267
+ switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref)) {
268
case 0:
269
/* Not branching from any existing branch */
270
if (explicit_tracking)
builtin/fast-export.c
+1
-1
@@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
823
if (e->flags & UNINTERESTING)
824
continue;
825
826
- if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
826
+ if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
827
continue;
828
829
if (refspecs) {
builtin/log.c
+1
-1
@@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
975
return NULL;
976
ref = rev->cmdline.rev[positive].name;
977
tip_oid = &rev->cmdline.rev[positive].item->oid;
978
- if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
978
+ if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
979
skip_prefix(full_ref, "refs/heads/", &v) &&
980
!oidcmp(tip_oid, &branch_oid))
981
branch = xstrdup(v);
builtin/merge-base.c
+1
-1
@@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
156
struct commit_list *bases;
157
int i, ret = 0;
158
159
- switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
159
+ switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
160
case 0:
161
die("No such ref: '%s'", argv[0]);
162
case 1:
builtin/merge.c
+1
-1
@@ -454,7 +454,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
454
if (!remote_head)
455
die(_("'%s' does not point to a commit"), remote);
456
457
- if (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {
457
+ if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref) > 0) {
458
if (starts_with(found_ref, "refs/heads/")) {
459
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
460
oid_to_hex(&branch_head), remote);
builtin/rev-parse.c
+1
-1
@@ -133,7 +133,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
133
struct object_id discard;
134
char *full;
135
136
- switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
136
+ switch (dwim_ref(name, strlen(name), &discard, &full)) {
137
case 0:
138
/*
139
* Not found -- not a ref. We could
builtin/show-branch.c
+1
-1
@@ -720,7 +720,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
720
die(Q_("only %d entry can be shown at one time.",
721
"only %d entries can be shown at one time.",
722
MAX_REVS), MAX_REVS);
723
- if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
723
+ if (!dwim_ref(*av, strlen(*av), &oid, &ref))
724
die(_("no such ref %s"), *av);
725
726
/* Has the base been specified? */
bundle.c
+1
-1
@@ -338,7 +338,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
338
339
if (e->item->flags & UNINTERESTING)
340
continue;
341
- if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
341
+ if (dwim_ref(e->name, strlen(e->name), &oid, &ref) != 1)
342
goto skip_write_ref;
343
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
344
flag = 0;
refs.c
+8
-7
@@ -456,15 +456,15 @@ static char *substitute_branch_name(const char **string, int *len)
456
return NULL;
457
}
458
459
-int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
459
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref)
460
{
461
char *last_branch = substitute_branch_name(&str, &len);
462
- int refs_found = expand_ref(str, len, sha1, ref);
462
+ int refs_found = expand_ref(str, len, oid, ref);
463
free(last_branch);
464
return refs_found;
465
}
466
467
-int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
467
+int expand_ref(const char *str, int len, struct object_id *oid, char **ref)
468
{
469
const char **p, *r;
470
int refs_found = 0;
@@ -472,15 +472,16 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
472
473
*ref = NULL;
474
for (p = ref_rev_parse_rules; *p; p++) {
475
- unsigned char sha1_from_ref[20];
476
- unsigned char *this_result;
475
+ struct object_id oid_from_ref;
476
+ struct object_id *this_result;
477
int flag;
478
479
- this_result = refs_found ? sha1_from_ref : sha1;
479
+ this_result = refs_found ? &oid_from_ref : oid;
480
strbuf_reset(&fullref);
481
strbuf_addf(&fullref, *p, len, str);
482
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
483
- this_result, &flag);
483
+ this_result ? this_result->hash : NULL,
484
+ &flag);
485
if (r) {
486
if (!refs_found++)
487
*ref = xstrdup(r);
refs.h
+2
-2
@@ -139,8 +139,8 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
139
*/
140
int refname_match(const char *abbrev_name, const char *full_name);
141
142
-int expand_ref(const char *str, int len, unsigned char *sha1, char **ref);
143
-int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
142
+int expand_ref(const char *str, int len, struct object_id *oid, char **ref);
143
+int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
144
int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
145
146
/*
remote.c
+1
-1
@@ -1629,7 +1629,7 @@ static void set_merge(struct branch *ret)
1629
strcmp(ret->remote_name, "."))
1630
continue;
1631
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
1632
- oid.hash, &ref) == 1)
1632
+ &oid, &ref) == 1)
1633
ret->merge[i]->dst = ref;
1634
else
1635
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
sha1_name.c
+3
-3
@@ -603,7 +603,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
603
604
if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
605
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
606
- refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
606
+ refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
607
if (refs_found > 0) {
608
warning(warn_msg, len, str);
609
if (advice_object_name_warning)
@@ -654,11 +654,11 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
654
655
if (!len && reflog_len)
656
/* allow "@{...}" to mean the current branch reflog */
657
- refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
657
+ refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
658
else if (reflog_len)
659
refs_found = dwim_log(str, len, oid->hash, &real_ref);
660
else
661
- refs_found = dwim_ref(str, len, oid->hash, &real_ref);
661
+ refs_found = dwim_ref(str, len, oid, &real_ref);
662
663
if (!refs_found)
664
return -1;
upload-pack.c
+1
-1
@@ -787,7 +787,7 @@ static void receive_needs(void)
787
if (skip_prefix(line, "deepen-not ", &arg)) {
788
char *ref = NULL;
789
struct object_id oid;
790
- if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1)
790
+ if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
791
die("git upload-pack: ambiguous deepen-not: %s", line);
792
string_list_append(&deepen_not, ref);
793
free(ref);
wt-status.c
+1
-1
@@ -1449,7 +1449,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1449
return;
1450
}
1451
1452
- if (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&
1452
+ if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
1453
/* sha1 is a commit? match without further lookup */
1454
(!oidcmp(&cb.noid, &oid) ||
1455
/* perhaps sha1 is a tag, try to dereference to a commit */