summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-07-07 21:13:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-07-07 22:32:23 (GMT)
commit9608a190c0344a55b1d106c1cca17b17fe276c86 (patch)
tree88cd554239c987a073593f8eb9d384d73543d36c /builtin
parent96ffd4ca937616c4a419cb9e2ef80b3156acaf80 (diff)
downloadgit-9608a190c0344a55b1d106c1cca17b17fe276c86.zip
git-9608a190c0344a55b1d106c1cca17b17fe276c86.tar.gz
git-9608a190c0344a55b1d106c1cca17b17fe276c86.tar.bz2
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 <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/name-rev.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index 87d4854..1234ebb 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -96,6 +96,17 @@ static int subpath_matches(const char *path, const char *filter)
return -1;
}
+static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
+{
+ if (shorten_unambiguous)
+ refname = shorten_unambiguous_ref(refname, 0);
+ else if (!prefixcmp(refname, "refs/heads/"))
+ refname = refname + 11;
+ else if (!prefixcmp(refname, "refs/"))
+ refname = refname + 5;
+ return refname;
+}
+
struct name_ref_data {
int tags_only;
int name_only;
@@ -134,13 +145,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void
if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o;
- if (can_abbreviate_output)
- path = shorten_unambiguous_ref(path, 0);
- else if (!prefixcmp(path, "refs/heads/"))
- path = path + 11;
- else if (!prefixcmp(path, "refs/"))
- path = path + 5;
-
+ path = name_ref_abbrev(path, can_abbreviate_output);
name_rev(commit, xstrdup(path), 0, 0, deref);
}
return 0;