This code is going to be expanded a bit soon. Keep it out for
better readability later.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com>
---
 refs.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/refs.c b/refs.c
index 2cacd934e..8ef7a52ba 100644
--- a/refs.c
+++ b/refs.c
@@ -1445,6 +1445,18 @@ static struct ref_store *lookup_ref_store(const char 
*submodule)
        return entry ? entry->refs : NULL;
 }
 
+static struct ref_store *init_submodule_ref_store(const char *submodule)
+{
+       struct strbuf submodule_sb = STRBUF_INIT;
+       struct ref_store *refs = NULL;
+
+       strbuf_addstr(&submodule_sb, submodule);
+       if (is_nonbare_repository_dir(&submodule_sb))
+               refs = ref_store_init(submodule);
+       strbuf_release(&submodule_sb);
+       return refs;
+}
+
 struct ref_store *get_ref_store(const char *submodule)
 {
        struct ref_store *refs;
@@ -1457,14 +1469,8 @@ struct ref_store *get_ref_store(const char *submodule)
        } else {
                refs = lookup_ref_store(submodule);
 
-               if (!refs) {
-                       struct strbuf submodule_sb = STRBUF_INIT;
-
-                       strbuf_addstr(&submodule_sb, submodule);
-                       if (is_nonbare_repository_dir(&submodule_sb))
-                               refs = ref_store_init(submodule);
-                       strbuf_release(&submodule_sb);
-               }
+               if (!refs)
+                       refs = init_submodule_ref_store(submodule);
        }
 
        return refs;
-- 
2.11.0.157.gd943d85

Reply via email to