Skip to content

Commit 0df670b

Browse files
committed
Merge branch 'jt/interpret-branch-name-fallback'
"git status" has trouble showing where it came from by interpreting reflog entries that recordcertain events, e.g. "checkout @{u}", and gives a hard/fatal error. Even though it inherently is impossible to give a correct answer because the reflog entries lose some information (e.g. "@{u}" does not record what branch the user was on hence which branch 'the upstream' needs to be computed, and even if the record were available, the relationship between branches may have changed), at least hide the error to allow "status" show its output. * jt/interpret-branch-name-fallback: wt-status: tolerate dangling marks refs: move dwim_ref() to header file sha1-name: replace unsigned int with option struct
2 parents 7364aee + f24c30e commit 0df670b

20 files changed

+98
-53
lines changed

archive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ static void parse_treeish_arg(const char **argv,
397397
const char *colon = strchrnul(name, ':');
398398
int refnamelen = colon - name;
399399

400-
if (!dwim_ref(name, refnamelen, &oid, &ref))
400+
if (!dwim_ref(name, refnamelen, &oid, &ref, 0))
401401
die(_("no such ref: %.*s"), refnamelen, name);
402402
} else {
403-
dwim_ref(name, strlen(name), &oid, &ref);
403+
dwim_ref(name, strlen(name), &oid, &ref, 0);
404404
}
405405

406406
if (get_oid(name, &oid))

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void create_branch(struct repository *r,
281281
die(_("Not a valid object name: '%s'."), start_name);
282282
}
283283

284-
switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref)) {
284+
switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
285285
case 0:
286286
/* Not branching from any existing branch */
287287
if (explicit_tracking)

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static void setup_branch_path(struct branch_info *branch)
651651
* If this is a ref, resolve it; otherwise, look up the OID for our
652652
* expression. Failure here is okay.
653653
*/
654-
if (!dwim_ref(branch->name, strlen(branch->name), &branch->oid, &branch->refname))
654+
if (!dwim_ref(branch->name, strlen(branch->name), &branch->oid, &branch->refname, 0))
655655
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
656656

657657
strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
@@ -1345,7 +1345,7 @@ static void die_expecting_a_branch(const struct branch_info *branch_info)
13451345
struct object_id oid;
13461346
char *to_free;
13471347

1348-
if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free) == 1) {
1348+
if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free, 0) == 1) {
13491349
const char *ref = to_free;
13501350

13511351
if (skip_prefix(ref, "refs/tags/", &ref))

builtin/fast-export.c

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

946-
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1)
946+
if (dwim_ref(e->name, strlen(e->name), &oid, &full_name, 0) != 1)
947947
continue;
948948

949949
if (refspecs.nr) {

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ static char *find_branch_name(struct rev_info *rev)
10611061
return NULL;
10621062
ref = rev->cmdline.rev[positive].name;
10631063
tip_oid = &rev->cmdline.rev[positive].item->oid;
1064-
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
1064+
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref, 0) &&
10651065
skip_prefix(full_ref, "refs/heads/", &v) &&
10661066
oideq(tip_oid, &branch_oid))
10671067
branch = xstrdup(v);

builtin/merge.c

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

503-
if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref) > 0) {
503+
if (dwim_ref(remote, strlen(remote), &branch_head, &found_ref, 0) > 0) {
504504
if (starts_with(found_ref, "refs/heads/")) {
505505
strbuf_addf(msg, "%s\t\tbranch '%s' of .\n",
506506
oid_to_hex(&branch_head), remote);

builtin/reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
423423
char *ref = NULL;
424424
int err;
425425

426-
dwim_ref(rev, strlen(rev), &dummy, &ref);
426+
dwim_ref(rev, strlen(rev), &dummy, &ref, 0);
427427
if (ref && !starts_with(ref, "refs/"))
428428
ref = NULL;
429429

builtin/rev-parse.c

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

139-
switch (dwim_ref(name, strlen(name), &discard, &full)) {
139+
switch (dwim_ref(name, strlen(name), &discard, &full, 0)) {
140140
case 0:
141141
/*
142142
* 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
@@ -741,7 +741,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
741741
die(Q_("only %d entry can be shown at one time.",
742742
"only %d entries can be shown at one time.",
743743
MAX_REVS), MAX_REVS);
744-
if (!dwim_ref(*av, strlen(*av), &oid, &ref))
744+
if (!dwim_ref(*av, strlen(*av), &oid, &ref, 0))
745745
die(_("no such ref %s"), *av);
746746

747747
/* Has the base been specified? */

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv)
185185
end_of_rev = strchrnul(revision, '@');
186186
strbuf_add(&symbolic, revision, end_of_rev - revision);
187187

188-
ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref);
188+
ret = dwim_ref(symbolic.buf, symbolic.len, &dummy, &expanded_ref, 0);
189189
strbuf_release(&symbolic);
190190
switch (ret) {
191191
case 0: /* Not found, but valid ref */

0 commit comments

Comments
 (0)