Retire NO_THE_INDEX_COMPATIBILITY_MACROS
cover Retire NO_THE_INDEX_COMPATIBILITY_MACROS
This is the follow up to [1], but actually completed now.
The reasoning why this series is a good idea is in the commit message of the last patch, quoted here:
The NO_THE_INDEX_COMPATIBILITY_MACROS pre processor setting was introduced in 4aab5b46f4 (Make read-cache.c "the_index" free., 2007-04-01), stating:
This makes all low-level functions defined in read-cache.c to take an explicit index_state structure as their first parameter, to specify which index to work on.
The reasoning is very vague, maybe indicating that having the index specified to work on is easier to for the new reader to understand what is going on.
All preceding patches worked on retiring functions that do not take an explicit index as to where to perform its work. Spelling out the reasons why we want to specify the index at each call:
1) Ease of understanding:
The recent patches dropped a lot of macros that may confuse new people diving into the code base.
2a) Spelling out global state explicitly:
Anything you do in submodule land today needs to spawn new processes in the submodule. This is cumbersome and not performant. So we may want to have an abstraction of a repo, i.e. all repository state in one struct. That way we can open a submodule in-process and perform the required actions without spawning a process. The road to this future is a long road, and we have to start somewhere. Exposing the global state seems like a good starter point.
2b) Spelling out global state explicitly (II): (Jeff Hostetler wrote)
In addition to (eventually) allowing multiple repos be open at the same time for submodules, it would also help with various multi-threading efforts. For example, we have loops that do a
"for (k = 0, k < active_nr; k++) {...}" There is no visual clue in that code that it references "the_index" and therefore should be subject to the same locking. Granted, this is a trivial example, but goes to the argument that the code has lots of subtle global variables and macros that make it difficult to reason about the code.
This step would help un-hide this.
Review as well as critique if this is the right approach to an endgame with less globals splattered throughout the codebase is welcome.
Thanks,
Stefan
[1] https://public-inbox.org/git/[email protected]/
Stefan Beller (24):
cache.h: drop read_cache()
cache.h: drop active_* macros
cache.h: drop read_cache_from
cache.h: drop read_cache_preload(pathspec)
cache.h: drop read_cache_unmerged()
unpack-trees.c: rename parameter 'the_index'
cache.h: drop read_blob_data_from_cache
cache.h: drop unmerge_cache[_entry_at]
cache.h: drop resolve_undo_clear
cache.h: drop cache_name_is_other
cache.h: drop cache_file_exists
cache.h: drop cache_dir_exists
cache.h: drop is_cache_unborn(), discard_cache(), unmerged_cache() cache.h: drop cache_name_pos
cache.h: drop add_cache_entry
cache.h: drop rename_cache_entry_at
cache.h: drop remove_file_from_cache
cache.h: drop add_to_cache
cache.h: drop add_file_to_cache
cache.h: drop chmod_cache_entry
cache.h: drop refresh_cache
cache.h: drop ce_modified
cache.h: drop ce_match_stat
cache.h: retire NO_THE_INDEX_COMPATIBILITY_MACROS
apply.c | 32 +++++++------ attr.c | 1 - builtin/add.c | 12 ++--- builtin/am.c | 26 +++++------ builtin/blame.c | 19 ++++---- builtin/check-attr.c | 2 +- builtin/check-ignore.c | 4 +- builtin/checkout-index.c | 12 ++--- builtin/checkout.c | 66 +++++++++++++------------- builtin/clean.c | 4 +- builtin/commit.c | 52 ++++++++++----------- builtin/describe.c | 2 +- builtin/diff-files.c | 4 +- builtin/diff-index.c | 6 +-- builtin/diff.c | 19 ++++---- builtin/fsck.c | 14 +++--- builtin/grep.c | 10 ++-- builtin/ls-files.c | 49 +++++++++---------- builtin/merge-index.c | 14 +++--- builtin/merge.c | 24 +++++----- builtin/mv.c | 22 ++++----- builtin/pull.c | 4 +- builtin/read-tree.c | 8 ++-- builtin/reset.c | 11 +++-- builtin/rev-parse.c | 2 +- builtin/rm.c | 26 +++++------ builtin/submodule--helper.c | 10 ++-- builtin/update-index.c | 91 +++++++++++++++++++----------------- cache.h | 35 -------------- check-racy.c | 10 ++-- convert.c | 4 +- diff-lib.c | 8 ++-- diff.c | 14 +++--- dir.c | 41 ++++++++-------- entry.c | 3 +- merge-recursive.c | 65 +++++++++++++------------- merge.c | 8 ++-- name-hash.c | 1 - pathspec.c | 16 +++---- read-cache.c | 5 +- rerere.c | 38 +++++++-------- revision.c | 22 ++++----- sequencer.c | 29 ++++++------ sha1_name.c | 22 ++++----- submodule.c | 20 ++++---- t/helper/test-dump-cache-tree.c | 4 +- t/helper/test-dump-untracked-cache.c | 2 +- t/helper/test-lazy-init-name-hash.c | 20 ++++---- t/helper/test-read-cache.c | 4 +- t/helper/test-scrap-cache-tree.c | 4 +- t/t2107-update-index-basic.sh | 2 +- tree.c | 10 ++-- unpack-trees.c | 9 ++-- wt-status.c | 24 +++++----- 54 files changed, 471 insertions(+), 495 deletions(-)
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 1/24 cache.h: drop read_cache()
This patch is produced via coccinelle using this semantic patch:
@@ @@
-read_cache()
+read_index(&the_index)
Additional manual editing:
* drop define in cache.h
* a comment in builtin/check-ignore.c and read-cache.c were converted
* builtin/diff.c: fix error message referencing the function.
--- apply.c | 2 +- builtin/add.c | 4 ++-- builtin/am.c | 2 +- builtin/blame.c | 4 ++-- builtin/check-attr.c | 2 +- builtin/check-ignore.c | 4 ++-- builtin/checkout-index.c | 2 +- builtin/clean.c | 2 +- builtin/commit.c | 4 ++-- builtin/diff-index.c | 2 +- builtin/diff.c | 6 +++--- builtin/fsck.c | 2 +- builtin/grep.c | 2 +- builtin/ls-files.c | 2 +- builtin/merge-index.c | 2 +- builtin/mv.c | 2 +- builtin/reset.c | 2 +- builtin/rev-parse.c | 2 +- builtin/rm.c | 2 +- builtin/submodule--helper.c | 2 +- builtin/update-index.c | 2 +- cache.h | 1 - check-racy.c | 2 +- diff.c | 2 +- merge-recursive.c | 2 +- merge.c | 2 +- read-cache.c | 2 +- rerere.c | 6 +++--- revision.c | 4 ++-- sequencer.c | 6 +++--- sha1_name.c | 2 +- submodule.c | 4 ++-- t/helper/test-dump-cache-tree.c | 2 +- t/helper/test-dump-untracked-cache.c | 2 +- t/helper/test-lazy-init-name-hash.c | 10 +++++----- t/helper/test-read-cache.c | 2 +- t/helper/test-scrap-cache-tree.c | 2 +- 37 files changed, 52 insertions(+), 53 deletions(-)
apply.c +1 -1
@@ -3987,7 +3987,7 @@ static int read_apply_cache(struct apply_state *state)if (state->index_file)return read_cache_from (state->index_file);else -return read_cache (); +return read_index (&the_index); }/* This function tries to read the object name from the current index */
builtin/add.c +2 -2
@@ -205,7 +205,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)git_config (git_diff_basic_config,NULL );/* no "diff" UI options */ -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("Could not read the index" ));init_revisions (&rev, prefix);
@@ -376,7 +376,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)return 0 ; } -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" ));/*
builtin/am.c +1 -1
@@ -1633,7 +1633,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pasay (state, stdout,_ ("Falling back to patching base and 3-way merge..." ));discard_cache (); -read_cache (); +read_index (&the_index);/* * This is not so wrong. Depending on which base we picked, orig_tree
builtin/blame.c +2 -2
@@ -2313,7 +2313,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,unsigned mode;struct strbuf msg =STRBUF_INIT ; -read_cache (); +read_index (&the_index);time (&now); commit =alloc_commit_node (); commit->object.parsed =1 ;
@@ -2395,7 +2395,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,* want to run "diff-index --cached". */ discard_cache (); -read_cache (); +read_index (&the_index); len =strlen (path);if (!mode) {
builtin/check-attr.c +1 -1
@@ -114,7 +114,7 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, check_attr_options, check_attr_usage,PARSE_OPT_KEEP_DASHDASH ); -if (read_cache () <0 ) { +if (read_index (&the_index) <0 ) {die ("invalid cache" ); }
builtin/check-ignore.c +2 -2
@@ -167,8 +167,8 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)if (show_non_matching && !verbose)die (_ ("--non-matching is only valid with --verbose" )); -/* read_cache() is only necessary so we can watch out for submodules. */ -if (!no_index &&read_cache () <0 ) +/* read_index() is only necessary so we can watch out for submodules. */ +if (!no_index &&read_index (&the_index) <0 )die (_ ("index file corrupt" ));memset (&dir,0 ,sizeof (dir));
builtin/checkout-index.c +1 -1
@@ -185,7 +185,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)git_config (git_default_config,NULL ); prefix_length = prefix ?strlen (prefix) :0 ; -if (read_cache () <0 ) { +if (read_index (&the_index) <0 ) {die ("invalid cache" ); }
builtin/clean.c +1 -1
@@ -916,7 +916,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) dir.flags |=DIR_SHOW_OTHER_DIRECTORIES ; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" ));if (!ignored)
builtin/commit.c +2 -2
@@ -465,7 +465,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixexit (1 );discard_cache (); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("cannot read the index" ));hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR );
@@ -888,7 +888,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,struct object_id oid;const char *parent ="HEAD" ; -if (!active_nr &&read_cache () <0 ) +if (!active_nr &&read_index (&the_index) <0 )die (_ ("Cannot read index" ));if (amend)
builtin/diff-index.c +1 -1
@@ -48,7 +48,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)perror ("read_cache_preload" );return -1 ; } - }else if (read_cache () <0 ) { + }else if (read_index (&the_index) <0 ) {perror ("read_cache" );return -1 ; }
builtin/diff.c +3 -3
@@ -148,8 +148,8 @@ static int builtin_diff_index(struct rev_info *revs,perror ("read_cache_preload" );return -1 ; } - }else if (read_cache () <0 ) { -perror ("read_cache" ); + }else if (read_index (&the_index) <0 ) { +perror ("read_index" );return -1 ; }return run_diff_index (revs, cached);
@@ -210,7 +210,7 @@ static void refresh_index_quietly(void)if (fd <0 )return ;discard_cache (); -read_cache (); +read_index (&the_index);refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED );update_index_if_able (&the_index, lock_file); }
builtin/fsck.c +1 -1
@@ -772,7 +772,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (keep_cache_objects) { verify_index_checksum =1 ; -read_cache (); +read_index (&the_index);for (i =0 ; i < active_nr; i++) {unsigned int mode;struct blob *blob;
builtin/grep.c +1 -1
@@ -676,7 +676,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,strbuf_addstr (&name, super_prefix); } -read_cache (); +read_index (&the_index);for (nr =0 ; nr < active_nr; nr++) {const struct cache_entry *ce = active_cache[nr];
builtin/ls-files.c +1 -1
@@ -578,7 +578,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) super_prefix =get_super_prefix ();git_config (git_default_config,NULL ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("index file corrupt" ); argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
builtin/merge-index.c +1 -1
@@ -77,7 +77,7 @@ int cmd_merge_index(int argc, const char **argv, const char *prefix)if (argc <3 )usage ("git merge-index [-o] [-q] <merge-program> (-a | [--] [<filename>...])" ); -read_cache (); +read_index (&the_index); i =1 ;if (!strcmp (argv[i],"-o" )) {
builtin/mv.c +1 -1
@@ -139,7 +139,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)usage_with_options (builtin_mv_usage, builtin_mv_options);hold_locked_index (&lock_file,LOCK_DIE_ON_ERROR ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); source =internal_prefix_pathspec (prefix, argv, argc,0 );
builtin/reset.c +1 -1
@@ -231,7 +231,7 @@ static void parse_args(struct pathspec *pathspec, } *rev_ret = rev; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); parse_pathspec(pathspec, 0,
builtin/rev-parse.c +1 -1
@@ -868,7 +868,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)continue ; }if (!strcmp (arg,"--shared-index-path" )) { -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("Could not read the index" ));if (the_index.split_index) {const unsigned char *sha1 = the_index.split_index->base_sha1;
builtin/rm.c +1 -1
@@ -267,7 +267,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)hold_locked_index (&lock_file,LOCK_DIE_ON_ERROR ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); parse_pathspec(&pathspec, 0,
builtin/submodule--helper.c +1 -1
@@ -240,7 +240,7 @@ static int module_list_compute(int argc, const char **argv,if (pathspec->nr) ps_matched =xcalloc (pathspec->nr,1 ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" ));for (i =0 ; i < active_nr; i++) {
builtin/update-index.c +1 -1
@@ -1021,7 +1021,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)if (newfd <0 ) lock_error = errno; - entries =read_cache (); + entries =read_index (&the_index);if (entries <0 )die ("cache corrupted" );
cache.h +0 -1
@@ -360,7 +360,6 @@ extern void free_name_hash(struct index_state *istate);#define active_cache_changed (the_index.cache_changed)#define active_cache_tree (the_index.cache_tree) -#define read_cache () read_index(&the_index)#define read_cache_from (path) read_index_from(&the_index, (path))#define read_cache_preload (pathspec) read_index_preload(&the_index, (pathspec))#define is_cache_unborn () is_index_unborn(&the_index)
check-racy.c +1 -1
@@ -6,7 +6,7 @@ int main(int ac, char **av)int dirty, clean, racy; dirty = clean = racy =0 ; -read_cache (); +read_index (&the_index);for (i =0 ; i < active_nr; i++) {struct cache_entry *ce = active_cache[i];struct stat st;
diff.c +1 -1
@@ -3497,7 +3497,7 @@ void diff_setup_done(struct diff_options *options)* when it fails, so we do not have to worry about * cleaning it up ourselves either. */ -read_cache (); +read_index (&the_index); }if (40 < options->abbrev) options->abbrev =40 ;/* full */
merge-recursive.c +1 -1
@@ -2075,7 +2075,7 @@ int merge_recursive(struct merge_options *o,discard_cache ();if (!o->call_depth) -read_cache (); +read_index (&the_index); o->ancestor ="merged common ancestors" ; clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree,
merge.c +1 -1
@@ -37,7 +37,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr,argv_array_clear (&args);discard_cache (); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("failed to read the cache" ));resolve_undo_clear ();
read-cache.c +1 -1
@@ -2506,7 +2506,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,* index_state, dropping any unmerged entries. Returns true if * the index is unmerged. Callers who want to refuse to work * from an unmerged state can call this and check its return value, -* instead of calling read_cache(). +* instead of calling read_index(). */ int read_index_unmerged (struct index_state *istate) {
rerere.c +3 -3
@@ -566,7 +566,7 @@ static int check_one_conflict(int i, int *type)static int find_conflict (struct string_list *conflict) {int i; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )return error ("Could not read index" );for (i =0 ; i < active_nr;) {
@@ -599,7 +599,7 @@ int rerere_remaining(struct string_list *merge_rr)int i;if (setup_rerere (merge_rr,RERERE_READONLY ))return 0 ; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )return error ("Could not read index" );for (i =0 ; i < active_nr;) {
@@ -1104,7 +1104,7 @@ int rerere_forget(struct pathspec *pathspec)struct string_list conflict =STRING_LIST_INIT_DUP ;struct string_list merge_rr =STRING_LIST_INIT_DUP ; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )return error ("Could not read index" ); fd =setup_rerere (&merge_rr,RERERE_NOAUTOUPDATE );
revision.c +2 -2
@@ -1267,7 +1267,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) {int i; -read_cache (); +read_index (&the_index);for (i =0 ; i < active_nr; i++) {struct cache_entry *ce = active_cache[i];struct blob *blob;
@@ -1408,7 +1408,7 @@ static void prepare_show_merge(struct rev_info *revs) head->object.flags |=SYMMETRIC_LEFT ;if (!active_nr) -read_cache (); +read_index (&the_index);for (i =0 ; i < active_nr; i++) {const struct cache_entry *ce = active_cache[i];if (!ce_stage (ce))
sequencer.c +3 -3
@@ -381,7 +381,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,struct strbuf sb =STRBUF_INIT ;struct strbuf err =STRBUF_INIT ; -read_cache (); +read_index (&the_index);if (checkout_fast_forward (from, to,1 ))return -1 ;/* the callee should have complained already */
@@ -437,7 +437,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR ); -read_cache (); +read_index (&the_index);init_merge_options (&o); o.ancestor = base ? base_label :"(empty tree)" ;
@@ -1844,7 +1844,7 @@ static int do_exec(const char *command_line) status =run_command_v_opt (child_argv,RUN_USING_SHELL );/* force re-reading of the cache */ -if (discard_cache () <0 ||read_cache () <0 ) +if (discard_cache () <0 ||read_index (&the_index) <0 )return error (_ ("could not read index" )); dirty =require_clean_work_tree ("rebase" ,NULL ,1 ,1 );
sha1_name.c +1 -1
@@ -1552,7 +1552,7 @@ static int get_sha1_with_context_1(const char *name,strlcpy (oc->path, cp,sizeof (oc->path));if (!active_cache) -read_cache (); +read_index (&the_index); pos =cache_name_pos (cp, namelen);if (pos <0 ) pos = -pos -1 ;
submodule.c +2 -2
@@ -177,7 +177,7 @@ void gitmodules_config(void)int pos;strbuf_addstr (&gitmodules_path, work_tree);strbuf_addstr (&gitmodules_path,"/.gitmodules" ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("index file corrupt" ); pos =cache_name_pos (".gitmodules" ,11 );if (pos <0 ) {/* .gitmodules not found or isn't merged */
@@ -1151,7 +1151,7 @@ int fetch_populated_submodules(const struct argv_array *options,if (!spf.work_tree) goto out; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("index file corrupt" );argv_array_push (&spf.args,"fetch" );
t/helper/test-dump-cache-tree.c +1 -1
@@ -59,7 +59,7 @@ int cmd_main(int ac, const char **av)struct index_state istate;struct cache_tree *another =cache_tree ();setup_git_directory (); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("unable to read index file" ); istate = the_index; istate.cache_tree = another;
t/helper/test-dump-untracked-cache.c +1 -1
@@ -47,7 +47,7 @@ int cmd_main(int ac, const char **av) ignore_untracked_cache_config =1 ;setup_git_directory (); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("unable to read index file" ); uc = the_index.untracked;if (!uc) {
t/helper/test-lazy-init-name-hash.c +5 -5
@@ -31,7 +31,7 @@ static void dump_run(void)struct dir_entry *dir;struct cache_entry *ce; -read_cache (); +read_index (&the_index);if (single) {test_lazy_init_name_hash (&the_index,0 ); }else {
@@ -69,7 +69,7 @@ static uint64_t time_runs(int try_threaded)for (i =0 ; i < count; i++) { t0 =getnanotime (); -read_cache (); +read_index (&the_index); t1 =getnanotime (); nr_threads_used =test_lazy_init_name_hash (&the_index, try_threaded); t2 =getnanotime ();
@@ -116,7 +116,7 @@ static void analyze_run(void)int i;int nr; -read_cache (); +read_index (&the_index); cache_nr_limit = the_index.cache_nr;discard_cache ();
@@ -131,7 +131,7 @@ static void analyze_run(void) nr = cache_nr_limit;for (i =0 ; i < count; i++) { -read_cache (); +read_index (&the_index); the_index.cache_nr = nr;/* cheap truncate of index */ t1s =getnanotime ();test_lazy_init_name_hash (&the_index,0 );
@@ -140,7 +140,7 @@ static void analyze_run(void) the_index.cache_nr = cache_nr_limit;discard_cache (); -read_cache (); +read_index (&the_index); the_index.cache_nr = nr;/* cheap truncate of index */ t1m =getnanotime (); nr_threads_used =test_lazy_init_name_hash (&the_index,1 );
t/helper/test-read-cache.c +1 -1
@@ -7,7 +7,7 @@ int cmd_main(int argc, const char **argv) cnt =strtol (argv[1 ],NULL ,0 );setup_git_directory ();for (i =0 ; i < cnt; i++) { -read_cache (); +read_index (&the_index);discard_cache (); }return 0 ;
t/helper/test-scrap-cache-tree.c +1 -1
@@ -9,7 +9,7 @@ int cmd_main(int ac, const char **av) {setup_git_directory ();hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR ); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die ("unable to read index file" ); active_cache_tree =NULL ;if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 3/24 cache.h: drop read_cache_from
In reply to Stefan Bellercoccinelle patch:
@@ expression E; @@
-read_cache_from(E)
+read_index_from(&the_index, E)
additionally drop the define from cache.h manually
--- apply.c | 2 +- builtin/am.c | 4 ++-- builtin/commit.c | 6 +++--- cache.h | 1 - 4 files changed, 6 insertions(+), 7 deletions(-)
apply.c +1 -1
@@ -3985,7 +3985,7 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)static int read_apply_cache (struct apply_state *state) {if (state->index_file) -return read_cache_from (state->index_file); +return read_index_from (&the_index, state->index_file);else return read_index (&the_index); }
builtin/am.c +2 -2
@@ -1557,7 +1557,7 @@ static int run_apply(const struct am_state *state, const char *index_file)if (index_file) {/* Reload index as apply_all_patches() will have modified it. */ discard_cache (); -read_cache_from (index_file); +read_index_from (&the_index, index_file); }return 0 ;
@@ -1600,7 +1600,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pareturn error ("could not build fake ancestor" );discard_cache (); -read_cache_from (index_path); +read_index_from (&the_index, index_path);if (write_index_as_tree (orig_tree.hash, &the_index, index_path,0 ,NULL ))return error (_ ("Repository lacks necessary blobs to fall back on 3-way merge." ));
builtin/commit.c +3 -3
@@ -370,7 +370,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixunsetenv (INDEX_ENVIRONMENT );discard_cache (); -read_cache_from (get_lock_file_path (&index_lock)); +read_index_from (&the_index,get_lock_file_path (&index_lock));if (update_main_cache_tree (WRITE_TREE_SILENT ) ==0 ) {if (reopen_lock_file (&index_lock) <0 )die (_ ("unable to write index file" ));
@@ -489,7 +489,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixdiscard_cache (); ret =get_lock_file_path (&false_lock); -read_cache_from (ret); +read_index_from (&the_index, ret);return ret; }
@@ -949,7 +949,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,* the editor and after we invoke run_status above. */ discard_cache (); -read_cache_from (index_file); +read_index_from (&the_index, index_file);if (update_main_cache_tree (0 )) {error (_ ("Error building trees" ));return 0 ;
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define read_cache_from (path) read_index_from(&the_index, (path))#define read_cache_preload (pathspec) read_index_preload(&the_index, (pathspec))#define is_cache_unborn () is_index_unborn(&the_index)#define read_cache_unmerged () read_index_unmerged(&the_index)
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 2/24 cache.h: drop active_* macros
In reply to Stefan BellerBased on the coccinelle patch:
@@ @@
-active_cache
+the_index.cache
@@ @@
-active_nr
+the_index.cache_nr
@@ @@
-active_alloc
+the_index.cache_alloc
@@ @@
-active_cache_changed
+the_index.cache_changed
@@ @@
-active_cache_tree
+the_index.cache_tree
Additional manual editing:
* drop the macros from cache.h
* fix the whitespace issue that apply complained about in builtin/checkout.c
* builtin/commit.c had an occurrence of active_cache_tree->sha1, which was not picked up with the coccinelle patch.
* diff.c and t/t2107-update-index-basic.sh referenced active_cache[_changed] in comments, fix them up.
* ative_nr was referenced in comments in read-cache.c and builtin/update-index.c, fix them.
--- apply.c | 6 ++--- builtin/add.c | 6 ++--- builtin/am.c | 6 ++--- builtin/blame.c | 6 ++--- builtin/checkout-index.c | 8 +++---- builtin/checkout.c | 49 ++++++++++++++++++++-------------------- builtin/commit.c | 20 ++++++++-------- builtin/fsck.c | 12 +++++----- builtin/grep.c | 8 +++---- builtin/ls-files.c | 36 ++++++++++++++--------------- builtin/merge-index.c | 10 ++++---- builtin/merge.c | 12 +++++----- builtin/mv.c | 10 ++++---- builtin/read-tree.c | 2 +- builtin/rm.c | 16 ++++++------- builtin/submodule--helper.c | 8 +++---- builtin/update-index.c | 48 ++++++++++++++++++++------------------- cache.h | 6 ----- check-racy.c | 4 ++-- diff-lib.c | 6 ++--- diff.c | 8 +++---- dir.c | 20 ++++++++-------- merge-recursive.c | 28 +++++++++++------------ pathspec.c | 14 ++++++------ read-cache.c | 2 +- rerere.c | 26 ++++++++++----------- revision.c | 18 +++++++-------- sequencer.c | 19 ++++++++-------- sha1_name.c | 14 ++++++------ submodule.c | 12 +++++----- t/helper/test-dump-cache-tree.c | 2 +- t/helper/test-scrap-cache-tree.c | 2 +- t/t2107-update-index-basic.sh | 2 +- tree.c | 8 +++---- wt-status.c | 12 +++++----- 35 files changed, 232 insertions(+), 234 deletions(-)
apply.c +3 -3
@@ -3499,7 +3499,7 @@ static int load_current(struct apply_state *state, pos =cache_name_pos (name,strlen (name));if (pos <0 )return error (_ ("%s: does not exist in index" ), name); - ce = active_cache[pos]; + ce = the_index.cache[pos];if (lstat (name, &st)) {if (errno !=ENOENT )return error_errno ("%s" , name);
@@ -3671,7 +3671,7 @@ static int check_preimage(struct apply_state *state, goto is_new;return error (_ ("%s: does not exist in index" ), old_name); } - *ce = active_cache[pos]; + *ce = the_index.cache[pos];if (stat_ret <0 ) {if (checkout_target (&the_index, *ce, st))return -1 ;
@@ -4001,7 +4001,7 @@ static int get_current_oid(struct apply_state *state, const char *path, pos =cache_name_pos (path,strlen (path));if (pos <0 )return -1 ; -oidcpy (oid, &active_cache[pos]->oid); +oidcpy (oid, &the_index.cache[pos]->oid);return 0 ; }
builtin/add.c +3 -3
@@ -34,8 +34,8 @@ static void chmod_pathspec(struct pathspec *pathspec, int force_mode) {int i; -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];if (pathspec && !ce_path_match (ce, pathspec,NULL ))continue ;
@@ -458,7 +458,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)unplug_bulk_checkin (); finish: -if (active_cache_changed) { +if (the_index.cache_changed) {if (write_locked_index (&the_index, &lock_file,COMMIT_LOCK ))die (_ ("Unable to write new index file" )); }
builtin/am.c +3 -3
@@ -1155,12 +1155,12 @@ static int index_has_changes(struct strbuf *sb)diff_flush (&opt);return DIFF_OPT_TST (&opt,HAS_CHANGES ) !=0 ; }else { -for (i =0 ; sb && i < active_nr; i++) { +for (i =0 ; sb && i < the_index.cache_nr; i++) {if (i)strbuf_addch (sb,' ' ); -strbuf_addstr (sb, active_cache[i]->name); +strbuf_addstr (sb, the_index.cache[i]->name); } -return !!active_nr; +return !!the_index.cache_nr; } }
builtin/blame.c +3 -3
@@ -2242,8 +2242,8 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path) pos =cache_name_pos (path,strlen (path));if (pos >=0 ) ;/* path is in the index */ -else if (-1 - pos < active_nr && - !strcmp (active_cache[-1 - pos]->name, path)) +else if (-1 - pos < the_index.cache_nr && + !strcmp (the_index.cache[-1 - pos]->name, path)) ;/* path is in the index, unmerged */ else die ("no such path '%s' in HEAD" , path);
@@ -2401,7 +2401,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,if (!mode) {int pos =cache_name_pos (path, len);if (0 <= pos) - mode = active_cache[pos]->ce_mode; + mode = the_index.cache[pos]->ce_mode;else /* Let's not bother reading from HEAD tree */ mode =S_IFREG |0644 ;
builtin/checkout-index.c +4 -4
@@ -54,8 +54,8 @@ static int checkout_file(const char *name, const char *prefix)if (pos <0 ) pos = -pos -1 ; -while (pos < active_nr) { -struct cache_entry *ce = active_cache[pos]; +while (pos < the_index.cache_nr) { +struct cache_entry *ce = the_index.cache[pos];if (ce_namelen (ce) != namelen ||memcmp (ce->name, name, namelen))break ;
@@ -95,8 +95,8 @@ static void checkout_all(const char *prefix, int prefix_length)int i, errs =0 ;struct cache_entry *last_ce =NULL ; -for (i =0 ; i < active_nr ; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr ; i++) { +struct cache_entry *ce = the_index.cache[i];if (ce_stage (ce) != checkout_stage && (CHECKOUT_ALL != checkout_stage || !ce_stage (ce)))continue ;
builtin/checkout.c +25 -24
122 lines not on this page · raw message
builtin/commit.c +10 -10
@@ -257,8 +257,8 @@ static int list_paths(struct string_list *list, const char *with_tree,free (max_prefix); } -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];struct string_list_item *item;if (ce->ce_flags &CE_UPDATE )
@@ -418,10 +418,10 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixif (!only && !pathspec.nr) {hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR );refresh_cache_or_die (refresh_flags); -if (active_cache_changed - || !cache_tree_fully_valid (active_cache_tree)) +if (the_index.cache_changed + || !cache_tree_fully_valid (the_index.cache_tree))update_main_cache_tree (WRITE_TREE_SILENT ); -if (active_cache_changed) { +if (the_index.cache_changed) {if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))die (_ ("unable to write new_index file" ));
@@ -888,7 +888,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,struct object_id oid;const char *parent ="HEAD" ; -if (!active_nr &&read_index (&the_index) <0 ) +if (!the_index.cache_nr &&read_index (&the_index) <0 )die (_ ("Cannot read index" ));if (amend)
@@ -897,10 +897,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,if (get_sha1 (parent, oid.hash)) {int i, ita_nr =0 ; -for (i =0 ; i < active_nr; i++) -if (ce_intent_to_add (active_cache[i])) +for (i =0 ; i < the_index.cache_nr; i++) +if (ce_intent_to_add (the_index.cache[i])) ita_nr++; - commitable = active_nr - ita_nr >0 ; + commitable = the_index.cache_nr - ita_nr >0 ; }else {/* * Unless the user did explicitly request a submodule
@@ -1758,7 +1758,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)append_merge_tag_headers (parents, &tail); } -if (commit_tree_extended (sb.buf, sb.len, active_cache_tree->sha1, +if (commit_tree_extended (sb.buf, sb.len, the_index.cache_tree->sha1, parents, oid.hash, author_ident.buf, sign_commit, extra)) {rollback_index_files ();die (_ ("failed to write commit object" ));
builtin/fsck.c +6 -6
@@ -773,15 +773,15 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (keep_cache_objects) { verify_index_checksum =1 ;read_index (&the_index); -for (i =0 ; i < active_nr; i++) { +for (i =0 ; i < the_index.cache_nr; i++) {unsigned int mode;struct blob *blob;struct object *obj; - mode = active_cache[i]->ce_mode; + mode = the_index.cache[i]->ce_mode;if (S_ISGITLINK (mode))continue ; - blob =lookup_blob (active_cache[i]->oid.hash); + blob =lookup_blob (the_index.cache[i]->oid.hash);if (!blob)continue ; obj = &blob->object;
@@ -789,11 +789,11 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)if (name_objects)add_decoration (fsck_walk_options.object_names, obj, -xstrfmt (":%s" , active_cache[i]->name)); +xstrfmt (":%s" , the_index.cache[i]->name));mark_object_reachable (obj); } -if (active_cache_tree) -fsck_cache_tree (active_cache_tree); +if (the_index.cache_tree) +fsck_cache_tree (the_index.cache_tree); }check_connectivity ();
builtin/grep.c +4 -4
@@ -678,8 +678,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,read_index (&the_index); -for (nr =0 ; nr < active_nr; nr++) { -const struct cache_entry *ce = active_cache[nr]; +for (nr =0 ; nr < the_index.cache_nr; nr++) { +const struct cache_entry *ce = the_index.cache[nr];strbuf_setlen (&name, name_base_len);strbuf_addstr (&name, ce->name);
@@ -711,8 +711,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,if (ce_stage (ce)) {do { nr++; - }while (nr < active_nr && - !strcmp (ce->name, active_cache[nr]->name)); + }while (nr < the_index.cache_nr && + !strcmp (ce->name, the_index.cache[nr]->name)); nr--;/* compensate for loop control */ }if (hit && opt->status_only)
builtin/ls-files.c +18 -18
@@ -139,20 +139,20 @@ static void show_killed_files(struct dir_struct *dir)die ("BUG: killed-file %.*s not found" , ent->len, ent->name); pos = -pos -1 ; -while (pos < active_nr && -ce_stage (active_cache[pos])) +while (pos < the_index.cache_nr && +ce_stage (the_index.cache[pos])) pos++;/* skip unmerged */ -if (active_nr <= pos) +if (the_index.cache_nr <= pos)break ;/* pos points at a name immediately after * ent->name in the cache. Does it expect * ent->name to be a directory? */ - len =ce_namelen (active_cache[pos]); + len =ce_namelen (the_index.cache[pos]);if ((ent->len < len) && - !strncmp (active_cache[pos]->name, + !strncmp (the_index.cache[pos]->name, ent->name, ent->len) && - active_cache[pos]->name[ent->len] =='/' ) + the_index.cache[pos]->name[ent->len] =='/' ) killed =1 ;break ; }
@@ -340,8 +340,8 @@ static void show_files(struct dir_struct *dir)show_killed_files (dir); }if (show_cached || show_stage) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if ((dir->flags &DIR_SHOW_IGNORED ) && !ce_excluded (dir, ce))continue ;
@@ -354,8 +354,8 @@ static void show_files(struct dir_struct *dir) } }if (show_deleted || show_modified) { -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];struct stat st;int err; if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -388,19 +388,19 @@ static void prune_cache(const char *prefix, size_t prefixlen)if (pos <0 ) pos = -pos-1 ; first = pos; - last = active_nr; + last = the_index.cache_nr;while (last > first) {int next = (last + first) >>1 ; -const struct cache_entry *ce = active_cache[next]; +const struct cache_entry *ce = the_index.cache[next];if (!strncmp (ce->name, prefix, prefixlen)) { first = next+1 ;continue ; } last = next; } -memmove (active_cache, active_cache + pos, +memmove (the_index.cache, the_index.cache + pos, (last - pos) *sizeof (struct cache_entry *)); - active_nr = last - pos; + the_index.cache_nr = last - pos; }/*
@@ -426,8 +426,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)die ("bad tree-ish %s" , tree_name);/* Hoist the unmerged entries up to stage #3 to make room */ -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];if (!ce_stage (ce))continue ; ce->ce_flags |=CE_STAGEMASK ;
@@ -443,8 +443,8 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix)if (read_tree (tree,1 , &pathspec))die ("unable to read tree entries %s" , tree_name); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];switch (ce_stage (ce)) {case 0 : last_stage0 = ce;
builtin/merge-index.c +5 -5
@@ -12,11 +12,11 @@ static int merge_entry(int pos, const char *path)char hexbuf[4 ][GIT_MAX_HEXSZ +1 ];char ownbuf[4 ][60 ]; -if (pos >= active_nr) +if (pos >= the_index.cache_nr)die ("git merge-index: %s not in the cache" , path); found =0 ; do { - const struct cache_entry *ce = active_cache[pos]; + const struct cache_entry *ce = the_index.cache[pos]; int stage = ce_stage(ce); if (strcmp(ce->name, path))
@@ -26,7 +26,7 @@ static int merge_entry(int pos, const char *path)xsnprintf (ownbuf[stage],sizeof (ownbuf[stage]),"%o" , ce->ce_mode); arguments[stage] = hexbuf[stage]; arguments[stage +4 ] = ownbuf[stage]; - }while (++pos < active_nr); + }while (++pos < the_index.cache_nr);if (!found)die ("git merge-index: %s not in the cache" , path);
@@ -57,8 +57,8 @@ static void merge_one_path(const char *path)static void merge_all (void ) {int i; -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if (!ce_stage (ce))continue ; i +=merge_entry (i, ce->name)-1 ;
builtin/merge.c +6 -6
@@ -615,7 +615,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,if (!trees[nr_trees++])return -1 ; opts.fn = threeway_merge; -cache_tree_free (&active_cache_tree); +cache_tree_free (&the_index.cache_tree);for (i =0 ; i < nr_trees; i++) {parse_tree (trees[i]);init_tree_desc (t+i, trees[i]->buffer, trees[i]->size);
@@ -640,7 +640,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,hold_locked_index (&lock,LOCK_DIE_ON_ERROR );refresh_cache (REFRESH_QUIET ); -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));rollback_lock_file (&lock);
@@ -680,7 +680,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common, remoteheads->item, reversed, &result);if (clean <0 )exit (128 ); -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))die (_ ("unable to write %s" ),get_index_file ());rollback_lock_file (&lock);
@@ -703,8 +703,8 @@ static int count_unmerged_entries(void) {int i, ret =0 ; -for (i =0 ; i < active_nr; i++) -if (ce_stage (active_cache[i])) +for (i =0 ; i < the_index.cache_nr; i++) +if (ce_stage (the_index.cache[i])) ret++;return ret;
@@ -787,7 +787,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)hold_locked_index (&lock,LOCK_DIE_ON_ERROR );refresh_cache (REFRESH_QUIET ); -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));rollback_lock_file (&lock);
builtin/mv.c +5 -5
@@ -78,7 +78,7 @@ static void prepare_move_submodule(const char *src, int first, const char **submodule_gitfile) {struct strbuf submodule_dotgit =STRBUF_INIT ; -if (!S_ISGITLINK (active_cache[first]->ce_mode)) +if (!S_ISGITLINK (the_index.cache[first]->ce_mode))die (_ ("Directory %s is in index and no submodule?" ), src);if (!is_staging_gitmodules_ok ())die (_ ("Please stage your changes to .gitmodules or stash them to proceed" ));
@@ -102,8 +102,8 @@ static int index_range_of_same_dir(const char *src, int length,die (_ ("%.*s is in index" ), len_w_slash, src_w_slash); first =-1 - first; -for (last = first; last < active_nr; last++) { -const char *path = active_cache[last]->name; +for (last = first; last < the_index.cache_nr; last++) { +const char *path = the_index.cache[last]->name;if (strncmp (path, src_w_slash, len_w_slash))break ; }
@@ -209,7 +209,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) dst_len =strlen (dst);for (j =0 ; j < last - first; j++) { -const char *path = active_cache[first + j]->name; +const char *path = the_index.cache[first + j]->name; source[argc + j] = path; destination[argc + j] =prefix_path (dst, dst_len, path + length +1 );
@@ -293,7 +293,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)if (gitmodules_modified)stage_updated_gitmodules (); -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &lock_file,COMMIT_LOCK ))die (_ ("Unable to write new index file" ));
builtin/read-tree.c +1 -1
@@ -251,7 +251,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)if (opts.debug_unpack) opts.fn = debug_merge; -cache_tree_free (&active_cache_tree); +cache_tree_free (&the_index.cache_tree);for (i =0 ; i < nr_trees; i++) {struct tree *tree = trees[i];parse_tree (tree);
builtin/rm.c +8 -8
@@ -30,8 +30,8 @@ static int get_ours_cache_pos(const char *path, int pos) {int i = -pos -1 ; -while ((i < active_nr) && !strcmp (active_cache[i]->name, path)) { -if (ce_stage (active_cache[i]) ==2 ) +while ((i < the_index.cache_nr) && !strcmp (the_index.cache[i]->name, path)) { +if (ce_stage (the_index.cache[i]) ==2 )return i; i++; }
@@ -73,7 +73,7 @@ static void submodules_absorb_gitdir_if_needed(const char *prefix)if (pos <0 )continue ; } - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (!S_ISGITLINK(ce->ce_mode) || !file_exists(ce->name) ||
@@ -122,11 +122,11 @@ static int check_local_mod(struct object_id *head, int index_only)if (pos <0 )continue ; -if (!S_ISGITLINK (active_cache[pos]->ce_mode) || +if (!S_ISGITLINK (the_index.cache[pos]->ce_mode) ||is_empty_dir (name))continue ; } - ce = active_cache[pos]; + ce = the_index.cache[pos];if (lstat (ce->name, &st) <0 ) {if (errno !=ENOENT && errno !=ENOTDIR )
@@ -278,8 +278,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) seen =xcalloc (pathspec.nr,1 ); -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if (!ce_path_match (ce, &pathspec, seen))continue ;ALLOC_GROW (list.entry, list.nr +1 , list.alloc);
@@ -386,7 +386,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)stage_updated_gitmodules (); } -if (active_cache_changed) { +if (the_index.cache_changed) {if (write_locked_index (&the_index, &lock_file,COMMIT_LOCK ))die (_ ("Unable to write new index file" )); }
builtin/submodule--helper.c +4 -4
@@ -243,8 +243,8 @@ static int module_list_compute(int argc, const char **argv,if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i]; if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), 0, ps_matched, 1) ||
@@ -253,8 +253,8 @@ static int module_list_compute(int argc, const char **argv,ALLOC_GROW (list->entries, list->nr +1 , list->alloc); list->entries[list->nr++] = ce; -while (i +1 < active_nr && - !strcmp (ce->name, active_cache[i +1 ]->name)) +while (i +1 < the_index.cache_nr && + !strcmp (ce->name, the_index.cache[i +1 ]->name))/* * Skip entries with the same name in different stages * to make sure an entry is returned only once.
builtin/update-index.c +25 -23
134 lines not on this page · raw message
cache.h +0 -6
@@ -354,12 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define active_cache (the_index.cache) -#define active_nr (the_index.cache_nr) -#define active_alloc (the_index.cache_alloc) -#define active_cache_changed (the_index.cache_changed) -#define active_cache_tree (the_index.cache_tree) -#define read_cache_from (path) read_index_from(&the_index, (path))#define read_cache_preload (pathspec) read_index_preload(&the_index, (pathspec))#define is_cache_unborn () is_index_unborn(&the_index)
check-racy.c +2 -2
@@ -7,8 +7,8 @@ int main(int ac, char **av) dirty = clean = racy =0 ;read_index (&the_index); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];struct stat st;if (lstat (ce->name, &st)) {
diff-lib.c +3 -3
@@ -95,10 +95,10 @@ int run_diff_files(struct rev_info *revs, unsigned int option)if (diff_unmerged_stage <0 ) diff_unmerged_stage =2 ; - entries = active_nr; + entries = the_index.cache_nr;for (i =0 ; i < entries; i++) {unsigned int oldmode, newmode; -struct cache_entry *ce = active_cache[i]; +struct cache_entry *ce = the_index.cache[i];int changed;unsigned dirty_submodule =0 ;const unsigned char *old_sha1, *new_sha1;
@@ -142,7 +142,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) dpath->mode = wt_mode;while (i < entries) { -struct cache_entry *nce = active_cache[i]; +struct cache_entry *nce = the_index.cache[i];int stage;if (strcmp (ce->name, nce->name))
diff.c +4 -4
@@ -2736,7 +2736,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int* by diff-cache --cached, which does read the cache before * calling us. */ -if (!active_cache) +if (!the_index.cache)return 0 ;/* We want to avoid the working directory if our caller
@@ -2762,7 +2762,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int pos =cache_name_pos (name, len);if (pos <0 )return 0 ; - ce = active_cache[pos]; + ce = the_index.cache[pos];/* * This is not the sha1 we are looking for, or
@@ -3490,10 +3490,10 @@ void diff_setup_done(struct diff_options *options)if (options->detect_rename && options->rename_limit <0 ) options->rename_limit = diff_rename_limit_default;if (options->setup &DIFF_SETUP_USE_CACHE ) { -if (!active_cache) +if (!the_index.cache)/* read-cache does not die even when it fails * so it is safe for us to do this here. Also -* it does not smudge active_cache or active_nr +* it does not smudge cache or nr of the_index * when it fails, so we do not have to worry about * cleaning it up ourselves either. */
dir.c +10 -10
@@ -599,9 +599,9 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size, pos =cache_name_pos (path, len);if (pos <0 )return NULL ; -if (!ce_skip_worktree (active_cache[pos])) +if (!ce_skip_worktree (the_index.cache[pos]))return NULL ; - data =read_sha1_file (active_cache[pos]->oid.hash, &type, &sz); + data =read_sha1_file (the_index.cache[pos]->oid.hash, &type, &sz);if (!data || type !=OBJ_BLOB ) {free (data);return NULL ;
@@ -609,7 +609,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size, *size =xsize_t (sz);if (sha1_stat) {memset (&sha1_stat->stat,0 ,sizeof (sha1_stat->stat)); -hashcpy (sha1_stat->sha1, active_cache[pos]->oid.hash); +hashcpy (sha1_stat->sha1, the_index.cache[pos]->oid.hash); }return data; }
@@ -786,11 +786,11 @@ static int add_excludes(const char *fname, const char *base, int baselen, ;/* no content change, ss->sha1 still good */ else if (check_index && (pos = cache_name_pos(fname, strlen(fname))) >= 0 && - !ce_stage(active_cache[pos]) && - ce_uptodate(active_cache[pos]) && + !ce_stage(the_index.cache[pos]) && + ce_uptodate(the_index.cache[pos]) && !would_convert_to_git(fname))hashcpy (sha1_stat->sha1, - active_cache[pos]->oid.hash); + the_index.cache[pos]->oid.hash); else hash_sha1_file(buf, size, "blob", sha1_stat->sha1);fill_stat_data (&sha1_stat->stat, &st);
@@ -1293,8 +1293,8 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len) pos =cache_name_pos (dirname, len);if (pos <0 ) pos = -pos-1 ; -while (pos < active_nr) { -const struct cache_entry *ce = active_cache[pos++]; +while (pos < the_index.cache_nr) { +const struct cache_entry *ce = the_index.cache[pos++];unsigned char endchar;if (strncmp (ce->name, dirname, len))
@@ -1478,8 +1478,8 @@ static int get_index_dtype(const char *path, int len)if (pos >=0 )return DT_UNKNOWN ; pos = -pos-1 ; -while (pos < active_nr) { - ce = active_cache[pos++]; +while (pos < the_index.cache_nr) { + ce = the_index.cache[pos++];if (strncmp (ce->name, path, len))break ;if (ce->name[len] >'/' )
merge-recursive.c +14 -14
@@ -275,7 +275,7 @@ static int git_merge_trees(int index_only,init_tree_desc_from_tree (t+2 , merge); rc =unpack_trees (3 , t, &opts); -cache_tree_free (&active_cache_tree); +cache_tree_free (&the_index.cache_tree);return rc; }
@@ -286,8 +286,8 @@ struct tree *write_tree_from_memory(struct merge_options *o)if (unmerged_cache ()) {int i;fprintf (stderr,"BUG: There are unmerged index entries:\n" ); -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if (ce_stage (ce))fprintf (stderr,"BUG: %d %.*s\n" ,ce_stage (ce), (int )ce_namelen (ce), ce->name);
@@ -295,16 +295,16 @@ struct tree *write_tree_from_memory(struct merge_options *o)die ("BUG: unmerged index entries in merge-recursive.c" ); } -if (!active_cache_tree) - active_cache_tree =cache_tree (); +if (!the_index.cache_tree) + the_index.cache_tree =cache_tree (); -if (!cache_tree_fully_valid (active_cache_tree) && +if (!cache_tree_fully_valid (the_index.cache_tree) &&cache_tree_update (&the_index,0 ) <0 ) {err (o,_ ("error building trees" ));return NULL ; } - result =lookup_tree (active_cache_tree->sha1); + result =lookup_tree (the_index.cache_tree->sha1);return result; }
@@ -370,10 +370,10 @@ static struct string_list *get_unmerged(void) unmerged->strdup_strings =1 ; -for (i =0 ; i < active_nr; i++) { +for (i =0 ; i < the_index.cache_nr; i++) {struct string_list_item *item;struct stage_data *e; -const struct cache_entry *ce = active_cache[i]; +const struct cache_entry *ce = the_index.cache[i];if (!ce_stage (ce))continue ;
@@ -683,8 +683,8 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)if (pos <0 ) pos =-1 - pos; -if (pos < active_nr && - !strncmp (dirpath.buf, active_cache[pos]->name, dirpath.len)) { +if (pos < the_index.cache_nr && + !strncmp (dirpath.buf, the_index.cache[pos]->name, dirpath.len)) {strbuf_release (&dirpath);return 1 ; }
@@ -709,9 +709,9 @@ static int was_tracked(const char *path)* had the path tracked (and resulted in a conflict). */ for (pos =-1 - pos; - pos < active_nr && !strcmp (path, active_cache[pos]->name); + pos < the_index.cache_nr && !strcmp (path, the_index.cache[pos]->name); pos++) -if (ce_stage (active_cache[pos]) ==2 ) +if (ce_stage (the_index.cache[pos]) ==2 )return 1 ;return 0 ; }
@@ -2145,7 +2145,7 @@ int merge_recursive_generic(struct merge_options *o,if (clean <0 )return clean; -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, lock,COMMIT_LOCK ))return err (o,_ ("Unable to write index." ));
pathspec.c +7 -7
@@ -32,8 +32,8 @@ void add_pathspec_matches_against_index(const struct pathspec *pathspec, num_unmatched++;if (!num_unmatched)return ; -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];ce_path_match (ce, pathspec, seen); } }
@@ -391,7 +391,7 @@ static void strip_submodule_slash_cheap(struct pathspec_item *item)if (item->len >=1 && item->match[item->len -1 ] =='/' ) {int i =cache_name_pos (item->match, item->len -1 ); -if (i >=0 &&S_ISGITLINK (active_cache[i]->ce_mode)) { +if (i >=0 &&S_ISGITLINK (the_index.cache[i]->ce_mode)) { item->len--; item->match[item->len] ='\0' ; }
@@ -402,8 +402,8 @@ static void strip_submodule_slash_expensive(struct pathspec_item *item) {int i; -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];int ce_len =ce_namelen (ce);if (!S_ISGITLINK (ce->ce_mode))
@@ -428,8 +428,8 @@ static void die_inside_submodule_path(struct pathspec_item *item) {int i; -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];int ce_len =ce_namelen (ce);if (!S_ISGITLINK (ce->ce_mode))
read-cache.c +1 -1
@@ -1791,7 +1791,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) istate->timestamp.nsec =ST_MTIME_NSEC (st);while (src_offset <= mmap_size -20 -8 ) { -/* After an array of active_nr index entries, +/* After an array of the_index.cache_nr index entries, * there can be arbitrary number of extended * sections, each of which is prefixed with * extension name (4-byte) and section length
rerere.c +13 -13
@@ -523,7 +523,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output*/ static int check_one_conflict (int i,int *type) { -const struct cache_entry *e = active_cache[i]; +const struct cache_entry *e = the_index.cache[i];if (!ce_stage (e)) { *type =RESOLVED ;
@@ -531,13 +531,13 @@ static int check_one_conflict(int i, int *type) } *type =PUNTED ; -while (ce_stage (active_cache[i]) ==1 ) +while (ce_stage (the_index.cache[i]) ==1 ) i++;/* Only handle regular files with both stages #2 and #3 */ -if (i +1 < active_nr) { -const struct cache_entry *e2 = active_cache[i]; -const struct cache_entry *e3 = active_cache[i +1 ]; +if (i +1 < the_index.cache_nr) { +const struct cache_entry *e2 = the_index.cache[i]; +const struct cache_entry *e3 = the_index.cache[i +1 ]; if (ce_stage(e2) == 2 && ce_stage(e3) == 3 && ce_same_name(e, e3) &&
@@ -547,7 +547,7 @@ static int check_one_conflict(int i, int *type) }/* Skip the entries with the same name */ -while (i < active_nr &&ce_same_name (e, active_cache[i])) +while (i < the_index.cache_nr &&ce_same_name (e, the_index.cache[i])) i++;return i; }
@@ -569,9 +569,9 @@ static int find_conflict(struct string_list *conflict)if (read_index (&the_index) <0 )return error ("Could not read index" ); -for (i =0 ; i < active_nr;) { +for (i =0 ; i < the_index.cache_nr;) {int conflict_type; -const struct cache_entry *e = active_cache[i]; +const struct cache_entry *e = the_index.cache[i]; i =check_one_conflict (i, &conflict_type);if (conflict_type ==THREE_STAGED )string_list_insert (conflict, (const char *)e->name);
@@ -602,9 +602,9 @@ int rerere_remaining(struct string_list *merge_rr)if (read_index (&the_index) <0 )return error ("Could not read index" ); -for (i =0 ; i < active_nr;) { +for (i =0 ; i < the_index.cache_nr;) {int conflict_type; -const struct cache_entry *e = active_cache[i]; +const struct cache_entry *e = the_index.cache[i]; i =check_one_conflict (i, &conflict_type);if (conflict_type ==PUNTED )string_list_insert (merge_rr, (const char *)e->name);
@@ -718,7 +718,7 @@ static void update_paths(struct string_list *update) item->string); } -if (active_cache_changed) { +if (the_index.cache_changed) {if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))die ("Unable to write new index file" ); }else
@@ -971,11 +971,11 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpureturn -1 ; pos = -pos -1 ; -while (pos < active_nr) { +while (pos < the_index.cache_nr) {enum object_type type;unsigned long size; - ce = active_cache[pos++]; + ce = the_index.cache[pos++];if (ce_namelen (ce) != len ||memcmp (ce->name, path, len))break ; i =ce_stage (ce) -1 ;
revision.c +9 -9
@@ -1268,8 +1268,8 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)int i;read_index (&the_index); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i];struct blob *blob;if (S_ISGITLINK (ce->ce_mode))
@@ -1282,9 +1282,9 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) ce->ce_mode, ce->name); } -if (active_cache_tree) { +if (the_index.cache_tree) {struct strbuf path =STRBUF_INIT ; -add_cache_tree (active_cache_tree, revs, &path); +add_cache_tree (the_index.cache_tree, revs, &path);strbuf_release (&path); } }
@@ -1407,10 +1407,10 @@ static void prepare_show_merge(struct rev_info *revs)free_commit_list (bases); head->object.flags |=SYMMETRIC_LEFT ; -if (!active_nr) +if (!the_index.cache_nr)read_index (&the_index); -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if (!ce_stage (ce))continue ;if (ce_path_match (ce, &revs->prune_data,NULL )) {
@@ -1419,8 +1419,8 @@ static void prepare_show_merge(struct rev_info *revs) prune[prune_num-2 ] = ce->name; prune[prune_num-1 ] =NULL ; } -while ((i+1 < active_nr) && -ce_same_name (ce, active_cache[i+1 ])) +while ((i+1 < the_index.cache_nr) && +ce_same_name (ce, the_index.cache[i+1 ])) i++; }clear_pathspec (&revs->prune_data);
sequencer.c +10 -9
@@ -413,12 +413,12 @@ void append_conflicts_hint(struct strbuf *msgbuf)strbuf_addch (msgbuf,'\n' );strbuf_commented_addf (msgbuf,"Conflicts:\n" ); -for (i =0 ; i < active_nr;) { -const struct cache_entry *ce = active_cache[i++]; +for (i =0 ; i < the_index.cache_nr;) { +const struct cache_entry *ce = the_index.cache[i++];if (ce_stage (ce)) {strbuf_commented_addf (msgbuf,"\t%s\n" , ce->name); -while (i < active_nr && !strcmp (ce->name, - active_cache[i]->name)) +while (i < the_index.cache_nr && !strcmp (ce->name, + the_index.cache[i]->name)) i++; } }
@@ -462,7 +462,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,if (clean <0 )return clean; -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))/* TRANSLATORS: %s will be "revert", "cherry-pick" or * "rebase -i".
@@ -501,14 +501,15 @@ static int is_index_unchanged(void)if (parse_commit (head_commit))return -1 ; -if (!active_cache_tree) - active_cache_tree =cache_tree (); +if (!the_index.cache_tree) + the_index.cache_tree =cache_tree (); -if (!cache_tree_fully_valid (active_cache_tree)) +if (!cache_tree_fully_valid (the_index.cache_tree))if (cache_tree_update (&the_index,0 ))return error (_ ("unable to update cache tree\n" )); -return !hashcmp (active_cache_tree->sha1, head_commit->tree->object.oid.hash); +return !hashcmp (the_index.cache_tree->sha1, + head_commit->tree->object.oid.hash); }static int write_author_script (const char *message)
sha1_name.c +7 -7
@@ -1444,8 +1444,8 @@ static void diagnose_invalid_index_path(int stage, pos =cache_name_pos (filename, namelen);if (pos <0 ) pos = -pos -1 ; -if (pos < active_nr) { - ce = active_cache[pos]; +if (pos < the_index.cache_nr) { + ce = the_index.cache[pos];if (ce_namelen (ce) == namelen && !memcmp (ce->name, filename, namelen)) die("Path '%s' is in the index, but not at stage %d.\n"
@@ -1460,8 +1460,8 @@ static void diagnose_invalid_index_path(int stage, pos =cache_name_pos (fullname.buf, fullname.len);if (pos <0 ) pos = -pos -1 ; -if (pos < active_nr) { - ce = active_cache[pos]; +if (pos < the_index.cache_nr) { + ce = the_index.cache[pos];if (ce_namelen (ce) == fullname.len && !memcmp (ce->name, fullname.buf, fullname.len)) die("Path '%s' is in the index, but not '%s'.\n"
@@ -1551,13 +1551,13 @@ static int get_sha1_with_context_1(const char *name,strlcpy (oc->path, cp,sizeof (oc->path)); -if (!active_cache) +if (!the_index.cache)read_index (&the_index); pos =cache_name_pos (cp, namelen);if (pos <0 ) pos = -pos -1 ; -while (pos < active_nr) { - ce = active_cache[pos]; +while (pos < the_index.cache_nr) { + ce = the_index.cache[pos];if (ce_namelen (ce) != namelen ||memcmp (ce->name, cp, namelen))break ;
submodule.c +6 -6
@@ -182,16 +182,16 @@ void gitmodules_config(void) pos =cache_name_pos (".gitmodules" ,11 );if (pos <0 ) {/* .gitmodules not found or isn't merged */ pos =-1 - pos; -if (active_nr > pos) {/* there is a .gitmodules */ -const struct cache_entry *ce = active_cache[pos]; +if (the_index.cache_nr > pos) {/* there is a .gitmodules */ +const struct cache_entry *ce = the_index.cache[pos];if (ce_namelen (ce) ==11 && !memcmp (ce->name,".gitmodules" ,11 )) gitmodules_is_unmerged =1 ; } - }else if (pos < active_nr) { + }else if (pos < the_index.cache_nr) {struct stat st;if (lstat (".gitmodules" , &st) ==0 && -ce_match_stat (active_cache[pos], &st,0 ) &DATA_CHANGED ) +ce_match_stat (the_index.cache[pos], &st,0 ) &DATA_CHANGED ) gitmodules_is_modified =1 ; }
@@ -1038,11 +1038,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 < the_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 = the_index.cache[spf->count];const char *git_dir, *default_argv;const struct submodule *submodule;
t/helper/test-dump-cache-tree.c +1 -1
@@ -64,5 +64,5 @@ int cmd_main(int ac, const char **av) istate = the_index; istate.cache_tree = another;cache_tree_update (&istate,WRITE_TREE_DRY_RUN ); -return dump_cache_tree (active_cache_tree, another,"" ); +return dump_cache_tree (the_index.cache_tree, another,"" ); }
t/helper/test-scrap-cache-tree.c +1 -1
@@ -11,7 +11,7 @@ int cmd_main(int ac, const char **av)hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR );if (read_index (&the_index) <0 )die ("unable to read index file" ); - active_cache_tree =NULL ; + the_index.cache_tree =NULL ;if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))die ("unable to write index file" );return 0 ;
t/t2107-update-index-basic.sh +1 -1
@@ -74,7 +74,7 @@ test_expect_success '.lock files cleaned up' ' cd repo && git config core.worktree ../../worktree && # --refresh triggers late setup_work_tree, - # active_cache_changed is zero, rollback_lock_file fails + # the_index.cache_changed is zero, rollback_lock_file fails git update-index --refresh && ! test -f .git/index.lock )
tree.c +4 -4
@@ -164,8 +164,8 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)* do it the original slow way, otherwise, append and then * sort at the end. */ -for (i =0 ; !fn && i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +for (i =0 ; !fn && i < the_index.cache_nr; i++) { +const struct cache_entry *ce = the_index.cache[i];if (ce_stage (ce) == stage) fn = read_one_entry; }
@@ -179,8 +179,8 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)/* * Sort the cache entry -- we need to nuke the cache tree, though. */ -cache_tree_free (&active_cache_tree); -QSORT (active_cache, active_nr, cmp_cache_name_compare); +cache_tree_free (&the_index.cache_tree); +QSORT (the_index.cache, the_index.cache_nr, cmp_cache_name_compare);return 0 ; }
wt-status.c +6 -6
@@ -487,8 +487,8 @@ static int unmerged_mask(const char *path) mask =0 ; pos = -pos-1 ; -while (pos < active_nr) { - ce = active_cache[pos++]; +while (pos < the_index.cache_nr) { + ce = the_index.cache[pos++];if (strcmp (ce->name, path) || !ce_stage (ce))break ; mask |= (1 << (ce_stage (ce) -1 ));
@@ -614,10 +614,10 @@ static void wt_status_collect_changes_initial(struct wt_status *s) {int i; -for (i =0 ; i < active_nr; i++) { +for (i =0 ; i < the_index.cache_nr; i++) {struct string_list_item *it;struct wt_status_change_data *d; -const struct cache_entry *ce = active_cache[i]; +const struct cache_entry *ce = the_index.cache[i];if (!ce_path_match (ce, &s->pathspec,NULL ))continue ;
@@ -2099,8 +2099,8 @@ static void wt_porcelain_v2_print_unmerged_entry( pos =cache_name_pos (it->string,strlen (it->string));assert (pos <0 ); pos = -pos-1 ; -while (pos < active_nr) { - ce = active_cache[pos++]; +while (pos < the_index.cache_nr) { + ce = the_index.cache[pos++]; stage =ce_stage (ce);if (strcmp (ce->name, it->string) || !stage)break ;
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 6/24 unpack-trees.c: rename parameter 'the_index'
In reply to Stefan BellerAs "the_index" is already a global variable, we do not want to confuse the local variable with the global variable.
--- unpack-trees.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
unpack-trees.c +4 -4
@@ -1199,7 +1199,7 @@ static int clear_ce_flags(struct cache_entry **cache, int nr,* Set/Clear CE_NEW_SKIP_WORKTREE according to $GIT_DIR/info/sparse-checkout */ static void mark_new_skip_worktree (struct exclude_list *el, -struct index_state *the_index, +struct index_state *index,int select_flag,int skip_wt_flag) {int i;
@@ -1208,8 +1208,8 @@ static void mark_new_skip_worktree(struct exclude_list *el,* 1. Pretend the narrowest worktree: only unmerged entries * are checked out */ -for (i =0 ; i < the_index->cache_nr; i++) { -struct cache_entry *ce = the_index->cache[i]; +for (i =0 ; i < index->cache_nr; i++) { +struct cache_entry *ce = index->cache[i];if (select_flag && !(ce->ce_flags & select_flag))continue ;
@@ -1224,7 +1224,7 @@ static void mark_new_skip_worktree(struct exclude_list *el,* 2. Widen worktree according to sparse-checkout file. * Matched entries will have skip_wt_flag cleared (i.e. "in") */ -clear_ce_flags (the_index->cache, the_index->cache_nr, +clear_ce_flags (index->cache, index->cache_nr, select_flag, skip_wt_flag, el); }
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 4/24 cache.h: drop read_cache_preload(pathspec)
In reply to Stefan Bellercoccinelle patch:
@@ expression E; @@
-read_cache_preload(E)
+read_index_preload(&the_index, E)
Additionally manual editing:
* drop the define from cache.h.
* builtin/{commit,describe}.c were not picked up as we have NULL and the address of an expression. Converted them manually.
* builtin/diff{-files,-index}.c error messages converted as well.
--- builtin/checkout.c | 4 ++-- builtin/commit.c | 4 ++-- builtin/describe.c | 2 +- builtin/diff-files.c | 4 ++-- builtin/diff-index.c | 4 ++-- builtin/diff.c | 8 ++++---- builtin/update-index.c | 2 +- cache.h | 1 - 8 files changed, 14 insertions(+), 15 deletions(-)
builtin/checkout.c +2 -2
@@ -295,7 +295,7 @@ static int checkout_paths(const struct checkout_opts *opts, lock_file =xcalloc (1 ,sizeof (struct lock_file ));hold_locked_index (lock_file,LOCK_DIE_ON_ERROR ); -if (read_cache_preload (&opts->pathspec) <0 ) +if (read_index_preload (&the_index, &opts->pathspec) <0 )return error (_ ("index file corrupt" ));if (opts->source_tree)
@@ -488,7 +488,7 @@ static int merge_working_tree(const struct checkout_opts *opts,struct lock_file *lock_file =xcalloc (1 ,sizeof (struct lock_file ));hold_locked_index (lock_file,LOCK_DIE_ON_ERROR ); -if (read_cache_preload (NULL ) <0 ) +if (read_index_preload (&the_index,NULL ) <0 )return error (_ ("index file corrupt" ));resolve_undo_clear ();
builtin/commit.c +2 -2
@@ -346,7 +346,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixPATHSPEC_PREFER_FULL , prefix, argv); -if (read_cache_preload (&pathspec) <0 ) +if (read_index_preload (&the_index, &pathspec) <0 )die (_ ("index file corrupt" ));if (interactive) {
@@ -1377,7 +1377,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)PATHSPEC_PREFER_FULL , prefix, argv); -read_cache_preload (&s.pathspec); +read_index_preload (&the_index, &s.pathspec);refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED , &s.pathspec,NULL ,NULL ); fd =hold_locked_index (&index_lock,0 );
builtin/describe.c +1 -1
@@ -531,7 +531,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)static struct lock_file index_lock;int fd; -read_cache_preload (NULL ); +read_index_preload (&the_index,NULL );refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED ,NULL ,NULL ,NULL ); fd =hold_locked_index (&index_lock,0 );
builtin/diff-files.c +2 -2
@@ -62,8 +62,8 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix) (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) rev.combine_merges = rev.dense_combined_merges = 1; -if (read_cache_preload (&rev.diffopt.pathspec) <0 ) { -perror ("read_cache_preload" ); +if (read_index_preload (&the_index, &rev.diffopt.pathspec) <0 ) { +perror ("read_index_preload" );return -1 ; } result =run_diff_files (&rev, options);
builtin/diff-index.c +2 -2
@@ -44,8 +44,8 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)usage (diff_cache_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (&rev.diffopt.pathspec) <0 ) { -perror ("read_cache_preload" ); +if (read_index_preload (&the_index, &rev.diffopt.pathspec) <0 ) { +perror ("read_index_preload" );return -1 ; } }else if (read_index (&the_index) <0 ) {
builtin/diff.c +4 -4
@@ -144,8 +144,8 @@ static int builtin_diff_index(struct rev_info *revs,usage (builtin_diff_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (&revs->diffopt.pathspec) <0 ) { -perror ("read_cache_preload" ); +if (read_index_preload (&the_index, &revs->diffopt.pathspec) <0 ) { +perror ("read_index_preload" );return -1 ; } }else if (read_index (&the_index) <0 ) {
@@ -246,8 +246,8 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv revs->combine_merges = revs->dense_combined_merges =1 ;setup_work_tree (); -if (read_cache_preload (&revs->diffopt.pathspec) <0 ) { -perror ("read_cache_preload" ); +if (read_index_preload (&the_index, &revs->diffopt.pathspec) <0 ) { +perror ("read_index_preload" );return -1 ; }return run_diff_files (revs, options);
builtin/update-index.c +1 -1
@@ -766,7 +766,7 @@ struct refresh_params {static int refresh (struct refresh_params *o,unsigned int flag) {setup_work_tree (); -read_cache_preload (NULL ); +read_index_preload (&the_index,NULL ); *o->has_errors |=refresh_cache (o->flags | flag);return 0 ; }
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define read_cache_preload (pathspec) read_index_preload(&the_index, (pathspec))#define is_cache_unborn () is_index_unborn(&the_index)#define read_cache_unmerged () read_index_unmerged(&the_index)#define discard_cache () discard_index(&the_index)
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 7/24 cache.h: drop read_blob_data_from_cache
In reply to Stefan BellerThis was done without cocinelle, as we only have 2 occurrences.
--- cache.h | 1 - convert.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
cache.h +0 -1
@@ -374,7 +374,6 @@ extern void free_name_hash(struct index_state *istate);#define resolve_undo_clear () resolve_undo_clear_index(&the_index)#define unmerge_cache_entry_at (at) unmerge_index_entry_at(&the_index, at)#define unmerge_cache (pathspec) unmerge_index(&the_index, pathspec) -#define read_blob_data_from_cache (path, sz) read_blob_data_from_index(&the_index, (path), (sz))#endif enum object_type {
convert.c +2 -2
@@ -137,7 +137,7 @@ const char *get_cached_convert_stats_ascii(const char *path) {const char *ret;unsigned long sz; -void *data =read_blob_data_from_cache (path, &sz); +void *data =read_blob_data_from_index (&the_index, path, &sz); ret =gather_convert_stats_ascii (data, sz);free (data);return ret;
@@ -222,7 +222,7 @@ static int has_cr_in_index(const char *path)void *data;int has_cr; - data =read_blob_data_from_cache (path, &sz); + data =read_blob_data_from_index (&the_index, path, &sz);if (!data)return 0 ; has_cr =memchr (data,'\r' , sz) !=NULL ;
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 5/24 cache.h: drop read_cache_unmerged()
In reply to Stefan Beller@@ @@
-read_cache_unmerged()
+read_index_unmerged(&the_index)
Additionally drop the define from cache.h manually.
--- builtin/am.c | 2 +- builtin/merge.c | 2 +- builtin/pull.c | 2 +- builtin/read-tree.c | 2 +- builtin/reset.c | 2 +- cache.h | 1 - sequencer.c | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-)
builtin/am.c +1 -1
@@ -2053,7 +2053,7 @@ static int clean_index(const struct object_id *head, const struct object_id *remif (!remote_tree)return error (_ ("Could not parse object '%s'." ),oid_to_hex (remote)); -read_cache_unmerged (); +read_index_unmerged (&the_index);if (fast_forward_to (head_tree, head_tree,1 ))return -1 ;
builtin/merge.c +1 -1
@@ -1170,7 +1170,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } -if (read_cache_unmerged ()) +if (read_index_unmerged (&the_index))die_resolve_conflict ("merge" );if (file_exists (git_path_merge_head ())) {
builtin/pull.c +1 -1
@@ -788,7 +788,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)git_config (git_pull_config,NULL ); -if (read_cache_unmerged ()) +if (read_index_unmerged (&the_index))die_resolve_conflict ("pull" );if (file_exists (git_path_merge_head ()))
builtin/read-tree.c +1 -1
@@ -195,7 +195,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)*/ if (opts.reset || opts.merge || opts.prefix) { -if (read_cache_unmerged () && (opts.prefix || opts.merge)) +if (read_index_unmerged (&the_index) && (opts.prefix || opts.merge))die ("You need to resolve your current index first" ); stage = opts.merge =1 ; }
builtin/reset.c +1 -1
@@ -66,7 +66,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet) opts.reset =1 ; } -read_cache_unmerged (); +read_index_unmerged (&the_index);if (reset_type ==KEEP ) {struct object_id head_oid;
cache.h +0 -1
@@ -355,7 +355,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #define is_cache_unborn () is_index_unborn(&the_index) -#define read_cache_unmerged () read_index_unmerged(&the_index)#define discard_cache () discard_index(&the_index)#define unmerged_cache () unmerged_index(&the_index)#define cache_name_pos (name, namelen) index_name_pos(&the_index,(name),(namelen))
sequencer.c +1 -1
@@ -349,7 +349,7 @@ static struct tree *empty_tree(void)static int error_dirty_index (struct replay_opts *opts) { -if (read_cache_unmerged ()) +if (read_index_unmerged (&the_index))return error_resolve_conflict (_ (action_name (opts))); error(_("your local changes would be overwritten by %s."),
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 10/24 cache.h: drop cache_name_is_other
In reply to Stefan Beller--- builtin/clean.c | 2 +- builtin/ls-files.c | 2 +- cache.h | 1 - dir.c | 2 +- wt-status.c | 4 ++-- 5 files changed, 5 insertions(+), 6 deletions(-)
builtin/clean.c +1 -1
@@ -938,7 +938,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)struct stat st;const char *rel; -if (!cache_name_is_other (ent->name, ent->len)) +if (!index_name_is_other (&the_index, ent->name, ent->len))continue ;if (pathspec.nr)
builtin/ls-files.c +1 -1
@@ -114,7 +114,7 @@ static void show_other_files(struct dir_struct *dir)for (i =0 ; i < dir->nr; i++) {struct dir_entry *ent = dir->entries[i]; -if (!cache_name_is_other (ent->name, ent->len)) +if (!index_name_is_other (&the_index, ent->name, ent->len))continue ;show_dir_entry (tag_other, ent); }
cache.h +0 -1
@@ -370,7 +370,6 @@ extern void free_name_hash(struct index_state *istate);#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options))#define cache_dir_exists (name, namelen) index_dir_exists(&the_index, (name), (namelen))#define cache_file_exists (name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase)) -#define cache_name_is_other (name, namelen) index_name_is_other(&the_index, (name), (namelen))#endif enum object_type {
dir.c +1 -1
@@ -1244,7 +1244,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathnastruct dir_entry *dir_add_ignored (struct dir_struct *dir,const char *pathname,int len) { -if (!cache_name_is_other (pathname, len)) +if (!index_name_is_other (&the_index, pathname, len))return NULL ;ALLOC_GROW (dir->ignored, dir->ignored_nr+1 , dir->ignored_alloc);
wt-status.c +2 -2
@@ -669,7 +669,7 @@ static void wt_status_collect_untracked(struct wt_status *s)for (i =0 ; i < dir.nr; i++) {struct dir_entry *ent = dir.entries[i]; -if (cache_name_is_other (ent->name, ent->len) && +if (index_name_is_other (&the_index, ent->name, ent->len) &&dir_path_match (ent, &s->pathspec,0 ,NULL ))string_list_insert (&s->untracked, ent->name);free (ent);
@@ -677,7 +677,7 @@ static void wt_status_collect_untracked(struct wt_status *s)for (i =0 ; i < dir.ignored_nr; i++) {struct dir_entry *ent = dir.ignored[i]; -if (cache_name_is_other (ent->name, ent->len) && +if (index_name_is_other (&the_index, ent->name, ent->len) &&dir_path_match (ent, &s->pathspec,0 ,NULL ))string_list_insert (&s->ignored, ent->name);free (ent);
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 12/24 cache.h: drop cache_dir_exists
In reply to Stefan Beller--- cache.h | 1 - dir.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-)
cache.h +0 -1
@@ -368,7 +368,6 @@ extern void free_name_hash(struct index_state *istate);#define refresh_cache (flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options)) -#define cache_dir_exists (name, namelen) index_dir_exists(&the_index, (name), (namelen))#endif enum object_type {
dir.c +1 -1
@@ -1266,7 +1266,7 @@ static enum exist_status directory_exists_in_index_icase(const char *dirname, in {struct cache_entry *ce; -if (cache_dir_exists (dirname, len)) +if (index_dir_exists (&the_index, dirname, len))return index_directory; ce =index_file_exists (&the_index, dirname, len, ignore_case);
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 11/24 cache.h: drop cache_file_exists
In reply to Stefan Beller--- apply.c | 2 +- cache.h | 1 - dir.c | 9 +++++---- merge-recursive.c | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-)
apply.c +1 -1
@@ -3810,7 +3810,7 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *naif (state->check_index) {struct cache_entry *ce; - ce =cache_file_exists (name->buf, name->len, ignore_case); + ce =index_file_exists (&the_index, name->buf, name->len, ignore_case);if (ce &&S_ISLNK (ce->ce_mode))return 1 ; }else {
cache.h +0 -1
@@ -369,7 +369,6 @@ extern void free_name_hash(struct index_state *istate);#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options))#define cache_dir_exists (name, namelen) index_dir_exists(&the_index, (name), (namelen)) -#define cache_file_exists (name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))#endif enum object_type {
dir.c +5 -4
@@ -1235,7 +1235,7 @@ static struct dir_entry *dir_entry_new(const char *pathname, int len)static struct dir_entry *dir_add_name (struct dir_struct *dir,const char *pathname,int len) { -if (cache_file_exists (pathname, len, ignore_case)) +if (index_file_exists (&the_index, pathname, len, ignore_case))return NULL ;ALLOC_GROW (dir->entries, dir->nr+1 , dir->alloc);
@@ -1269,7 +1269,7 @@ static enum exist_status directory_exists_in_index_icase(const char *dirname, inif (cache_dir_exists (dirname, len))return index_directory; - ce =cache_file_exists (dirname, len, ignore_case); + ce =index_file_exists (&the_index, dirname, len, ignore_case);if (ce &&S_ISGITLINK (ce->ce_mode))return index_gitdir;
@@ -1460,7 +1460,7 @@ static int get_index_dtype(const char *path, int len)int pos;const struct cache_entry *ce; - ce =cache_file_exists (path, len,0 ); + ce =index_file_exists (&the_index, path, len,0 );if (ce) {if (!ce_uptodate (ce))return DT_UNKNOWN ;
@@ -1522,7 +1522,8 @@ static enum path_treatment treat_one_path(struct dir_struct *dir, int dtype, struct dirent *de) { int exclude; -int has_path_in_index = !!cache_file_exists (path->buf, path->len, ignore_case); +int has_path_in_index = !!index_file_exists (&the_index, path->buf, + path->len, ignore_case);if (dtype ==DT_UNKNOWN ) dtype =get_dtype (de, path->buf, path->len);
merge-recursive.c +2 -1
@@ -623,7 +623,8 @@ static int remove_file(struct merge_options *o, int clean,if (update_working_directory) {if (ignore_case) {struct cache_entry *ce; - ce =cache_file_exists (path,strlen (path), ignore_case); + ce =index_file_exists (&the_index, path, +strlen (path), ignore_case);if (ce &&ce_stage (ce) ==0 )return 0 ; }
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 13/24 cache.h: drop is_cache_unborn(), discard_cache(), unmerged_cache()
In reply to Stefan Bellercocci semantic patch:
@@ @@
-is_cache_unborn()
+is_index_unborn(&the_index)
@@ @@
-discard_cache()
+discard_index(&the_index)
@@ @@
-unmerged_cache()
+unmerged_index(&the_index)
Additionally the defines in cache.h were removed manually.
--- builtin/am.c | 8 ++++---- builtin/blame.c | 2 +- builtin/checkout.c | 4 ++-- builtin/commit.c | 10 +++++----- builtin/diff.c | 2 +- builtin/pull.c | 2 +- builtin/read-tree.c | 2 +- builtin/reset.c | 2 +- cache.h | 3 --- merge-recursive.c | 8 ++++---- merge.c | 2 +- sequencer.c | 4 ++-- t/helper/test-lazy-init-name-hash.c | 10 +++++----- t/helper/test-read-cache.c | 2 +- wt-status.c | 2 +- 15 files changed, 30 insertions(+), 33 deletions(-)
builtin/am.c +4 -4
@@ -1556,7 +1556,7 @@ static int run_apply(const struct am_state *state, const char *index_file)if (index_file) {/* Reload index as apply_all_patches() will have modified it. */ -discard_cache (); +discard_index (&the_index);read_index_from (&the_index, index_file); }
@@ -1599,7 +1599,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_paif (build_fake_ancestor (state, index_path))return error ("could not build fake ancestor" ); -discard_cache (); +discard_index (&the_index);read_index_from (&the_index, index_path);if (write_index_as_tree (orig_tree.hash, &the_index, index_path,0 ,NULL ))
@@ -1632,7 +1632,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pasay (state, stdout,_ ("Falling back to patching base and 3-way merge..." )); -discard_cache (); +discard_index (&the_index);read_index (&the_index);/*
@@ -1938,7 +1938,7 @@ static void am_resolve(struct am_state *state)die_user_resolve (state); } -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {printf_ln (_ ("You still have unmerged paths in your index.\n" "Did you forget to use 'git add'?" ));die_user_resolve (state);
builtin/blame.c +1 -1
@@ -2394,7 +2394,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,* bits; we are not going to write this index out -- we just * want to run "diff-index --cached". */ -discard_cache (); +discard_index (&the_index);read_index (&the_index); len =strlen (path);
builtin/checkout.c +2 -2
@@ -510,13 +510,13 @@ static int merge_working_tree(const struct checkout_opts *opts,refresh_cache (REFRESH_QUIET ); -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {error (_ ("you need to resolve your current index first" ));return 1 ; }/* 2-way merge to the new branch */ - topts.initial_checkout =is_cache_unborn (); + topts.initial_checkout =is_index_unborn (&the_index); topts.update =1 ; topts.merge =1 ; topts.gently = opts->merge && old->commit;
builtin/commit.c +5 -5
@@ -301,7 +301,7 @@ static void create_base_index(const struct commit *current_head)struct tree_desc t;if (!current_head) { -discard_cache (); +discard_index (&the_index);return ; }
@@ -369,7 +369,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixelse unsetenv (INDEX_ENVIRONMENT ); -discard_cache (); +discard_index (&the_index);read_index_from (&the_index,get_lock_file_path (&index_lock));if (update_main_cache_tree (WRITE_TREE_SILENT ) ==0 ) {if (reopen_lock_file (&index_lock) <0 )
@@ -464,7 +464,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixif (list_paths (&partial, !current_head ?NULL :"HEAD" , prefix, &pathspec))exit (1 ); -discard_cache (); +discard_index (&the_index);if (read_index (&the_index) <0 )die (_ ("cannot read the index" ));
@@ -487,7 +487,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixif (write_locked_index (&the_index, &false_lock,CLOSE_LOCK ))die (_ ("unable to write temporary index file" )); -discard_cache (); +discard_index (&the_index); ret =get_lock_file_path (&false_lock);read_index_from (&the_index, ret);return ret;
@@ -948,7 +948,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,* and write it out as a tree. We must do this before we invoke * the editor and after we invoke run_status above. */ -discard_cache (); +discard_index (&the_index);read_index_from (&the_index, index_file);if (update_main_cache_tree (0 )) {error (_ ("Error building trees" ));
builtin/diff.c +1 -1
@@ -209,7 +209,7 @@ static void refresh_index_quietly(void) fd =hold_locked_index (lock_file,0 );if (fd <0 )return ; -discard_cache (); +discard_index (&the_index);read_index (&the_index);refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED );update_index_if_able (&the_index, lock_file);
builtin/pull.c +1 -1
@@ -805,7 +805,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)if (opt_autostash !=-1 ) autostash = opt_autostash; -if (is_null_oid (&orig_head) && !is_cache_unborn ()) +if (is_null_oid (&orig_head) && !is_index_unborn (&the_index))die (_ ("Updating an unborn branch with changes added to the index." ));if (!autostash)
builtin/read-tree.c +1 -1
@@ -234,7 +234,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)break ;case 2 : opts.fn = twoway_merge; - opts.initial_checkout =is_cache_unborn (); + opts.initial_checkout =is_index_unborn (&the_index);break ;case 3 :default :
builtin/reset.c +1 -1
@@ -179,7 +179,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,static void die_if_unmerged_cache (int reset_type) { -if (is_merge () ||unmerged_cache ()) +if (is_merge () ||unmerged_index (&the_index))die (_ ("Cannot do a %s reset in the middle of a merge." ),_ (reset_type_names[reset_type]));
cache.h +0 -3
@@ -354,9 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define is_cache_unborn () is_index_unborn(&the_index) -#define discard_cache () discard_index(&the_index) -#define unmerged_cache () unmerged_index(&the_index)#define cache_name_pos (name, namelen) index_name_pos(&the_index,(name),(namelen))#define add_cache_entry (ce, option) add_index_entry(&the_index, (ce), (option))#define rename_cache_entry_at (pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))
merge-recursive.c +4 -4
@@ -283,7 +283,7 @@ struct tree *write_tree_from_memory(struct merge_options *o) {struct tree *result =NULL ; -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {int i;fprintf (stderr,"BUG: There are unmerged index entries:\n" );for (i =0 ; i < the_index.cache_nr; i++) {
@@ -1942,7 +1942,7 @@ int merge_trees(struct merge_options *o,return -1 ; } -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {struct string_list *entries, *re_head, *re_merge;int i;string_list_clear (&o->current_file_set,1 );
@@ -2058,7 +2058,7 @@ int merge_recursive(struct merge_options *o,* overwritten it: the committed "conflicts" were * already resolved. */ -discard_cache (); +discard_index (&the_index); saved_b1 = o->branch1; saved_b2 = o->branch2; o->branch1 ="Temporary merge branch 1" ;
@@ -2074,7 +2074,7 @@ int merge_recursive(struct merge_options *o,return err (o,_ ("merge returned no commit" )); } -discard_cache (); +discard_index (&the_index);if (!o->call_depth)read_index (&the_index);
merge.c +1 -1
@@ -36,7 +36,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr, ret =run_command_v_opt (args.argv,RUN_GIT_CMD );argv_array_clear (&args); -discard_cache (); +discard_index (&the_index);if (read_index (&the_index) <0 )die (_ ("failed to read the cache" ));resolve_undo_clear_index (&the_index);
sequencer.c +2 -2
@@ -958,7 +958,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,if (index_differs_from (unborn ?EMPTY_TREE_SHA1_HEX :"HEAD" ,0 ,0 ))return error_dirty_index (opts); } -discard_cache (); +discard_index (&the_index);if (!commit->parents) parent =NULL ;
@@ -1845,7 +1845,7 @@ static int do_exec(const char *command_line) status =run_command_v_opt (child_argv,RUN_USING_SHELL );/* force re-reading of the cache */ -if (discard_cache () <0 ||read_index (&the_index) <0 ) +if (discard_index (&the_index) <0 ||read_index (&the_index) <0 )return error (_ ("could not read index" )); dirty =require_clean_work_tree ("rebase" ,NULL ,1 ,1 );
t/helper/test-lazy-init-name-hash.c +5 -5
@@ -52,7 +52,7 @@ static void dump_run(void) ce =hashmap_iter_next (&iter_cache); } -discard_cache (); +discard_index (&the_index); }/*
@@ -92,7 +92,7 @@ static uint64_t time_runs(int try_threaded) the_index.cache_nr);fflush (stdout); -discard_cache (); +discard_index (&the_index); } avg = sum / count;
@@ -118,7 +118,7 @@ static void analyze_run(void)read_index (&the_index); cache_nr_limit = the_index.cache_nr; -discard_cache (); +discard_index (&the_index); nr = analyze;while (1 ) {
@@ -138,7 +138,7 @@ static void analyze_run(void) t2s =getnanotime (); sum_single += (t2s - t1s); the_index.cache_nr = cache_nr_limit; -discard_cache (); +discard_index (&the_index);read_index (&the_index); the_index.cache_nr = nr;/* cheap truncate of index */
@@ -147,7 +147,7 @@ static void analyze_run(void) t2m =getnanotime (); sum_multi += (t2m - t1m); the_index.cache_nr = cache_nr_limit; -discard_cache (); +discard_index (&the_index);if (!nr_threads_used) printf(" [size %8d] [single %f] non-threaded code path used\n",
t/helper/test-read-cache.c +1 -1
@@ -8,7 +8,7 @@ int cmd_main(int argc, const char **argv)setup_git_directory ();for (i =0 ; i < cnt; i++) {read_index (&the_index); -discard_cache (); +discard_index (&the_index); }return 0 ; }
wt-status.c +1 -1
@@ -2247,7 +2247,7 @@ int has_uncommitted_changes(int ignore_submodules)struct rev_info rev_info;int result; -if (is_cache_unborn ()) +if (is_index_unborn (&the_index))return 0 ;init_revisions (&rev_info,NULL );
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 9/24 cache.h: drop resolve_undo_clear
In reply to Stefan Beller--- builtin/checkout.c | 2 +- builtin/merge.c | 2 +- builtin/read-tree.c | 2 +- builtin/update-index.c | 2 +- cache.h | 1 - merge.c | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-)
builtin/checkout.c +1 -1
@@ -491,7 +491,7 @@ static int merge_working_tree(const struct checkout_opts *opts,if (read_index_preload (&the_index,NULL ) <0 )return error (_ ("index file corrupt" )); -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);if (opts->force) { ret =reset_tree (new->commit->tree, opts,1 , writeout_error);if (ret)
builtin/merge.c +1 -1
@@ -1191,7 +1191,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)else die (_ ("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)." )); } -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);if (verbosity <0 ) show_diffstat =0 ;
builtin/read-tree.c +1 -1
@@ -199,7 +199,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)die ("You need to resolve your current index first" ); stage = opts.merge =1 ; } -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);for (i =0 ; i < argc; i++) {const char *arg = argv[i];
builtin/update-index.c +1 -1
@@ -796,7 +796,7 @@ static int chmod_callback(const struct option *opt,static int resolve_undo_clear_callback (const struct option *opt,const char *arg,int unset) { -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);return 0 ; }
cache.h +0 -1
@@ -371,7 +371,6 @@ extern void free_name_hash(struct index_state *istate);#define cache_dir_exists (name, namelen) index_dir_exists(&the_index, (name), (namelen))#define cache_file_exists (name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))#define cache_name_is_other (name, namelen) index_name_is_other(&the_index, (name), (namelen)) -#define resolve_undo_clear () resolve_undo_clear_index(&the_index)#endif enum object_type {
merge.c +1 -1
@@ -39,7 +39,7 @@ int try_merge_command(const char *strategy, size_t xopts_nr,discard_cache ();if (read_index (&the_index) <0 )die (_ ("failed to read the cache" )); -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);return ret; }
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 8/24 cache.h: drop unmerge_cache[_entry_at]
In reply to Stefan Beller--- builtin/update-index.c | 2 +- cache.h | 2 -- rerere.c | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-)
builtin/update-index.c +1 -1
@@ -613,7 +613,7 @@ static int unresolve_one(const char *path) pos =cache_name_pos (path, namelen);if (0 <= pos) {/* already merged */ - pos =unmerge_cache_entry_at (pos); + pos =unmerge_index_entry_at (&the_index, pos);if (pos < the_index.cache_nr) {const struct cache_entry *ce = the_index.cache[pos]; if (ce_stage(ce) &&
cache.h +0 -2
@@ -372,8 +372,6 @@ extern void free_name_hash(struct index_state *istate);#define cache_file_exists (name, namelen, igncase) index_file_exists(&the_index, (name), (namelen), (igncase))#define cache_name_is_other (name, namelen) index_name_is_other(&the_index, (name), (namelen))#define resolve_undo_clear () resolve_undo_clear_index(&the_index) -#define unmerge_cache_entry_at (at) unmerge_index_entry_at(&the_index, at) -#define unmerge_cache (pathspec) unmerge_index(&the_index, pathspec)#endif enum object_type {
rerere.c +1 -1
@@ -1116,7 +1116,7 @@ int rerere_forget(struct pathspec *pathspec)* recover the original conflicted state and then * find the conflicted paths. */ -unmerge_cache (pathspec); +unmerge_index (&the_index, pathspec);find_conflict (&conflict);for (i =0 ; i < conflict.nr; i++) {struct string_list_item *it = &conflict.items[i];
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 14/24 cache.h: drop cache_name_pos
In reply to Stefan Bellercoccinelle patch:
@@ expression name, namelen; @@
-cache_name_pos(name, namelen)
+index_name_pos(&the_index, name, namelen)
Additionally manual editing:
* drop the define from cache.h.
--- apply.c | 9 +++++---- builtin/blame.c | 4 ++-- builtin/checkout-index.c | 2 +- builtin/checkout.c | 2 +- builtin/ls-files.c | 7 ++++--- builtin/merge-index.c | 2 +- builtin/mv.c | 8 ++++---- builtin/rm.c | 4 ++-- builtin/update-index.c | 10 +++++----- cache.h | 1 - diff.c | 2 +- dir.c | 8 ++++---- merge-recursive.c | 4 ++-- pathspec.c | 2 +- rerere.c | 2 +- sha1_name.c | 6 +++--- submodule.c | 2 +- wt-status.c | 4 ++-- 18 files changed, 40 insertions(+), 39 deletions(-)
apply.c +5 -4
@@ -3496,7 +3496,7 @@ static int load_current(struct apply_state *state,if (!patch->is_new)die ("BUG: patch to %s is not a creation" , patch->old_name); - pos =cache_name_pos (name,strlen (name)); + pos =index_name_pos (&the_index, name,strlen (name));if (pos <0 )return error (_ ("%s: does not exist in index" ), name); ce = the_index.cache[pos];
@@ -3665,7 +3665,8 @@ static int check_preimage(struct apply_state *state, }if (state->check_index && !previous) { -int pos =cache_name_pos (old_name,strlen (old_name)); +int pos =index_name_pos (&the_index, old_name, +strlen (old_name));if (pos <0 ) {if (patch->is_new <0 ) goto is_new;
@@ -3721,7 +3722,7 @@ static int check_to_create(struct apply_state *state,struct stat nst;if (state->check_index && -cache_name_pos (new_name,strlen (new_name)) >=0 && +index_name_pos (&the_index, new_name,strlen (new_name)) >=0 && !ok_if_exists)return EXISTS_IN_INDEX ;if (state->cached)
@@ -3998,7 +3999,7 @@ static int get_current_oid(struct apply_state *state, const char *path,if (read_apply_cache (state) <0 )return -1 ; - pos =cache_name_pos (path,strlen (path)); + pos =index_name_pos (&the_index, path,strlen (path));if (pos <0 )return -1 ;oidcpy (oid, &the_index.cache[pos]->oid);
builtin/blame.c +2 -2
@@ -2239,7 +2239,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)return ; } - pos =cache_name_pos (path,strlen (path)); + pos =index_name_pos (&the_index, path,strlen (path));if (pos >=0 ) ;/* path is in the index */ else if (-1 - pos < the_index.cache_nr &&
@@ -2399,7 +2399,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, len =strlen (path);if (!mode) { -int pos =cache_name_pos (path, len); +int pos =index_name_pos (&the_index, path, len);if (0 <= pos) mode = the_index.cache[pos]->ce_mode;else
builtin/checkout-index.c +1 -1
@@ -46,7 +46,7 @@ static void write_tempfile_record(const char *name, const char *prefix)static int checkout_file (const char *name,const char *prefix) {int namelen =strlen (name); -int pos =cache_name_pos (name, namelen); +int pos =index_name_pos (&the_index, name, namelen);int has_same_name =0 ;int did_checkout =0 ;int errs =0 ;
builtin/checkout.c +1 -1
@@ -107,7 +107,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,* entry in place. Whether it is UPTODATE or not, checkout_entry will * do the right thing. */ - pos =cache_name_pos (ce->name, ce->ce_namelen); + pos =index_name_pos (&the_index, ce->name, ce->ce_namelen);if (pos >=0 ) {struct cache_entry *old = the_index.cache[pos]; if (ce->ce_mode == old->ce_mode &&
builtin/ls-files.c +4 -3
@@ -134,7 +134,8 @@ static void show_killed_files(struct dir_struct *dir)/* If ent->name is prefix of an entry in the * cache, it will be killed. */ - pos =cache_name_pos (ent->name, ent->len); + pos =index_name_pos (&the_index, ent->name, + ent->len);if (0 <= pos)die ("BUG: killed-file %.*s not found" , ent->len, ent->name);
@@ -156,7 +157,7 @@ static void show_killed_files(struct dir_struct *dir) killed =1 ;break ; } -if (0 <=cache_name_pos (ent->name, sp - ent->name)) { +if (0 <=index_name_pos (&the_index, ent->name, sp - ent->name)) {/* If any of the leading directories in * ent->name is registered in the cache, * ent->name will be killed.
@@ -384,7 +385,7 @@ static void prune_cache(const char *prefix, size_t prefixlen)if (!prefix)return ; - pos =cache_name_pos (prefix, prefixlen); + pos =index_name_pos (&the_index, prefix, prefixlen);if (pos <0 ) pos = -pos-1 ; first = pos;
builtin/merge-index.c +1 -1
@@ -44,7 +44,7 @@ static int merge_entry(int pos, const char *path)static void merge_one_path (const char *path) { -int pos =cache_name_pos (path,strlen (path)); +int pos =index_name_pos (&the_index, path,strlen (path));/* * If it already exists in the cache as stage0, it's
builtin/mv.c +4 -4
@@ -97,7 +97,7 @@ static int index_range_of_same_dir(const char *src, int length,const char *src_w_slash =add_slash (src);int first, last, len_w_slash = length +1 ; - first =cache_name_pos (src_w_slash, len_w_slash); + first =index_name_pos (&the_index, src_w_slash, len_w_slash);if (first >=0 )die (_ ("%.*s is in index" ), len_w_slash, src_w_slash);
@@ -187,7 +187,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) && lstat(dst, &st) == 0) bad =_ ("cannot move directory over file" ); else if (src_is_dir) { -int first =cache_name_pos (src, length), last; +int first =index_name_pos (&the_index, src, length), last;if (first >=0 ) prepare_move_submodule(src, first,
@@ -218,7 +218,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } argc += last - first; } - }else if (cache_name_pos (src, length) <0 ) + }else if (index_name_pos (&the_index, src, length) <0 ) bad =_ ("not under version control" );else if (lstat (dst, &st) ==0 && (!ignore_case ||strcasecmp (src, dst))) {
@@ -284,7 +284,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)if (mode ==WORKING_DIRECTORY )continue ; - pos =cache_name_pos (src,strlen (src)); + pos =index_name_pos (&the_index, src,strlen (src));assert (pos >=0 );if (!show_only)rename_cache_entry_at (pos, dst);
builtin/rm.c +2 -2
@@ -67,7 +67,7 @@ static void submodules_absorb_gitdir_if_needed(const char *prefix)int pos;const struct cache_entry *ce; - pos =cache_name_pos (name,strlen (name)); + pos =index_name_pos (&the_index, name,strlen (name));if (pos <0 ) { pos =get_ours_cache_pos (name, pos);if (pos <0 )
@@ -112,7 +112,7 @@ static int check_local_mod(struct object_id *head, int index_only)int local_changes =0 ;int staged_changes =0 ; - pos =cache_name_pos (name,strlen (name)); + pos =index_name_pos (&the_index, name,strlen (name));if (pos <0 ) {/* * Skip unmerged entries except for populated submodules
builtin/update-index.c +5 -5
@@ -225,7 +225,7 @@ static int test_if_untracked_cache_is_supported(void)static int mark_ce_flags (const char *path,int flag,int mark) {int namelen =strlen (path); -int pos =cache_name_pos (path, namelen); +int pos =index_name_pos (&the_index, path, namelen);if (0 <= pos) {if (mark) the_index.cache[pos]->ce_flags |= flag;
@@ -317,7 +317,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int lenstatic int process_directory (const char *path,int len,struct stat *st) {struct object_id oid; -int pos =cache_name_pos (path, len); +int pos =index_name_pos (&the_index, path, len);/* Exact match: file or existing gitlink */ if (pos >=0 ) {
@@ -368,7 +368,7 @@ static int process_path(const char *path)if (has_symlink_leading_path (path, len))return error ("'%s' is beyond a symbolic link" , path); - pos =cache_name_pos (path, len); + pos =index_name_pos (&the_index, path, len); ce = pos <0 ?NULL : the_index.cache[pos];if (ce &&ce_skip_worktree (ce)) {/*
@@ -428,7 +428,7 @@ static void chmod_path(char flip, const char *path)int pos;struct cache_entry *ce; - pos =cache_name_pos (path,strlen (path)); + pos =index_name_pos (&the_index, path,strlen (path));if (pos <0 ) goto fail; ce = the_index.cache[pos];
@@ -610,7 +610,7 @@ static int unresolve_one(const char *path)struct cache_entry *ce_2 =NULL , *ce_3 =NULL ;/* See if there is such entry in the index. */ - pos =cache_name_pos (path, namelen); + pos =index_name_pos (&the_index, path, namelen);if (0 <= pos) {/* already merged */ pos =unmerge_index_entry_at (&the_index, pos);
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define cache_name_pos (name, namelen) index_name_pos(&the_index,(name),(namelen))#define add_cache_entry (ce, option) add_index_entry(&the_index, (ce), (option))#define rename_cache_entry_at (pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))#define remove_cache_entry_at (pos) remove_index_entry_at(&the_index, (pos))
diff.c +1 -1
@@ -2759,7 +2759,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, intreturn 0 ; len =strlen (name); - pos =cache_name_pos (name, len); + pos =index_name_pos (&the_index, name, len);if (pos <0 )return 0 ; ce = the_index.cache[pos];
dir.c +4 -4
@@ -596,7 +596,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,void *data; len =strlen (path); - pos =cache_name_pos (path, len); + pos =index_name_pos (&the_index, path, len);if (pos <0 )return NULL ;if (!ce_skip_worktree (the_index.cache[pos]))
@@ -785,7 +785,7 @@ static int add_excludes(const char *fname, const char *base, int baselen, !match_stat_data_racy(&the_index, &sha1_stat->stat, &st)) ;/* no content change, ss->sha1 still good */ else if (check_index && - (pos = cache_name_pos(fname, strlen(fname))) >= 0 && + (pos = index_name_pos(&the_index, fname, strlen(fname))) >= 0 && !ce_stage (the_index.cache[pos]) &&ce_uptodate (the_index.cache[pos]) && !would_convert_to_git(fname))
@@ -1290,7 +1290,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)if (ignore_case)return directory_exists_in_index_icase (dirname, len); - pos =cache_name_pos (dirname, len); + pos =index_name_pos (&the_index, dirname, len);if (pos <0 ) pos = -pos-1 ;while (pos < the_index.cache_nr) {
@@ -1474,7 +1474,7 @@ static int get_index_dtype(const char *path, int len) }/* Try to look it up as a directory */ - pos =cache_name_pos (path, len); + pos =index_name_pos (&the_index, path, len);if (pos >=0 )return DT_UNKNOWN ; pos = -pos-1 ;
merge-recursive.c +2 -2
@@ -680,7 +680,7 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)strbuf_addstr (&dirpath, path);strbuf_addch (&dirpath,'/' ); - pos =cache_name_pos (dirpath.buf, dirpath.len); + pos =index_name_pos (&the_index, dirpath.buf, dirpath.len);if (pos <0 ) pos =-1 - pos;
@@ -697,7 +697,7 @@ static int dir_in_way(const char *path, int check_working_copy, int empty_ok)static int was_tracked (const char *path) { -int pos =cache_name_pos (path,strlen (path)); +int pos =index_name_pos (&the_index, path,strlen (path));if (0 <= pos)/* we have been tracking this path */
pathspec.c +1 -1
@@ -389,7 +389,7 @@ static const char *parse_element_magic(unsigned *magic, int *prefix_len,static void strip_submodule_slash_cheap (struct pathspec_item *item) {if (item->len >=1 && item->match[item->len -1 ] =='/' ) { -int i =cache_name_pos (item->match, item->len -1 ); +int i =index_name_pos (&the_index, item->match, item->len -1 );if (i >=0 &&S_ISGITLINK (the_index.cache[i]->ce_mode)) { item->len--;
rerere.c +1 -1
@@ -966,7 +966,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu* Reproduce the conflicted merge in-core */ len =strlen (path); - pos =cache_name_pos (path, len); + pos =index_name_pos (&the_index, path, len);if (0 <= pos)return -1 ; pos = -pos -1 ;
sha1_name.c +3 -3
@@ -1441,7 +1441,7 @@ static void diagnose_invalid_index_path(int stage, prefix ="" ;/* Wrong stage number? */ - pos =cache_name_pos (filename, namelen); + pos =index_name_pos (&the_index, filename, namelen);if (pos <0 ) pos = -pos -1 ;if (pos < the_index.cache_nr) {
@@ -1457,7 +1457,7 @@ static void diagnose_invalid_index_path(int stage,/* Confusion between relative and absolute filenames? */ strbuf_addstr (&fullname, prefix);strbuf_addstr (&fullname, filename); - pos =cache_name_pos (fullname.buf, fullname.len); + pos =index_name_pos (&the_index, fullname.buf, fullname.len);if (pos <0 ) pos = -pos -1 ;if (pos < the_index.cache_nr) {
@@ -1553,7 +1553,7 @@ static int get_sha1_with_context_1(const char *name,if (!the_index.cache)read_index (&the_index); - pos =cache_name_pos (cp, namelen); + pos =index_name_pos (&the_index, cp, namelen);if (pos <0 ) pos = -pos -1 ;while (pos < the_index.cache_nr) {
submodule.c +1 -1
@@ -179,7 +179,7 @@ void gitmodules_config(void)strbuf_addstr (&gitmodules_path,"/.gitmodules" );if (read_index (&the_index) <0 )die ("index file corrupt" ); - pos =cache_name_pos (".gitmodules" ,11 ); + pos =index_name_pos (&the_index,".gitmodules" ,11 );if (pos <0 ) {/* .gitmodules not found or isn't merged */ pos =-1 - pos;if (the_index.cache_nr > pos) {/* there is a .gitmodules */
wt-status.c +2 -2
@@ -481,7 +481,7 @@ static int unmerged_mask(const char *path)int pos, mask;const struct cache_entry *ce; - pos =cache_name_pos (path,strlen (path)); + pos =index_name_pos (&the_index, path,strlen (path));if (0 <= pos)return 0 ;
@@ -2096,7 +2096,7 @@ static void wt_porcelain_v2_print_unmerged_entry(*/ memset (stages,0 ,sizeof (stages)); sum =0 ; - pos =cache_name_pos (it->string,strlen (it->string)); + pos =index_name_pos (&the_index, it->string,strlen (it->string));assert (pos <0 ); pos = -pos-1 ;while (pos < the_index.cache_nr) {
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 22/24 cache.h: drop ce_modified
In reply to Stefan Beller--- builtin/ls-files.c | 2 +- cache.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
builtin/ls-files.c +1 -1
@@ -369,7 +369,7 @@ static void show_files(struct dir_struct *dir) err =lstat (ce->name, &st);if (show_deleted && err)show_ce_entry (tag_removed, ce); -if (show_modified &&ce_modified (ce, &st,0 )) +if (show_modified &&ie_modified (&the_index, ce, &st,0 ))show_ce_entry (tag_modified, ce); } }
cache.h +0 -1
@@ -355,7 +355,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS #define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) -#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options))#endif enum object_type {
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 20/24 cache.h: drop chmod_cache_entry
In reply to Stefan Beller--- builtin/add.c | 2 +- builtin/update-index.c | 2 +- cache.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)
builtin/add.c +1 -1
@@ -40,7 +40,7 @@ static void chmod_pathspec(struct pathspec *pathspec, int force_mode)if (pathspec && !ce_path_match (ce, pathspec,NULL ))continue ; -if (chmod_cache_entry (ce, force_mode) <0 ) +if (chmod_index_entry (&the_index, ce, force_mode) <0 )fprintf (stderr,"cannot chmod '%s'" , ce->name); } }
builtin/update-index.c +1 -1
@@ -432,7 +432,7 @@ static void chmod_path(char flip, const char *path)if (pos <0 ) goto fail; ce = the_index.cache[pos]; -if (chmod_cache_entry (ce, flip) <0 ) +if (chmod_index_entry (&the_index, ce, flip) <0 ) goto fail;report ("chmod %cx '%s'" , flip, path);
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define chmod_cache_entry (ce, flip) chmod_index_entry(&the_index, (ce), (flip))#define refresh_cache (flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options))
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 23/24 cache.h: drop ce_match_stat
In reply to Stefan Bellercoccinelle patch:
@@ expression ce, st, options; @@
-ce_match_stat(ce, st, options)
+ie_match_stat(&the_index, ce, st, options)
Additionally drop the define from cache.h manually.
Note that there is an empty define section in cache.h now. The cleanup of that is done in a later patch.
--- apply.c | 3 ++- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- cache.h | 1 - check-racy.c | 4 ++-- diff-lib.c | 2 +- diff.c | 2 +- entry.c | 3 ++- submodule.c | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-)
apply.c +2 -1
@@ -3364,7 +3364,8 @@ static int verify_index_match(const struct cache_entry *ce, struct stat *st)return -1 ;return 0 ; } -return ce_match_stat (ce, st,CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE ); +return ie_match_stat (&the_index, ce, st, +CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE ); }#define SUBMODULE_PATCH_WITHOUT_INDEX 1
builtin/rm.c +1 -1
@@ -163,7 +163,7 @@ static int check_local_mod(struct object_id *head, int index_only)* Is the index different from the file in the work tree? * If it's a submodule, is its work tree modified? */ - if (ce_match_stat(ce, &st, 0) || + if (ie_match_stat(&the_index, ce, &st, 0) || (S_ISGITLINK(ce->ce_mode) && bad_to_remove_submodule(ce->name, SUBMODULE_REMOVAL_DIE_ON_ERROR |
builtin/update-index.c +1 -1
@@ -268,7 +268,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int lenstruct cache_entry *ce;/* Was the old index entry already up-to-date? */ -if (old && !ce_stage (old) && !ce_match_stat (old, st,0 )) +if (old && !ce_stage (old) && !ie_match_stat (&the_index, old, st,0 ))return 0 ; size =cache_entry_size (len);
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))#endif enum object_type {
check-racy.c +2 -2
@@ -16,9 +16,9 @@ int main(int ac, char **av)continue ; } -if (ce_match_stat (ce, &st,0 )) +if (ie_match_stat (&the_index, ce, &st,0 )) dirty++; -else if (ce_match_stat (ce, &st,CE_MATCH_RACY_IS_DIRTY )) +else if (ie_match_stat (&the_index, ce, &st,CE_MATCH_RACY_IS_DIRTY )) racy++;else clean++;
diff-lib.c +1 -1
@@ -69,7 +69,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt, struct stat *st, unsigned ce_option, unsigned *dirty_submodule) { - int changed = ce_match_stat(ce, st, ce_option); + int changed = ie_match_stat(&the_index, ce, st, ce_option);if (S_ISGITLINK (ce->ce_mode)) {unsigned orig_flags = diffopt->flags;if (!DIFF_OPT_TST (diffopt,OVERRIDE_SUBMODULE_CONFIG ))
diff.c +1 -1
@@ -2782,7 +2782,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int* If ce matches the file in the work tree, we can reuse it. */ if (ce_uptodate (ce) || - (!lstat (name, &st) && !ce_match_stat (ce, &st,0 ))) + (!lstat (name, &st) && !ie_match_stat (&the_index, ce, &st,0 )))return 1 ;return 0 ;
entry.c +2 -1
@@ -266,7 +266,8 @@ int checkout_entry(struct cache_entry *ce,if (!check_path (path.buf, path.len, &st, state->base_dir_len)) {const struct submodule *sub; -unsigned changed =ce_match_stat (ce, &st,CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE ); +unsigned changed =ie_match_stat (&the_index, ce, &st, +CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE );/* * Needs to be checked before !changed returns early, * as the possibly empty directory was not changed
submodule.c +1 -1
@@ -191,7 +191,7 @@ void gitmodules_config(void) }else if (pos < the_index.cache_nr) {struct stat st;if (lstat (".gitmodules" , &st) ==0 && -ce_match_stat (the_index.cache[pos], &st,0 ) &DATA_CHANGED ) +ie_match_stat (&the_index, the_index.cache[pos], &st,0 ) &DATA_CHANGED ) gitmodules_is_modified =1 ; }
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 24/24 cache.h: retire NO_THE_INDEX_COMPATIBILITY_MACROS
In reply to Stefan BellerThe NO_THE_INDEX_COMPATIBILITY_MACROS pre processor setting was introduced in 4aab5b46f4 (Make read-cache.c "the_index" free., 2007-04-01), stating:
This makes all low-level functions defined in read-cache.c to take an explicit index_state structure as their first parameter, to specify which index to work on.
The reasoning is very vague, maybe indicating that having the index specified to work on is easier to for the new reader to understand what is going on.
All preceding patches worked on retiring functions that do not take an explicit index as to where to perform its work. Spelling out the reasons why we want to specify the index at each call:
1) Ease of understanding:
The recent patches dropped a lot of macros that may confuse new people diving into the code base.
2a) Spelling out global state explicitly:
Anything you do in submodule land today needs to spawn new processes in the submodule. This is cumbersome and not performant. So we may want to have an abstraction of a repo, i.e. all repository state in one struct. That way we can open a submodule in-process and perform the required actions without spawning a process. The road to this future is a long road, and we have to start somewhere. Exposing the global state seems like a good starter point.
2b) Spelling out global state explicitly (II): (Jeff Hostetler wrote)
In addition to (eventually) allowing multiple repos be open at the same time for submodules, it would also help with various multi-threading efforts. For example, we have loops that do a
"for (k = 0, k < active_nr; k++) {...}" There is no visual clue in that code that it references "the_index" and therefore should be subject to the same locking. Granted, this is a trivial example, but goes to the argument that the code has lots of subtle global variables and macros that make it difficult to reason about the code.
This step would help un-hide this.
--- attr.c | 1 - cache.h | 4 ---- name-hash.c | 1 - read-cache.c | 1 - unpack-trees.c | 1 - 5 files changed, 8 deletions(-)
attr.c +0 -1
@@ -7,7 +7,6 @@* an insanely large number of attributes. */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "exec_cmd.h" #include "attr.h"
cache.h +0 -4
@@ -352,10 +352,6 @@ extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);extern void remove_name_hash (struct index_state *istate,struct cache_entry *ce);extern void free_name_hash (struct index_state *istate); - -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#endif -enum object_type {OBJ_BAD =-1 ,OBJ_NONE =0 ,
name-hash.c +0 -1
@@ -5,7 +5,6 @@* * Copyright (C) 2008 Linus Torvalds */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" struct dir_entry {
read-cache.c +0 -1
@@ -3,7 +3,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "tempfile.h" #include "lockfile.h"
unpack-trees.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "dir.h" #include "tree.h"
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 21/24 cache.h: drop refresh_cache
In reply to Stefan Bellercoccinelle patch:
@@ expression flags; @@ -refresh_cache(flags) +refresh_index(&the_index, flags, NULL, NULL, NULL)
Additionally drop the define from cache.h manually.
This is a commit where I think the macro expansion is maybe silly, but for reasons outlined in the first patch of the series, we still follow through.
--- builtin/am.c | 4 ++-- builtin/checkout.c | 2 +- builtin/commit.c | 6 +++--- builtin/diff.c | 3 ++- builtin/merge.c | 8 ++++---- builtin/update-index.c | 3 ++- cache.h | 1 - merge.c | 2 +- wt-status.c | 2 +- 9 files changed, 16 insertions(+), 15 deletions(-)
builtin/am.c +2 -2
@@ -1122,7 +1122,7 @@ static void refresh_and_write_cache(void)struct lock_file *lock_file =xcalloc (1 ,sizeof (struct lock_file ));hold_locked_index (lock_file,LOCK_DIE_ON_ERROR ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (write_locked_index (&the_index, lock_file,COMMIT_LOCK ))die (_ ("unable to write index file" )); }
@@ -1977,7 +1977,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) lock_file =xcalloc (1 ,sizeof (struct lock_file ));hold_locked_index (lock_file,LOCK_DIE_ON_ERROR ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );memset (&opts,0 ,sizeof (opts)); opts.head_idx =1 ;
builtin/checkout.c +1 -1
@@ -509,7 +509,7 @@ static int merge_working_tree(const struct checkout_opts *opts,setup_unpack_trees_porcelain (&topts,"checkout" ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (unmerged_index (&the_index)) {error (_ ("you need to resolve your current index first" ));
builtin/commit.c +3 -3
@@ -328,7 +328,7 @@ static void refresh_cache_or_die(int refresh_flags)* refresh_flags contains REFRESH_QUIET, so the only errors * are for unmerged entries. */ -if (refresh_cache (refresh_flags |REFRESH_IN_PORCELAIN )) +if (refresh_index (&the_index, refresh_flags |REFRESH_IN_PORCELAIN ,NULL ,NULL ,NULL ))die_resolve_conflict ("commit" ); }
@@ -470,7 +470,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixhold_locked_index (&index_lock,LOCK_DIE_ON_ERROR );add_remove_files (&partial); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );update_main_cache_tree (WRITE_TREE_SILENT );if (write_locked_index (&the_index, &index_lock,CLOSE_LOCK ))die (_ ("unable to write new_index file" ));
@@ -482,7 +482,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefixcreate_base_index (current_head);add_remove_files (&partial); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (write_locked_index (&the_index, &false_lock,CLOSE_LOCK ))die (_ ("unable to write temporary index file" ));
builtin/diff.c +2 -1
@@ -211,7 +211,8 @@ static void refresh_index_quietly(void)return ;discard_index (&the_index);read_index (&the_index); -refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED ); +refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED ,NULL , +NULL ,NULL );update_index_if_able (&the_index, lock_file); }
builtin/merge.c +4 -4
@@ -324,7 +324,7 @@ static void restore_state(const struct object_id *head,run_command_v_opt (args,RUN_GIT_CMD );strbuf_release (&sb); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL ); }/* This is called when no merge was necessary. */
@@ -639,7 +639,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,const char *head_arg ="HEAD" ;hold_locked_index (&lock,LOCK_DIE_ON_ERROR ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));
@@ -786,7 +786,7 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)static struct lock_file lock;hold_locked_index (&lock,LOCK_DIE_ON_ERROR ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK ))return error (_ ("Unable to write index." ));
@@ -1393,7 +1393,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)* We are not doing octopus, not fast-forward, and have * only one common. */ -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (allow_trivial && fast_forward !=FF_ONLY ) {/* See if it is really trivial. */ git_committer_info (IDENT_STRICT );
builtin/update-index.c +2 -1
@@ -767,7 +767,8 @@ static int refresh(struct refresh_params *o, unsigned int flag) {setup_work_tree ();read_index_preload (&the_index,NULL ); - *o->has_errors |=refresh_cache (o->flags | flag); + *o->has_errors |=refresh_index (&the_index, o->flags | flag,NULL , +NULL ,NULL );return 0 ; }
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define refresh_cache (flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))#define ce_modified (ce, st, options) ie_modified(&the_index, (ce), (st), (options))#endif
merge.c +1 -1
@@ -55,7 +55,7 @@ int checkout_fast_forward(const unsigned char *head,struct dir_struct dir;struct lock_file *lock_file =xcalloc (1 ,sizeof (struct lock_file )); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (hold_locked_index (lock_file,LOCK_REPORT_ON_ERROR ) <0 )return -1 ;
wt-status.c +1 -1
@@ -2270,7 +2270,7 @@ int require_clean_work_tree(const char *action, const char *hint, int ignore_subint err =0 , fd; fd =hold_locked_index (lock_file,0 ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (0 <= fd)update_index_if_able (&the_index, lock_file);rollback_lock_file (lock_file);
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 19/24 cache.h: drop add_file_to_cache
In reply to Stefan Beller--- cache.h | 1 - rerere.c | 2 +- submodule.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-)
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define add_file_to_cache (path, flags) add_file_to_index(&the_index, (path), (flags))#define chmod_cache_entry (ce, flip) chmod_index_entry(&the_index, (ce), (flip))#define refresh_cache (flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)#define ce_match_stat (ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
rerere.c +1 -1
@@ -712,7 +712,7 @@ static void update_paths(struct string_list *update)for (i =0 ; i < update->nr; i++) {struct string_list_item *item = &update->items[i]; -if (add_file_to_cache (item->string,0 )) +if (add_file_to_index (&the_index, item->string,0 ))exit (128 );fprintf (stderr,"Staged '%s' using previous resolution.\n" , item->string);
submodule.c +1 -1
@@ -119,7 +119,7 @@ int remove_path_from_gitmodules(const char *path)void stage_updated_gitmodules (void ) { -if (add_file_to_cache (".gitmodules" ,0 )) +if (add_file_to_index (&the_index,".gitmodules" ,0 ))die (_ ("staging updated .gitmodules failed" )); }
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 18/24 cache.h: drop add_to_cache
In reply to Stefan Beller--- builtin/commit.c | 2 +- cache.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
builtin/commit.c +1 -1
@@ -287,7 +287,7 @@ static void add_remove_files(struct string_list *list)continue ;if (!lstat (p->string, &st)) { -if (add_to_cache (p->string, &st,0 )) +if (add_to_index (&the_index, p->string, &st,0 ))die (_ ("updating files failed" )); }else remove_file_from_index (&the_index, p->string);
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define add_to_cache (path, st, flags) add_to_index(&the_index, (path), (st), (flags))#define add_file_to_cache (path, flags) add_file_to_index(&the_index, (path), (flags))#define chmod_cache_entry (ce, flip) chmod_index_entry(&the_index, (ce), (flip))#define refresh_cache (flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 17/24 cache.h: drop remove_file_from_cache
In reply to Stefan Bellercoccinelle patch:
@@ expression path; @@
-remove_file_from_cache(path)
+remove_file_from_index(&the_index, path)
Additionally drop the define from cache.h manually.
--- apply.c | 4 ++-- builtin/commit.c | 2 +- builtin/reset.c | 2 +- builtin/rm.c | 2 +- builtin/update-index.c | 10 +++++----- cache.h | 1 - merge-recursive.c | 16 ++++++++-------- 7 files changed, 18 insertions(+), 19 deletions(-)
apply.c +2 -2
@@ -4230,7 +4230,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)static int remove_file (struct apply_state *state,struct patch *patch,int rmdir_empty) {if (state->update_index) { -if (remove_file_from_cache (patch->old_name) <0 ) +if (remove_file_from_index (&the_index, patch->old_name) <0 )return error (_ ("unable to remove %s from index" ), patch->old_name); }if (!state->cached) {
@@ -4418,7 +4418,7 @@ static int add_conflicted_stages_file(struct apply_state *state, ce_size =cache_entry_size (namelen); mode = patch->new_mode ? patch->new_mode : (S_IFREG |0644 ); -remove_file_from_cache (patch->new_name); +remove_file_from_index (&the_index, patch->new_name);for (stage =1 ; stage <4 ; stage++) {if (is_null_oid (&patch->threeway_stage[stage -1 ]))continue ;
builtin/commit.c +1 -1
@@ -290,7 +290,7 @@ static void add_remove_files(struct string_list *list)if (add_to_cache (p->string, &st,0 ))die (_ ("updating files failed" )); }else -remove_file_from_cache (p->string); +remove_file_from_index (&the_index, p->string); } }
builtin/reset.c +1 -1
@@ -125,7 +125,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,struct cache_entry *ce;if (is_missing && !intent_to_add) { -remove_file_from_cache (one->path); +remove_file_from_index (&the_index, one->path);continue ; }
builtin/rm.c +1 -1
@@ -343,7 +343,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)if (!quiet)printf ("rm '%s'\n" , path); -if (remove_file_from_cache (path)) +if (remove_file_from_index (&the_index, path))die (_ ("git rm: unable to remove %s" ), path); }
builtin/update-index.c +5 -5
@@ -243,7 +243,7 @@ static int remove_one_path(const char *path) {if (!allow_remove)return error ("%s: does not exist and --remove not passed" , path); -if (remove_file_from_cache (path)) +if (remove_file_from_index (&the_index, path))return error ("%s: cannot remove from the index" , path);return 0 ; }
@@ -376,7 +376,7 @@ static int process_path(const char *path)* so updating it does not make sense. * On the other hand, removing it from index should work */ -if (allow_remove &&remove_file_from_cache (path)) +if (allow_remove &&remove_file_from_index (&the_index, path))return error ("%s: cannot remove from the index" , path);return 0 ; }
@@ -459,7 +459,7 @@ static void update_one(const char *path) }if (force_remove) { -if (remove_file_from_cache (path)) +if (remove_file_from_index (&the_index, path))die ("git update-index: unable to remove %s" , path);report ("remove '%s'" , path);return ;
@@ -541,7 +541,7 @@ static void read_index_info(int nul_term_line)if (!mode) {/* mode == 0 means there is no such path -- remove */ -if (remove_file_from_cache (path_name)) +if (remove_file_from_index (&the_index, path_name))die ("git update-index: unable to remove %s" , ptr); }
@@ -658,7 +658,7 @@ static int unresolve_one(const char *path) goto free_return; } -remove_file_from_cache (path); +remove_file_from_index (&the_index, path);if (add_index_entry (&the_index, ce_2,ADD_CACHE_OK_TO_ADD )) {error ("%s: cannot add our version to the index." , path); ret =-1 ;
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define remove_file_from_cache (path) remove_file_from_index(&the_index, (path))#define add_to_cache (path, st, flags) add_to_index(&the_index, (path), (st), (flags))#define add_file_to_cache (path, flags) add_file_to_index(&the_index, (path), (flags))#define chmod_cache_entry (ce, flip) chmod_index_entry(&the_index, (ce), (flip))
merge-recursive.c +8 -8
@@ -582,7 +582,7 @@ static int update_stages(struct merge_options *opt, const char *path,int clear =1 ;int options =ADD_CACHE_OK_TO_ADD |ADD_CACHE_SKIP_DFCHECK ;if (clear) -if (remove_file_from_cache (path)) +if (remove_file_from_index (&the_index, path))return -1 ;if (o)if (add_cacheinfo (opt, o->mode, &o->oid, path,1 ,0 , options))
@@ -617,7 +617,7 @@ static int remove_file(struct merge_options *o, int clean,int update_working_directory = !o->call_depth && !no_wd;if (update_cache) { -if (remove_file_from_cache (path)) +if (remove_file_from_index (&the_index, path))return -1 ; }if (update_working_directory) {
@@ -1084,7 +1084,7 @@ static int handle_change_delete(struct merge_options *o,* correct; since there is no true "middle point" between * them, simply reuse the base version for virtual merge base. */ - ret =remove_file_from_cache (path); + ret =remove_file_from_index (&the_index, path);if (!ret) ret =update_file (o,0 , o_oid, o_mode, update_path); }else {
@@ -1145,7 +1145,7 @@ static int conflict_rename_delete(struct merge_options *o,return -1 ;if (o->call_depth) -return remove_file_from_cache (dest->path); +return remove_file_from_index (&the_index, dest->path);else return update_stages(o, dest->path, NULL, rename_branch == o->branch1 ? dest : NULL,
@@ -1263,14 +1263,14 @@ static int conflict_rename_rename_1to2(struct merge_options *o,return -1 ; }else -remove_file_from_cache (a->path); +remove_file_from_index (&the_index, a->path); add =filespec_from_entry (&other, ci->dst_entry2,3 ^1 );if (add) {if (update_file (o,0 , &add->oid, add->mode, b->path))return -1 ; }else -remove_file_from_cache (b->path); +remove_file_from_index (&the_index, b->path); }else if (handle_file (o, a,2 , ci) ||handle_file (o, b,3 , ci))return -1 ;
@@ -1759,7 +1759,7 @@ static int merge_content(struct merge_options *o,if (df_conflict_remains) {char *new_path;if (o->call_depth) { -remove_file_from_cache (path); +remove_file_from_index (&the_index, path); }else {if (!mfi.clean) {if (update_stages (o, path, &one, &a, &b))
@@ -1887,7 +1887,7 @@ static int process_entry(struct merge_options *o,if (update_file (o,0 , oid, mode, new_path)) clean_merge =-1 ;else if (o->call_depth) -remove_file_from_cache (path); +remove_file_from_index (&the_index, path);free (new_path); }else {output (o,2 ,_ ("Adding %s" ), path);
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 16/24 cache.h: drop rename_cache_entry_at
In reply to Stefan BellerOne define was unused, the other occurs just once. Easy patch.
--- builtin/mv.c | 2 +- cache.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-)
builtin/mv.c +1 -1
@@ -287,7 +287,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) pos =index_name_pos (&the_index, src,strlen (src));assert (pos >=0 );if (!show_only) -rename_cache_entry_at (pos, dst); +rename_index_entry_at (&the_index, pos, dst); }if (gitmodules_modified)
cache.h +0 -2
@@ -354,8 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define rename_cache_entry_at (pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name)) -#define remove_cache_entry_at (pos) remove_index_entry_at(&the_index, (pos))#define remove_file_from_cache (path) remove_file_from_index(&the_index, (path))#define add_to_cache (path, st, flags) add_to_index(&the_index, (path), (st), (flags))#define add_file_to_cache (path, flags) add_file_to_index(&the_index, (path), (flags))
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24
PATCH 15/24 cache.h: drop add_cache_entry
In reply to Stefan Bellercoccinelle patch
-add_cache_entry(ce, option)
+add_index_entry(&the_index, ce, option)
Additionally drop the define from cache.h manually.
--- apply.c | 4 ++-- builtin/blame.c | 3 ++- builtin/checkout.c | 3 ++- builtin/reset.c | 3 ++- builtin/update-index.c | 8 ++++---- cache.h | 1 - merge-recursive.c | 4 ++-- tree.c | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-)
apply.c +2 -2
@@ -4284,7 +4284,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list) "for newly created file %s"), path); } } -if (add_cache_entry (ce,ADD_CACHE_OK_TO_ADD ) <0 ) { +if (add_index_entry (&the_index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) {free (ce);return error (_ ("unable to add cache entry for %s" ), path); }
@@ -4428,7 +4428,7 @@ static int add_conflicted_stages_file(struct apply_state *state, ce->ce_flags =create_ce_flags (stage); ce->ce_namelen = namelen;oidcpy (&ce->oid, &patch->threeway_stage[stage -1 ]); -if (add_cache_entry (ce,ADD_CACHE_OK_TO_ADD ) <0 ) { +if (add_index_entry (&the_index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) {free (ce);return error (_ ("unable to add cache entry for %s" ), patch->new_name);
builtin/blame.c +2 -1
@@ -2413,7 +2413,8 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, ce->ce_flags =create_ce_flags (0 ); ce->ce_namelen = len; ce->ce_mode =create_ce_mode (mode); -add_cache_entry (ce,ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ); +add_index_entry (&the_index, ce, +ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE );cache_tree_invalidate_path (&the_index, path);
builtin/checkout.c +2 -1
@@ -118,7 +118,8 @@ static int update_some(const unsigned char *sha1, struct strbuf *base, } } -add_cache_entry (ce,ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ); +add_index_entry (&the_index, ce, +ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE );return 0 ; }
builtin/reset.c +2 -1
@@ -138,7 +138,8 @@ static void update_index_from_diff(struct diff_queue_struct *q, ce->ce_flags |=CE_INTENT_TO_ADD ;set_object_name_for_intent_to_add_entry (ce); } -add_cache_entry (ce,ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ); +add_index_entry (&the_index, ce, +ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE ); } }
builtin/update-index.c +4 -4
@@ -286,7 +286,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len } option = allow_add ?ADD_CACHE_OK_TO_ADD :0 ; option |= allow_replace ?ADD_CACHE_OK_TO_REPLACE :0 ; -if (add_cache_entry (ce, option)) +if (add_index_entry (&the_index, ce, option))return error ("%s: cannot add to the index - missing --add option?" , path);return 0 ; }
@@ -416,7 +416,7 @@ static int add_cacheinfo(unsigned int mode, const struct object_id *oid, ce->ce_flags |=CE_VALID ; option = allow_add ?ADD_CACHE_OK_TO_ADD :0 ; option |= allow_replace ?ADD_CACHE_OK_TO_REPLACE :0 ; -if (add_cache_entry (ce, option)) +if (add_index_entry (&the_index, ce, option))return error ("%s: cannot add to the index - missing --add option?" , path);report ("add '%s'" , path);
@@ -659,12 +659,12 @@ static int unresolve_one(const char *path) }remove_file_from_cache (path); -if (add_cache_entry (ce_2,ADD_CACHE_OK_TO_ADD )) { +if (add_index_entry (&the_index, ce_2,ADD_CACHE_OK_TO_ADD )) {error ("%s: cannot add our version to the index." , path); ret =-1 ; goto free_return; } -if (!add_cache_entry (ce_3,ADD_CACHE_OK_TO_ADD )) +if (!add_index_entry (&the_index, ce_3,ADD_CACHE_OK_TO_ADD ))return 0 ;error ("%s: cannot add their version to the index." , path); ret =-1 ;
cache.h +0 -1
@@ -354,7 +354,6 @@ extern void free_name_hash(struct index_state *istate);#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS -#define add_cache_entry (ce, option) add_index_entry(&the_index, (ce), (option))#define rename_cache_entry_at (pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))#define remove_cache_entry_at (pos) remove_index_entry_at(&the_index, (pos))#define remove_file_from_cache (path) remove_file_from_index(&the_index, (path))
merge-recursive.c +2 -2
@@ -230,7 +230,7 @@ static int add_cacheinfo(struct merge_options *o,if (!ce)return err (o,_ ("addinfo_cache failed for path '%s'" ), path); - ret =add_cache_entry (ce, options); + ret =add_index_entry (&the_index, ce, options);if (refresh) {struct cache_entry *nce;
@@ -238,7 +238,7 @@ static int add_cacheinfo(struct merge_options *o,if (!nce)return err (o,_ ("addinfo_cache failed for path '%s'" ), path);if (nce != ce) - ret =add_cache_entry (nce, options); + ret =add_index_entry (&the_index, nce, options); }return ret; }
tree.c +1 -1
@@ -27,7 +27,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int bmemcpy (ce->name, base, baselen);memcpy (ce->name + baselen, pathname, len+1 );hashcpy (ce->oid.hash, sha1); -return add_cache_entry (ce, opt); +return add_index_entry (&the_index, ce, opt); } static int read_one_entry(const unsigned char *sha1, struct strbuf *base,
Signature · 1 line
2.13.0.rc1.39.ga6db8bfa24