Merge branch 'bw/repo-object'

Introduce a "repository" object to eventually make it easier to
work in multiple repositories (the primary focus is to work with
the superproject and its submodules) in a single process.

* bw/repo-object:
  ls-files: use repository object
  repository: enable initialization of submodules
  submodule: convert is_submodule_initialized to work on a repository
  submodule: add repo_read_gitmodules
  submodule-config: store the_submodule_cache in the_repository
  repository: add index_state to struct repo
  config: read config from a repository object
  path: add repo_worktree_path and strbuf_repo_worktree_path
  path: add repo_git_path and strbuf_repo_git_path
  path: worktree_git_path() should not use file relocation
  path: convert do_git_path to take a 'struct repository'
  path: convert strbuf_git_common_path to take a 'struct repository'
  path: always pass in commondir to update_common_dir
  path: create path.h
  environment: store worktree in the_repository
  environment: place key repository state in the_repository
  repository: introduce the repository object
  environment: remove namespace_len variable
  setup: add comment indicating a hack
  setup: don't perform lazy initialization of repository state
This commit is contained in:
Junio C Hamano
2017-07-05 13:32:55 -07:00
20 changed files with 974 additions and 375 deletions

View File

@ -1,4 +1,5 @@
#include "cache.h"
#include "repository.h"
#include "config.h"
#include "submodule-config.h"
#include "submodule.h"
@ -255,6 +256,20 @@ void gitmodules_config(void)
}
}
static int gitmodules_cb(const char *var, const char *value, void *data)
{
struct repository *repo = data;
return submodule_config_option(repo, var, value);
}
void repo_read_gitmodules(struct repository *repo)
{
char *gitmodules_path = repo_worktree_path(repo, ".gitmodules");
git_config_from_file(gitmodules_cb, gitmodules_path, repo);
free(gitmodules_path);
}
void gitmodules_config_sha1(const unsigned char *commit_sha1)
{
struct strbuf rev = STRBUF_INIT;
@ -268,21 +283,17 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
}
/*
* NEEDSWORK: With the addition of different configuration options to determine
* if a submodule is of interests, the validity of this function's name comes
* into question. Once the dust has settled and more concrete terminology is
* decided upon, come up with a more proper name for this function. One
* potential candidate could be 'is_submodule_active()'.
*
* Determine if a submodule has been initialized at a given 'path'
*/
int is_submodule_initialized(const char *path)
int is_submodule_active(struct repository *repo, const char *path)
{
int ret = 0;
char *key = NULL;
char *value = NULL;
const struct string_list *sl;
const struct submodule *module = submodule_from_path(null_sha1, path);
const struct submodule *module;
module = submodule_from_cache(repo, null_sha1, path);
/* early return if there isn't a path->module mapping */
if (!module)
@ -290,14 +301,14 @@ int is_submodule_initialized(const char *path)
/* submodule.<name>.active is set */
key = xstrfmt("submodule.%s.active", module->name);
if (!git_config_get_bool(key, &ret)) {
if (!repo_config_get_bool(repo, key, &ret)) {
free(key);
return ret;
}
free(key);
/* submodule.active is set */
sl = git_config_get_value_multi("submodule.active");
sl = repo_config_get_value_multi(repo, "submodule.active");
if (sl) {
struct pathspec ps;
struct argv_array args = ARGV_ARRAY_INIT;
@ -317,7 +328,7 @@ int is_submodule_initialized(const char *path)
/* fallback to checking if the URL is set */
key = xstrfmt("submodule.%s.url", module->name);
ret = !git_config_get_string(key, &value);
ret = !repo_config_get_string(repo, key, &value);
free(value);
free(key);
@ -1517,7 +1528,7 @@ int submodule_move_head(const char *path,
const struct submodule *sub;
int *error_code_ptr, error_code;
if (!is_submodule_initialized(path))
if (!is_submodule_active(the_repository, path))
return 0;
if (flags & SUBMODULE_MOVE_HEAD_FORCE)