Skip to content

Commit 5ab8f22

Browse files
committed
Merge branch 'nd/files-backend-git-dir'
The "submodule" specific field in the ref_store structure is replaced with a more generic "gitdir" that can later be used also when dealing with ref_store that represents the set of refs visible from the other worktrees. * nd/files-backend-git-dir: (28 commits) refs.h: add a note about sorting order of for_each_ref_* t1406: new tests for submodule ref store t1405: some basic tests on main ref store t/helper: add test-ref-store to test ref-store functions refs: delete pack_refs() in favor of refs_pack_refs() files-backend: avoid ref api targeting main ref store refs: new transaction related ref-store api refs: add new ref-store api refs: rename get_ref_store() to get_submodule_ref_store() and make it public files-backend: replace submodule_allowed check in files_downcast() refs: move submodule code out of files-backend.c path.c: move some code out of strbuf_git_path_submodule() refs.c: make get_main_ref_store() public and use it refs.c: kill register_ref_store(), add register_submodule_ref_store() refs.c: flatten get_ref_store() a bit refs: rename lookup_ref_store() to lookup_submodule_ref_store() refs.c: introduce get_main_ref_store() files-backend: remove the use of git_path() files-backend: add and use files_ref_path() files-backend: add and use files_reflog_path() ...
2 parents 52d77af + adac811 commit 5ab8f22

File tree

13 files changed

+1319
-403
lines changed

13 files changed

+1319
-403
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ TEST_PROGRAMS_NEED_X += test-parse-options
630630
TEST_PROGRAMS_NEED_X += test-path-utils
631631
TEST_PROGRAMS_NEED_X += test-prio-queue
632632
TEST_PROGRAMS_NEED_X += test-read-cache
633+
TEST_PROGRAMS_NEED_X += test-ref-store
633634
TEST_PROGRAMS_NEED_X += test-regex
634635
TEST_PROGRAMS_NEED_X += test-revision-walking
635636
TEST_PROGRAMS_NEED_X += test-run-command

builtin/pack-refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
1717
};
1818
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
1919
usage_with_options(pack_refs_usage, opts);
20-
return pack_refs(flags);
20+
return refs_pack_refs(get_main_ref_store(), flags);
2121
}

path.c

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -471,39 +471,19 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
471471
}
472472

473473
/* Returns 0 on success, negative on failure. */
474-
#define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1
475474
static int do_submodule_path(struct strbuf *buf, const char *path,
476475
const char *fmt, va_list args)
477476
{
478-
const char *git_dir;
479477
struct strbuf git_submodule_common_dir = STRBUF_INIT;
480478
struct strbuf git_submodule_dir = STRBUF_INIT;
481-
const struct submodule *sub;
482-
int err = 0;
479+
int ret;
483480

484-
strbuf_addstr(buf, path);
485-
strbuf_complete(buf, '/');
486-
strbuf_addstr(buf, ".git");
487-
488-
git_dir = read_gitfile(buf->buf);
489-
if (git_dir) {
490-
strbuf_reset(buf);
491-
strbuf_addstr(buf, git_dir);
492-
}
493-
if (!is_git_directory(buf->buf)) {
494-
gitmodules_config();
495-
sub = submodule_from_path(null_sha1, path);
496-
if (!sub) {
497-
err = SUBMODULE_PATH_ERR_NOT_CONFIGURED;
498-
goto cleanup;
499-
}
500-
strbuf_reset(buf);
501-
strbuf_git_path(buf, "%s/%s", "modules", sub->name);
502-
}
503-
504-
strbuf_addch(buf, '/');
505-
strbuf_addbuf(&git_submodule_dir, buf);
481+
ret = submodule_to_gitdir(&git_submodule_dir, path);
482+
if (ret)
483+
goto cleanup;
506484

485+
strbuf_complete(&git_submodule_dir, '/');
486+
strbuf_addbuf(buf, &git_submodule_dir);
507487
strbuf_vaddf(buf, fmt, args);
508488

509489
if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf))
@@ -514,8 +494,7 @@ static int do_submodule_path(struct strbuf *buf, const char *path,
514494
cleanup:
515495
strbuf_release(&git_submodule_dir);
516496
strbuf_release(&git_submodule_common_dir);
517-
518-
return err;
497+
return ret;
519498
}
520499

521500
char *git_pathdup_submodule(const char *path, const char *fmt, ...)

0 commit comments

Comments
 (0)