v7 is mostly about style changes except the one bug in
test-ref-store.c, missing setup_git_directory().

There's one new patch, 03/28, which maps to the "if (!refs)" deletion
in the interdiff.

The one comment from v6 I haven't addressed in v7 is whether to delete
REF_STORE_READ. But if it is deleted, I think I'm doing it in
nd/worktree-kill-parse-ref, which is partly about cleanup refs code
anyway, to avoid another re-roll in this series.

diff --git a/refs.c b/refs.c
index 77a39f8b17..ec1f563824 100644
--- a/refs.c
+++ b/refs.c
@@ -1523,18 +1523,15 @@ static struct ref_store *ref_store_init(const char 
*gitdir,
 
 struct ref_store *get_main_ref_store(void)
 {
-       struct ref_store *refs;
-
        if (main_ref_store)
                return main_ref_store;
 
-       refs = ref_store_init(get_git_dir(),
-                             (REF_STORE_READ |
-                              REF_STORE_WRITE |
-                              REF_STORE_ODB |
-                              REF_STORE_MAIN));
-       main_ref_store = refs;
-       return refs;
+       main_ref_store = ref_store_init(get_git_dir(),
+                                       (REF_STORE_READ |
+                                        REF_STORE_WRITE |
+                                        REF_STORE_ODB |
+                                        REF_STORE_MAIN));
+       return main_ref_store;
 }
 
 /*
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4242486118..a5b405436f 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1195,9 +1195,9 @@ static void files_reflog_path(struct files_ref_store 
*refs,
        }
 }
 
-static void files_refname_path(struct files_ref_store *refs,
-                              struct strbuf *sb,
-                              const char *refname)
+static void files_ref_path(struct files_ref_store *refs,
+                          struct strbuf *sb,
+                          const char *refname)
 {
        switch (ref_type(refname)) {
        case REF_TYPE_PER_WORKTREE:
@@ -1283,7 +1283,7 @@ static void read_loose_refs(const char *dirname, struct 
ref_dir *dir)
        struct strbuf path = STRBUF_INIT;
        size_t path_baselen;
 
-       files_refname_path(refs, &path, dirname);
+       files_ref_path(refs, &path, dirname);
        path_baselen = path.len;
 
        d = opendir(path.buf);
@@ -1420,7 +1420,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
        *type = 0;
        strbuf_reset(&sb_path);
 
-       files_refname_path(refs, &sb_path, refname);
+       files_ref_path(refs, &sb_path, refname);
 
        path = sb_path.buf;
 
@@ -1608,7 +1608,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
        *lock_p = lock = xcalloc(1, sizeof(*lock));
 
        lock->ref_name = xstrdup(refname);
-       files_refname_path(refs, &ref_file, refname);
+       files_ref_path(refs, &ref_file, refname);
 
 retry:
        switch (safe_create_leading_directories(ref_file.buf)) {
@@ -1949,8 +1949,6 @@ static struct ref_iterator *files_ref_iterator_begin(
        refs = files_downcast(ref_store,
                              REF_STORE_READ | (ref_paranoia ? 0 : 
REF_STORE_ODB),
                              "ref_iterator_begin");
-       if (!refs)
-               return empty_ref_iterator_begin();
 
        iter = xcalloc(1, sizeof(*iter));
        ref_iterator = &iter->base;
@@ -2086,7 +2084,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct 
files_ref_store *refs,
        if (flags & REF_DELETING)
                resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
 
-       files_refname_path(refs, &ref_file, refname);
+       files_ref_path(refs, &ref_file, refname);
        resolved = !!refs_resolve_ref_unsafe(&refs->base,
                                             refname, resolve_flags,
                                             lock->old_oid.hash, type);
@@ -2387,7 +2385,7 @@ static void try_remove_empty_parents(struct 
files_ref_store *refs,
                strbuf_setlen(&buf, q - buf.buf);
 
                strbuf_reset(&sb);
-               files_refname_path(refs, &sb, buf.buf);
+               files_ref_path(refs, &sb, buf.buf);
                if ((flags & REMOVE_EMPTY_PARENTS_REF) && rmdir(sb.buf))
                        flags &= ~REMOVE_EMPTY_PARENTS_REF;
 
@@ -2709,7 +2707,7 @@ static int files_rename_ref(struct ref_store *ref_store,
                        struct strbuf path = STRBUF_INIT;
                        int result;
 
-                       files_refname_path(refs, &path, newrefname);
+                       files_ref_path(refs, &path, newrefname);
                        result = remove_empty_directories(&path);
                        strbuf_release(&path);
 
@@ -2935,10 +2933,10 @@ static int log_ref_write_fd(int fd, const unsigned char 
*old_sha1,
        return 0;
 }
 
-int files_log_ref_write(struct files_ref_store *refs,
-                       const char *refname, const unsigned char *old_sha1,
-                       const unsigned char *new_sha1, const char *msg,
-                       int flags, struct strbuf *err)
+static int files_log_ref_write(struct files_ref_store *refs,
+                              const char *refname, const unsigned char 
*old_sha1,
+                              const unsigned char *new_sha1, const char *msg,
+                              int flags, struct strbuf *err)
 {
        int logfd, result;
 
@@ -3957,7 +3955,7 @@ static int files_transaction_commit(struct ref_store 
*ref_store,
                            update->type & REF_ISSYMREF) {
                                /* It is a loose reference. */
                                strbuf_reset(&sb);
-                               files_refname_path(refs, &sb, lock->ref_name);
+                               files_ref_path(refs, &sb, lock->ref_name);
                                if (unlink_or_msg(sb.buf, err)) {
                                        ret = TRANSACTION_GENERIC_ERROR;
                                        goto cleanup;
@@ -4266,11 +4264,11 @@ static int files_init_db(struct ref_store *ref_store, 
struct strbuf *err)
        /*
         * Create .git/refs/{heads,tags}
         */
-       files_refname_path(refs, &sb, "refs/heads");
+       files_ref_path(refs, &sb, "refs/heads");
        safe_create_dir(sb.buf, 1);
 
        strbuf_reset(&sb);
-       files_refname_path(refs, &sb, "refs/tags");
+       files_ref_path(refs, &sb, "refs/tags");
        safe_create_dir(sb.buf, 1);
 
        strbuf_release(&sb);
diff --git a/submodule.c b/submodule.c
index 3c445f274e..a31f68812c 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1597,11 +1597,6 @@ const char *get_superproject_working_tree(void)
        return ret;
 }
 
-/*
- * Given a submodule path (as in the index), return the repository
- * path of that submodule in 'buf'. Return -1 on error or when the
- * submodule is not initialized.
- */
 int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
 {
        const struct submodule *sub;
diff --git a/submodule.h b/submodule.h
index bddbba7f32..fce2fb64d2 100644
--- a/submodule.h
+++ b/submodule.h
@@ -81,6 +81,11 @@ extern int push_unpushed_submodules(struct sha1_array 
*commits,
                                    int dry_run);
 extern void connect_work_tree_and_git_dir(const char *work_tree, const char 
*git_dir);
 extern int parallel_submodules(void);
+/*
+ * Given a submodule path (as in the index), return the repository
+ * path of that submodule in 'buf'. Return -1 on error or when the
+ * submodule is not initialized.
+ */
 int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
 
 /*
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 57849ee59a..2d84c45ffe 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -261,6 +261,8 @@ int cmd_main(int argc, const char **argv)
        const char *func;
        struct command *cmd;
 
+       setup_git_directory();
+
        argv = get_store(argv + 1, &refs);
 
        func = *argv++;

-- 
2.11.0.157.gd943d85

Reply via email to