Merge branch 'bw/submodule-sans-cache-compat'

Code clean-up.

* bw/submodule-sans-cache-compat:
  submodule: convert get_next_submodule to not rely on the_index
  submodule: used correct index in is_staging_gitmodules_ok
  submodule: convert stage_updated_gitmodules to take a struct index_state
This commit is contained in:
Junio C Hamano 2017-12-27 11:16:28 -08:00
Родитель 237aa99cd2 e724197f23
Коммит 00c4d2b6bc
5 изменённых файлов: 31 добавлений и 23 удалений

Просмотреть файл

@ -3,6 +3,7 @@
*/
#include "cache.h"
#include "config.h"
#include "repository.h"
#include "refs.h"
#include "commit.h"
#include "builtin.h"
@ -1397,7 +1398,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
struct argv_array options = ARGV_ARRAY_INIT;
add_options_to_argv(&options);
result = fetch_populated_submodules(&options,
result = fetch_populated_submodules(the_repository,
&options,
submodule_prefix,
recurse_submodules,
recurse_submodules_default,

Просмотреть файл

@ -291,7 +291,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
}
if (gitmodules_modified)
stage_updated_gitmodules();
stage_updated_gitmodules(&the_index);
if (active_cache_changed &&
write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

Просмотреть файл

@ -382,7 +382,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
}
strbuf_release(&buf);
if (gitmodules_modified)
stage_updated_gitmodules();
stage_updated_gitmodules(&the_index);
}
if (active_cache_changed) {

Просмотреть файл

@ -1,3 +1,5 @@
#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "repository.h"
#include "config.h"
@ -55,14 +57,15 @@ int is_gitmodules_unmerged(const struct index_state *istate)
* future version when we learn to stage the changes we do ourselves without
* staging any previous modifications.
*/
int is_staging_gitmodules_ok(const struct index_state *istate)
int is_staging_gitmodules_ok(struct index_state *istate)
{
int pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE));
if ((pos >= 0) && (pos < istate->cache_nr)) {
struct stat st;
if (lstat(GITMODULES_FILE, &st) == 0 &&
ce_match_stat(istate->cache[pos], &st, CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
ie_match_stat(istate, istate->cache[pos], &st,
CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
return 0;
}
@ -143,9 +146,9 @@ int remove_path_from_gitmodules(const char *path)
return 0;
}
void stage_updated_gitmodules(void)
void stage_updated_gitmodules(struct index_state *istate)
{
if (add_file_to_cache(GITMODULES_FILE, 0))
if (add_file_to_index(istate, GITMODULES_FILE, 0))
die(_("staging updated .gitmodules failed"));
}
@ -1178,7 +1181,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
struct submodule_parallel_fetch {
int count;
struct argv_array args;
const char *work_tree;
struct repository *r;
const char *prefix;
int command_line_option;
int default_option;
@ -1199,7 +1202,7 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
int fetch_recurse = submodule->fetch_recurse;
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
if (!repo_config_get_string_const(the_repository, key, &value)) {
if (!repo_config_get_string_const(spf->r, key, &value)) {
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
}
free(key);
@ -1218,11 +1221,11 @@ static int get_next_submodule(struct child_process *cp,
int ret = 0;
struct submodule_parallel_fetch *spf = data;
for (; spf->count < active_nr; spf->count++) {
for (; spf->count < spf->r->index->cache_nr; spf->count++) {
struct strbuf submodule_path = STRBUF_INIT;
struct strbuf submodule_git_dir = STRBUF_INIT;
struct strbuf submodule_prefix = STRBUF_INIT;
const struct cache_entry *ce = active_cache[spf->count];
const struct cache_entry *ce = spf->r->index->cache[spf->count];
const char *git_dir, *default_argv;
const struct submodule *submodule;
struct submodule default_submodule = SUBMODULE_INIT;
@ -1230,7 +1233,7 @@ static int get_next_submodule(struct child_process *cp,
if (!S_ISGITLINK(ce->ce_mode))
continue;
submodule = submodule_from_path(&null_oid, ce->name);
submodule = submodule_from_cache(spf->r, &null_oid, ce->name);
if (!submodule) {
const char *name = default_name_or_path(ce->name);
if (name) {
@ -1256,7 +1259,7 @@ static int get_next_submodule(struct child_process *cp,
continue;
}
strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
strbuf_repo_worktree_path(&submodule_path, spf->r, "%s", ce->name);
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, ce->name);
git_dir = read_gitfile(submodule_git_dir.buf);
@ -1309,7 +1312,8 @@ static int fetch_finish(int retvalue, struct strbuf *err,
return 0;
}
int fetch_populated_submodules(const struct argv_array *options,
int fetch_populated_submodules(struct repository *r,
const struct argv_array *options,
const char *prefix, int command_line_option,
int default_option,
int quiet, int max_parallel_jobs)
@ -1317,16 +1321,16 @@ int fetch_populated_submodules(const struct argv_array *options,
int i;
struct submodule_parallel_fetch spf = SPF_INIT;
spf.work_tree = get_git_work_tree();
spf.r = r;
spf.command_line_option = command_line_option;
spf.default_option = default_option;
spf.quiet = quiet;
spf.prefix = prefix;
if (!spf.work_tree)
if (!r->worktree)
goto out;
if (read_cache() < 0)
if (repo_read_index(r) < 0)
die("index file corrupt");
argv_array_push(&spf.args, "fetch");

Просмотреть файл

@ -34,10 +34,10 @@ struct submodule_update_strategy {
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
extern int is_gitmodules_unmerged(const struct index_state *istate);
extern int is_staging_gitmodules_ok(const struct index_state *istate);
extern int is_staging_gitmodules_ok(struct index_state *istate);
extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);
extern int remove_path_from_gitmodules(const char *path);
extern void stage_updated_gitmodules(void);
extern void stage_updated_gitmodules(struct index_state *istate);
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
const char *path);
extern int git_default_submodule_config(const char *var, const char *value, void *cb);
@ -76,10 +76,12 @@ extern int should_update_submodules(void);
*/
extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
extern void check_for_new_submodule_commits(struct object_id *oid);
extern int fetch_populated_submodules(const struct argv_array *options,
const char *prefix, int command_line_option,
int default_option,
int quiet, int max_parallel_jobs);
extern int fetch_populated_submodules(struct repository *r,
const struct argv_array *options,
const char *prefix,
int command_line_option,
int default_option,
int quiet, int max_parallel_jobs);
extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
extern int submodule_uses_gitfile(const char *path);