Skip to content

Commit

Permalink
Merge branch 'nd/files-backend-git-dir'
Browse files Browse the repository at this point in the history
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()
  ...
  • Loading branch information
gitster committed Apr 20, 2017
2 parents 52d77af + adac811 commit 5ab8f22
Show file tree
Hide file tree
Showing 13 changed files with 1,319 additions and 403 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ TEST_PROGRAMS_NEED_X += test-parse-options
TEST_PROGRAMS_NEED_X += test-path-utils
TEST_PROGRAMS_NEED_X += test-prio-queue
TEST_PROGRAMS_NEED_X += test-read-cache
TEST_PROGRAMS_NEED_X += test-ref-store
TEST_PROGRAMS_NEED_X += test-regex
TEST_PROGRAMS_NEED_X += test-revision-walking
TEST_PROGRAMS_NEED_X += test-run-command
Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
};
if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
usage_with_options(pack_refs_usage, opts);
return pack_refs(flags);
return refs_pack_refs(get_main_ref_store(), flags);
}
35 changes: 7 additions & 28 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,39 +471,19 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)
}

/* Returns 0 on success, negative on failure. */
#define SUBMODULE_PATH_ERR_NOT_CONFIGURED -1
static int do_submodule_path(struct strbuf *buf, const char *path,
const char *fmt, va_list args)
{
const char *git_dir;
struct strbuf git_submodule_common_dir = STRBUF_INIT;
struct strbuf git_submodule_dir = STRBUF_INIT;
const struct submodule *sub;
int err = 0;
int ret;

strbuf_addstr(buf, path);
strbuf_complete(buf, '/');
strbuf_addstr(buf, ".git");

git_dir = read_gitfile(buf->buf);
if (git_dir) {
strbuf_reset(buf);
strbuf_addstr(buf, git_dir);
}
if (!is_git_directory(buf->buf)) {
gitmodules_config();
sub = submodule_from_path(null_sha1, path);
if (!sub) {
err = SUBMODULE_PATH_ERR_NOT_CONFIGURED;
goto cleanup;
}
strbuf_reset(buf);
strbuf_git_path(buf, "%s/%s", "modules", sub->name);
}

strbuf_addch(buf, '/');
strbuf_addbuf(&git_submodule_dir, buf);
ret = submodule_to_gitdir(&git_submodule_dir, path);
if (ret)
goto cleanup;

strbuf_complete(&git_submodule_dir, '/');
strbuf_addbuf(buf, &git_submodule_dir);
strbuf_vaddf(buf, fmt, args);

if (get_common_dir_noenv(&git_submodule_common_dir, git_submodule_dir.buf))
Expand All @@ -514,8 +494,7 @@ static int do_submodule_path(struct strbuf *buf, const char *path,
cleanup:
strbuf_release(&git_submodule_dir);
strbuf_release(&git_submodule_common_dir);

return err;
return ret;
}

char *git_pathdup_submodule(const char *path, const char *fmt, ...)
Expand Down
Loading

0 comments on commit 5ab8f22

Please sign in to comment.