]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/name-rev.c
treewide: be explicit about dependence on gettext.h
[thirdparty/git.git] / builtin / name-rev.c
index 0ebf06fad5a68ce542eedae7c455d9fc1900b726..6977a5f580b83c1778f6f4d5cae61415256ca641 100644 (file)
@@ -1,5 +1,7 @@
 #include "builtin.h"
-#include "cache.h"
+#include "alloc.h"
+#include "gettext.h"
+#include "hex.h"
 #include "repository.h"
 #include "config.h"
 #include "commit.h"
@@ -265,17 +267,6 @@ 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 (skip_prefix(refname, "refs/heads/", &refname))
-               ; /* refname already advanced */
-       else
-               skip_prefix(refname, "refs/", &refname);
-       return refname;
-}
-
 struct name_ref_data {
        int tags_only;
        int name_only;
@@ -301,11 +292,19 @@ static void add_to_tip_table(const struct object_id *oid, const char *refname,
                             int shorten_unambiguous, struct commit *commit,
                             timestamp_t taggerdate, int from_tag, int deref)
 {
-       refname = name_ref_abbrev(refname, shorten_unambiguous);
+       char *short_refname = NULL;
+
+       if (shorten_unambiguous)
+               short_refname = shorten_unambiguous_ref(refname, 0);
+       else if (skip_prefix(refname, "refs/heads/", &refname))
+               ; /* refname already advanced */
+       else
+               skip_prefix(refname, "refs/", &refname);
 
        ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
        oidcpy(&tip_table.table[tip_table.nr].oid, oid);
-       tip_table.table[tip_table.nr].refname = xstrdup(refname);
+       tip_table.table[tip_table.nr].refname = short_refname ?
+               short_refname : xstrdup(refname);
        tip_table.table[tip_table.nr].commit = commit;
        tip_table.table[tip_table.nr].taggerdate = taggerdate;
        tip_table.table[tip_table.nr].from_tag = from_tag;