Commit cca5fa64 authored by brian m. carlson's avatar brian m. carlson Committed by Junio C Hamano

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's avatarbrian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
parent 34c290a6
......@@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
const char *colon = strchrnul(name, ':');
int refnamelen = colon - name;
if (!dwim_ref(name, refnamelen, oid.hash, &ref))
if (!dwim_ref(name, refnamelen, &oid, &ref))
die("no such ref: %.*s", refnamelen, name);
free(ref);
}
......
......@@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
die(_("Not a valid object name: '%s'."), start_name);
}
switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) {
switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref)) {
case 0:
/* Not branching from any existing branch */
if (explicit_tracking)
......
......@@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
if (e->flags & UNINTERESTING)
continue;
if (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
continue;
if (refspecs) {
......
......@@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
return NULL;
ref = rev->cmdline.rev[positive].name;
tip_oid = &rev->cmdline.rev[positive].item->oid;
if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
!oidcmp(tip_oid, &branch_oid))
branch = xstrdup(v);
......
......@@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
struct commit_list *bases;
int i, ret = 0;
switch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {
switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) {
case 0:
die("No such ref: '%s'", argv[0]);
case 1:
......
......@@ -454,7 +454,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
if (!remote_head)
die(_("'%s' does not point to a commit"), remote);
if (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {
if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref) > 0) {
if (starts_with(found_ref, "refs/heads/")) {
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
oid_to_hex(&branch_head), remote);
......
......@@ -133,7 +133,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
struct object_id discard;
char *full;
switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
switch (dwim_ref(name, strlen(name), &discard, &full)) {
case 0:
/*
* Not found -- not a ref. We could
......
......@@ -720,7 +720,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
die(Q_("only %d entry can be shown at one time.",
"only %d entries can be shown at one time.",
MAX_REVS), MAX_REVS);
if (!dwim_ref(*av, strlen(*av), oid.hash, &ref))
if (!dwim_ref(*av, strlen(*av), &oid, &ref))
die(_("no such ref %s"), *av);
/* Has the base been specified? */
......
......@@ -338,7 +338,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
if (e->item->flags & UNINTERESTING)
continue;
if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
if (dwim_ref(e->name, strlen(e->name), &oid, &ref) != 1)
goto skip_write_ref;
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
flag = 0;
......
......@@ -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);
......
......@@ -139,8 +139,8 @@ int resolve_gitlink_ref(const char *submodule, const char *refname,
*/
int refname_match(const char *abbrev_name, const char *full_name);
int expand_ref(const char *str, int len, unsigned char *sha1, char **ref);
int dwim_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);
int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
/*
......
......@@ -1629,7 +1629,7 @@ static void set_merge(struct branch *ret)
strcmp(ret->remote_name, "."))
continue;
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
oid.hash, &ref) == 1)
&oid, &ref) == 1)
ret->merge[i]->dst = ref;
else
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
......
......@@ -603,7 +603,7 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
refs_found = dwim_ref(str, len, &tmp_oid, &real_ref);
if (refs_found > 0) {
warning(warn_msg, len, str);
if (advice_object_name_warning)
......@@ -654,11 +654,11 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
if (!len && reflog_len)
/* allow "@{...}" to mean the current branch reflog */
refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
refs_found = dwim_ref("HEAD", 4, oid, &real_ref);
else if (reflog_len)
refs_found = dwim_log(str, len, oid->hash, &real_ref);
else
refs_found = dwim_ref(str, len, oid->hash, &real_ref);
refs_found = dwim_ref(str, len, oid, &real_ref);
if (!refs_found)
return -1;
......
......@@ -787,7 +787,7 @@ static void receive_needs(void)
if (skip_prefix(line, "deepen-not ", &arg)) {
char *ref = NULL;
struct object_id oid;
if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1)
if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
die("git upload-pack: ambiguous deepen-not: %s", line);
string_list_append(&deepen_not, ref);
free(ref);
......
......@@ -1449,7 +1449,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
return;
}
if (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&
if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
/* sha1 is a commit? match without further lookup */
(!oidcmp(&cb.noid, &oid) ||
/* perhaps sha1 is a tag, try to dereference to a commit */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment