refs.c: add refs_shorten_unambiguous_ref()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 6, 2019 at 18:34 UTC 546edf37ae427cf5fdb8c00d1820df73cd16eed6
2 files changed +11 -2
refs.c
+9 -2
@@ -1169,7 +1169,8 @@ int update_ref(const char *msg, const char *refname,
1169 old_oid, flags, onerr);
1170 }
1171
1172 -char *shorten_unambiguous_ref(const char *refname, int strict)
1172 +char *refs_shorten_unambiguous_ref(struct ref_store *refs,
1173 + const char *refname, int strict)
1174 {
1175 int i;
1176 static char **scanf_fmts;
@@ -1247,7 +1248,7 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
1248 strbuf_reset(&resolved_buf);
1249 strbuf_addf(&resolved_buf, rule,
1250 short_name_len, short_name);
1250 - if (ref_exists(resolved_buf.buf))
1251 + if (refs_ref_exists(refs, resolved_buf.buf))
1252 break;
1253 }
1254
@@ -1266,6 +1267,12 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
1267 return xstrdup(refname);
1268 }
1269
1270 +char *shorten_unambiguous_ref(const char *refname, int strict)
1271 +{
1272 + return refs_shorten_unambiguous_ref(get_main_ref_store(the_repository),
1273 + refname, strict);
1274 +}
1275 +
1276 static struct string_list *hide_refs;
1277
1278 int parse_hide_refs_config(const char *var, const char *value, const char *section)
refs.h
+2
@@ -462,6 +462,8 @@ int check_refname_format(const char *refname, int flags);
462
463 const char *prettify_refname(const char *refname);
464
465 +char *refs_shorten_unambiguous_ref(struct ref_store *refs,
466 + const char *refname, int strict);
467 char *shorten_unambiguous_ref(const char *refname, int strict);
468
469 /** rename ref, return 0 on success **/