Skip to content

Commit 9608a19

Browse files
committed
name-ref: factor out name shortening logic from name_ref()
The logic will be used in a new codepath for showing exact matches. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96ffd4c commit 9608a19

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

builtin/name-rev.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ static int subpath_matches(const char *path, const char *filter)
9696
return -1;
9797
}
9898

99+
static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
100+
{
101+
if (shorten_unambiguous)
102+
refname = shorten_unambiguous_ref(refname, 0);
103+
else if (!prefixcmp(refname, "refs/heads/"))
104+
refname = refname + 11;
105+
else if (!prefixcmp(refname, "refs/"))
106+
refname = refname + 5;
107+
return refname;
108+
}
109+
99110
struct name_ref_data {
100111
int tags_only;
101112
int name_only;
@@ -134,13 +145,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
134145
if (o && o->type == OBJ_COMMIT) {
135146
struct commit *commit = (struct commit *)o;
136147

137-
if (can_abbreviate_output)
138-
path = shorten_unambiguous_ref(path, 0);
139-
else if (!prefixcmp(path, "refs/heads/"))
140-
path = path + 11;
141-
else if (!prefixcmp(path, "refs/"))
142-
path = path + 5;
143-
148+
path = name_ref_abbrev(path, can_abbreviate_output);
144149
name_rev(commit, xstrdup(path), 0, 0, deref);
145150
}
146151
return 0;

0 commit comments

Comments
 (0)