Skip to content

Commit 2c817df

Browse files
author
Junio C Hamano
committed
name-rev: do not omit leading components of ref name.
In a repository with mainto/1.0 (to keep maintaining the 1.0.X series) and fixo/1.0 (to keep fixes that apply to both 1.0.X series and upwards) branches, "git-name-rev mainto/1.0" answered just "1.0" making things ambiguous. Show refnames unambiguously like show-branch does. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent a94d994 commit 2c817df

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

name-rev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ static int name_ref(const char *path, const unsigned char *sha1)
9393
}
9494
if (o && o->type == commit_type) {
9595
struct commit *commit = (struct commit *)o;
96-
const char *p;
9796

98-
while ((p = strchr(path, '/')))
99-
path = p+1;
97+
if (!strncmp(path, "refs/heads/", 11))
98+
path = path + 11;
99+
else if (!strncmp(path, "refs/", 5))
100+
path = path + 5;
100101

101102
name_rev(commit, strdup(path), 0, 0, deref);
102103
}

t/t6010-merge-base.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ H=$(doit 8 H $A $F)
4646

4747
test_expect_success 'compute merge-base (single)' \
4848
'MB=$(git-merge-base G H) &&
49-
expr "$(git-name-rev "$MB")" : "[0-9a-f]* B"'
49+
expr "$(git-name-rev "$MB")" : "[0-9a-f]* tags/B"'
5050

5151
test_expect_success 'compute merge-base (all)' \
5252
'MB=$(git-merge-base --all G H) &&
53-
expr "$(git-name-rev "$MB")" : "[0-9a-f]* B"'
53+
expr "$(git-name-rev "$MB")" : "[0-9a-f]* tags/B"'
5454

5555
test_expect_success 'compute merge-base with show-branch' \
5656
'MB=$(git-show-branch --merge-base G H) &&
57-
expr "$(git-name-rev "$MB")" : "[0-9a-f]* B"'
57+
expr "$(git-name-rev "$MB")" : "[0-9a-f]* tags/B"'
5858

5959
test_done

0 commit comments

Comments
 (0)