1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 22:06:20 +02:00

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:
brian m. carlson 2017-10-15 22:06:57 +00:00 committed by Junio C Hamano
parent 34c290a6fc
commit cca5fa6406
15 changed files with 25 additions and 24 deletions

View File

@ -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);
}

View File

@ -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)

View File

@ -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) {

View File

@ -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);

View File

@ -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:

View File

@ -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);

View File

@ -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

View File

@ -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? */

View File

@ -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;

15
refs.c
View File

@ -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);

4
refs.h
View File

@ -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);
/*

View File

@ -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]);

View File

@ -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;

View File

@ -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);

View File

@ -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 */