refs.c: add refs_shorten_unambiguous_ref()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 6 Apr 2019 11:34:25 +0000 (18:34 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Apr 2019 08:26:32 +0000 (17:26 +0900)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs.h
diff --git a/refs.c b/refs.c
index b869f32d8babf962ae89a39d9fc8de3ee62166e3..3dde824aab6eaba3440b851fdf1f9a4d817c763f 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
                               old_oid, flags, onerr);
 }
 
-char *shorten_unambiguous_ref(const char *refname, int strict)
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+                                  const char *refname, int strict)
 {
        int i;
        static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
                        strbuf_reset(&resolved_buf);
                        strbuf_addf(&resolved_buf, rule,
                                    short_name_len, short_name);
-                       if (ref_exists(resolved_buf.buf))
+                       if (refs_ref_exists(refs, resolved_buf.buf))
                                break;
                }
 
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
        return xstrdup(refname);
 }
 
+char *shorten_unambiguous_ref(const char *refname, int strict)
+{
+       return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
+                                           refname, strict);
+}
+
 static struct string_list *hide_refs;
 
 int parse_hide_refs_config(const char *var, const char *value, const char *section)
diff --git a/refs.h b/refs.h
index 308fa1f03b26c151f2df76a0c4f2f675e7bbee5a..56275702418168d0af4838a680f0ea27193fa604 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
 
 const char *prettify_refname(const char *refname);
 
+char *refs_shorten_unambiguous_ref(struct ref_store *refs,
+                                  const char *refname, int strict);
 char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/