Skip to content

Commit cca5fa6

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 34c290a commit cca5fa6

File tree

15 files changed

+25
-24
lines changed

15 files changed

+25
-24
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
371371
const char *colon = strchrnul(name, ':');
372372
int refnamelen = colon - name;
373373

374-
if (!dwim_ref(name, refnamelen, oid.hash, &ref))
374+
if (!dwim_ref(name, refnamelen, &oid, &ref))
375375
die("no such ref: %.*s", refnamelen, name);
376376
free(ref);
377377
}

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
264264
die(_("Not a valid object name: '%s'."), start_name);
265265
}
266266

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)) {
268268
case 0:
269269
/* Not branching from any existing branch */
270270
if (explicit_tracking)

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
823823
if (e->flags & UNINTERESTING)
824824
continue;
825825

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)
827827
continue;
828828

829829
if (refspecs) {

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
975975
return NULL;
976976
ref = rev->cmdline.rev[positive].name;
977977
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) &&
979979
skip_prefix(full_ref, "refs/heads/", &v) &&
980980
!oidcmp(tip_oid, &branch_oid))
981981
branch = xstrdup(v);

builtin/merge-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
156156
struct commit_list *bases;
157157
int i, ret = 0;
158158

159-
switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
159+
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
160160
case 0:
161161
die("No such ref: '%s'", argv[0]);
162162
case 1:

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
454454
if (!remote_head)
455455
die(_("'%s' does not point to a commit"), remote);
456456

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) {
458458
if (starts_with(found_ref, "refs/heads/")) {
459459
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
460460
oid_to_hex(&branch_head), remote);

builtin/rev-parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
133133
struct object_id discard;
134134
char *full;
135135

136-
switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
136+
switch (dwim_ref(name, strlen(name), &discard, &full)) {
137137
case 0:
138138
/*
139139
* Not found -- not a ref. We could

builtin/show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
720720
die(Q_("only %d entry can be shown at one time.",
721721
"only %d entries can be shown at one time.",
722722
MAX_REVS), MAX_REVS);
723-
if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
723+
if (!dwim_ref(*av, strlen(*av), &oid, &ref))
724724
die(_("no such ref %s"), *av);
725725

726726
/* Has the base been specified? */

bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
338338

339339
if (e->item->flags & UNINTERESTING)
340340
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)
342342
goto skip_write_ref;
343343
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
344344
flag = 0;

refs.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,31 +456,32 @@ static char *substitute_branch_name(const char **string, int *len)
456456
return NULL;
457457
}
458458

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)
460460
{
461461
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);
463463
free(last_branch);
464464
return refs_found;
465465
}
466466

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)
468468
{
469469
const char **p, *r;
470470
int refs_found = 0;
471471
struct strbuf fullref = STRBUF_INIT;
472472

473473
*ref = NULL;
474474
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;
477477
int flag;
478478

479-
this_result = refs_found ? sha1_from_ref : sha1;
479+
this_result = refs_found ? &oid_from_ref : oid;
480480
strbuf_reset(&fullref);
481481
strbuf_addf(&fullref, *p, len, str);
482482
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
483-
this_result, &flag);
483+
this_result ? this_result->hash : NULL,
484+
&flag);
484485
if (r) {
485486
if (!refs_found++)
486487
*ref = xstrdup(r);

0 commit comments

Comments
 (0)