+#define NO_THE_INDEX_COMPATIBILITY_MACROS
+
#include "cache.h"
#include "repository.h"
#include "config.h"
* 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;
}
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"));
}
struct object_id *one, struct object_id *two,
unsigned dirty_submodule)
{
- const struct object_id *old = &empty_tree_oid, *new = &empty_tree_oid;
+ const struct object_id *old = the_hash_algo->empty_tree, *new = the_hash_algo->empty_tree;
struct commit *left = NULL, *right = NULL;
struct commit_list *merge_bases = NULL;
struct child_process cp = CHILD_PROCESS_INIT;
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;
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);
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;
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) {
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);
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)
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");
else
argv_array_push(&cp.args, "-m");
- argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+ if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
+ argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+
argv_array_push(&cp.args, new ? new : EMPTY_TREE_SHA1_HEX);
if (run_command(&cp)) {
cp.dir = path;
prepare_submodule_repo_env(&cp.env_array);
- argv_array_pushl(&cp.args, "update-ref", "HEAD", new, NULL);
+ argv_array_pushl(&cp.args, "update-ref", "HEAD",
+ "--no-deref", new, NULL);
if (run_command(&cp)) {
ret = -1;