Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
refs: move submodule slash stripping code to get_submodule_ref_store
author
Nguyễn Thái Ngọc Duy
<pclouds@gmail.com>
Wed, 23 Aug 2017 12:36:54 +0000
(19:36 +0700)
committer
Junio C Hamano
<gitster@pobox.com>
Thu, 24 Aug 2017 21:46:50 +0000
(14:46 -0700)
This is a better place that will benefit all submodule callers instead
of just resolve_gitlink_ref()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
2c616c1
)
diff --git
a/refs.c
b/refs.c
index 522c4ab74f505c1737f79311deea083ee33c3112..ea8e6b9f427eebb873b15f7bb47e917f60eaa4ea 100644
(file)
--- a/
refs.c
+++ b/
refs.c
@@
-1503,25
+1503,10
@@
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
int resolve_gitlink_ref(const char *submodule, const char *refname,
unsigned char *sha1)
{
int resolve_gitlink_ref(const char *submodule, const char *refname,
unsigned char *sha1)
{
- size_t len = strlen(submodule);
struct ref_store *refs;
int flags;
struct ref_store *refs;
int flags;
- while (len && is_dir_sep(submodule[len - 1]))
- len--;
-
- if (!len)
- return -1;
-
- if (submodule[len]) {
- /* We need to strip off one or more trailing slashes */
- char *stripped = xmemdupz(submodule, len);
-
- refs = get_submodule_ref_store(stripped);
- free(stripped);
- } else {
- refs = get_submodule_ref_store(submodule);
- }
+ refs = get_submodule_ref_store(submodule);
if (!refs)
return -1;
if (!refs)
return -1;
@@
-1636,6
+1621,16
@@
struct ref_store *get_submodule_ref_store(const char *submodule)
{
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
{
struct strbuf submodule_sb = STRBUF_INIT;
struct ref_store *refs;
+ char *to_free = NULL;
+ size_t len;
+
+ if (submodule) {
+ len = strlen(submodule);
+ while (len && is_dir_sep(submodule[len - 1]))
+ len--;
+ if (!len)
+ return NULL;
+ }
if (!submodule || !*submodule) {
/*
if (!submodule || !*submodule) {
/*
@@
-1645,6
+1640,10
@@
struct ref_store *get_submodule_ref_store(const char *submodule)
return get_main_ref_store();
}
return get_main_ref_store();
}
+ if (submodule[len])
+ /* We need to strip off one or more trailing slashes */
+ submodule = to_free = xmemdupz(submodule, len);
+
refs = lookup_ref_store_map(&submodule_ref_stores, submodule);
if (refs)
goto done;
refs = lookup_ref_store_map(&submodule_ref_stores, submodule);
if (refs)
goto done;
@@
-1664,6
+1663,8
@@
struct ref_store *get_submodule_ref_store(const char *submodule)
done:
strbuf_release(&submodule_sb);
done:
strbuf_release(&submodule_sb);
+ free(to_free);
+
return refs;
}
return refs;
}