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>
This commit is contained in:
parent
34c290a6fc
commit
cca5fa6406
@ -371,7 +371,7 @@ static void parse_treeish_arg(const char **argv,
|
|||||||
const char *colon = strchrnul(name, ':');
|
const char *colon = strchrnul(name, ':');
|
||||||
int refnamelen = colon - 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);
|
die("no such ref: %.*s", refnamelen, name);
|
||||||
free(ref);
|
free(ref);
|
||||||
}
|
}
|
||||||
|
2
branch.c
2
branch.c
@ -264,7 +264,7 @@ void create_branch(const char *name, const char *start_name,
|
|||||||
die(_("Not a valid object name: '%s'."), 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:
|
case 0:
|
||||||
/* Not branching from any existing branch */
|
/* Not branching from any existing branch */
|
||||||
if (explicit_tracking)
|
if (explicit_tracking)
|
||||||
|
@ -823,7 +823,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)
|
|||||||
if (e->flags & UNINTERESTING)
|
if (e->flags & UNINTERESTING)
|
||||||
continue;
|
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;
|
continue;
|
||||||
|
|
||||||
if (refspecs) {
|
if (refspecs) {
|
||||||
|
@ -975,7 +975,7 @@ static char *find_branch_name(struct rev_info *rev)
|
|||||||
return NULL;
|
return NULL;
|
||||||
ref = rev->cmdline.rev[positive].name;
|
ref = rev->cmdline.rev[positive].name;
|
||||||
tip_oid = &rev->cmdline.rev[positive].item->oid;
|
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) &&
|
skip_prefix(full_ref, "refs/heads/", &v) &&
|
||||||
!oidcmp(tip_oid, &branch_oid))
|
!oidcmp(tip_oid, &branch_oid))
|
||||||
branch = xstrdup(v);
|
branch = xstrdup(v);
|
||||||
|
@ -156,7 +156,7 @@ static int handle_fork_point(int argc, const char **argv)
|
|||||||
struct commit_list *bases;
|
struct commit_list *bases;
|
||||||
int i, ret = 0;
|
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:
|
case 0:
|
||||||
die("No such ref: '%s'", argv[0]);
|
die("No such ref: '%s'", argv[0]);
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -454,7 +454,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
|
|||||||
if (!remote_head)
|
if (!remote_head)
|
||||||
die(_("'%s' does not point to a commit"), remote);
|
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/")) {
|
if (starts_with(found_ref, "refs/heads/")) {
|
||||||
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
|
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
|
||||||
oid_to_hex(&branch_head), remote);
|
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;
|
struct object_id discard;
|
||||||
char *full;
|
char *full;
|
||||||
|
|
||||||
switch (dwim_ref(name, strlen(name), discard.hash, &full)) {
|
switch (dwim_ref(name, strlen(name), &discard, &full)) {
|
||||||
case 0:
|
case 0:
|
||||||
/*
|
/*
|
||||||
* Not found -- not a ref. We could
|
* 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.",
|
die(Q_("only %d entry can be shown at one time.",
|
||||||
"only %d entries can be shown at one time.",
|
"only %d entries can be shown at one time.",
|
||||||
MAX_REVS), MAX_REVS);
|
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);
|
die(_("no such ref %s"), *av);
|
||||||
|
|
||||||
/* Has the base been specified? */
|
/* Has the base been specified? */
|
||||||
|
2
bundle.c
2
bundle.c
@ -338,7 +338,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
|
|||||||
|
|
||||||
if (e->item->flags & UNINTERESTING)
|
if (e->item->flags & UNINTERESTING)
|
||||||
continue;
|
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;
|
goto skip_write_ref;
|
||||||
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
|
if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
|
||||||
flag = 0;
|
flag = 0;
|
||||||
|
15
refs.c
15
refs.c
@ -456,15 +456,15 @@ static char *substitute_branch_name(const char **string, int *len)
|
|||||||
return NULL;
|
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);
|
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);
|
free(last_branch);
|
||||||
return refs_found;
|
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;
|
const char **p, *r;
|
||||||
int refs_found = 0;
|
int refs_found = 0;
|
||||||
@ -472,15 +472,16 @@ int expand_ref(const char *str, int len, unsigned char *sha1, char **ref)
|
|||||||
|
|
||||||
*ref = NULL;
|
*ref = NULL;
|
||||||
for (p = ref_rev_parse_rules; *p; p++) {
|
for (p = ref_rev_parse_rules; *p; p++) {
|
||||||
unsigned char sha1_from_ref[20];
|
struct object_id oid_from_ref;
|
||||||
unsigned char *this_result;
|
struct object_id *this_result;
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
this_result = refs_found ? sha1_from_ref : sha1;
|
this_result = refs_found ? &oid_from_ref : oid;
|
||||||
strbuf_reset(&fullref);
|
strbuf_reset(&fullref);
|
||||||
strbuf_addf(&fullref, *p, len, str);
|
strbuf_addf(&fullref, *p, len, str);
|
||||||
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
|
r = resolve_ref_unsafe(fullref.buf, RESOLVE_REF_READING,
|
||||||
this_result, &flag);
|
this_result ? this_result->hash : NULL,
|
||||||
|
&flag);
|
||||||
if (r) {
|
if (r) {
|
||||||
if (!refs_found++)
|
if (!refs_found++)
|
||||||
*ref = xstrdup(r);
|
*ref = xstrdup(r);
|
||||||
|
4
refs.h
4
refs.h
@ -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 refname_match(const char *abbrev_name, const char *full_name);
|
||||||
|
|
||||||
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);
|
||||||
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);
|
||||||
int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
|
int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
2
remote.c
2
remote.c
@ -1629,7 +1629,7 @@ static void set_merge(struct branch *ret)
|
|||||||
strcmp(ret->remote_name, "."))
|
strcmp(ret->remote_name, "."))
|
||||||
continue;
|
continue;
|
||||||
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
|
if (dwim_ref(ret->merge_name[i], strlen(ret->merge_name[i]),
|
||||||
oid.hash, &ref) == 1)
|
&oid, &ref) == 1)
|
||||||
ret->merge[i]->dst = ref;
|
ret->merge[i]->dst = ref;
|
||||||
else
|
else
|
||||||
ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
|
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 (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
|
||||||
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
|
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) {
|
if (refs_found > 0) {
|
||||||
warning(warn_msg, len, str);
|
warning(warn_msg, len, str);
|
||||||
if (advice_object_name_warning)
|
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)
|
if (!len && reflog_len)
|
||||||
/* allow "@{...}" to mean the current branch reflog */
|
/* 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)
|
else if (reflog_len)
|
||||||
refs_found = dwim_log(str, len, oid->hash, &real_ref);
|
refs_found = dwim_log(str, len, oid->hash, &real_ref);
|
||||||
else
|
else
|
||||||
refs_found = dwim_ref(str, len, oid->hash, &real_ref);
|
refs_found = dwim_ref(str, len, oid, &real_ref);
|
||||||
|
|
||||||
if (!refs_found)
|
if (!refs_found)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -787,7 +787,7 @@ static void receive_needs(void)
|
|||||||
if (skip_prefix(line, "deepen-not ", &arg)) {
|
if (skip_prefix(line, "deepen-not ", &arg)) {
|
||||||
char *ref = NULL;
|
char *ref = NULL;
|
||||||
struct object_id oid;
|
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);
|
die("git upload-pack: ambiguous deepen-not: %s", line);
|
||||||
string_list_append(&deepen_not, ref);
|
string_list_append(&deepen_not, ref);
|
||||||
free(ref);
|
free(ref);
|
||||||
|
@ -1449,7 +1449,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
|
|||||||
return;
|
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 */
|
/* sha1 is a commit? match without further lookup */
|
||||||
(!oidcmp(&cb.noid, &oid) ||
|
(!oidcmp(&cb.noid, &oid) ||
|
||||||
/* perhaps sha1 is a tag, try to dereference to a commit */
|
/* perhaps sha1 is a tag, try to dereference to a commit */
|
||||||
|
Loading…
Reference in New Issue
Block a user