Kill the_index part 1, expose it
cover Kill the_index part 1, expose it
This is the beginning of the end of the_index. The problem with the_index is it lets library code anywhere access it freely. This is not good because from high level you may not realize that the_index is being used while you don't want to touch index at all, or you want to use a different index instead.
This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
This is the first part, which kills the use of index compat macros outside builtin/ and expose the_index in all library code. Later on we will ban the_index from one file each time until it's gone for good.
"struct index_state *" will be passed from builtin/ through the call chain to the function that needs it. In some cases, "struct repository *" will be passed instead when the whole operation spans more than just the index. By the end, the_index becomes part of "index compat macros" and cannot be used outside builtin/
Part one is mechanical conversion with the help of coccinelle. The only real patches are the first and the last one.
[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index
Nguyễn Thái Ngọc Duy (15):
contrib: add cocci script to replace index compat macros apply.c: stop using index compat macros blame.c: stop using index compat macros check-racy.c: stop using index compat macros diff-lib.c: stop using index compat macros diff.c: stop using index compat macros
entry.c: stop using index compat macros merge-recursive.c: stop using index compat macros merge.c: stop using index compat macros rerere.c: stop using index compat macros revision.c: stop using index compat macros sequencer.c: stop using index compat macros sha1-name.c: stop using index compat macros wt-status.c: stop using index compat macros cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
apply.c | 34 ++--- attr.c | 1 - blame.c | 19 +-- builtin/add.c | 1 + builtin/am.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/commit.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/fsck.c | 1 + builtin/ls-files.c | 1 - builtin/merge-index.c | 1 + builtin/merge-ours.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/reset.c | 1 + builtin/rev-parse.c | 1 + builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + builtin/update-index.c | 1 + cache.h | 2 +- check-racy.c | 10 +- contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++ convert.c | 1 - diff-lib.c | 8 +- diff.c | 12 +- dir.c | 1 - entry.c | 3 +- merge-recursive.c | 65 ++++----- merge.c | 14 +- name-hash.c | 1 - pathspec.c | 1 - read-cache.c | 1 - rerere.c | 36 ++--- revision.c | 14 +- sequencer.c | 32 ++--- sha1-name.c | 22 +-- submodule.c | 1 - t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-tool.h | 2 + tree.c | 1 - unpack-trees.c | 1 - wt-status.c | 24 ++-- 52 files changed, 363 insertions(+), 154 deletions(-) create mode 100644 contrib/coccinelle/index-compat.cocci
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 1/15 contrib: add cocci script to replace index compat macros
Index compat macros are going to be removed to expose the_index and then reorganized to use the right index instead of simply the_index because sometimes we want to use a different index.
This cocci script can help with the first step. It can be used later on on even builtin/ when we start to reorganize code in there, but for now this is the script that performs all the conversion outside builtin/
--- contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 contrib/coccinelle/index-compat.cocci
contrib/coccinelle/index-compat.cocci new file +184 -0
@@ -0,0 +1,184 @@ +@@ +@@ +-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 + +@@ +@@ +- read_cache() ++ read_index(&the_index) + +@@ +expression path; +@@ +- read_cache_from(path) ++ read_index_from(&the_index, path, get_git_dir()) + +@@ +expression pathspec; +@@ +- read_cache_preload(pathspec) ++ read_index_preload(&the_index, pathspec) + +@@ +@@ +- is_cache_unborn() ++ is_index_unborn(&the_index) + +@@ +@@ +- read_cache_unmerged() ++ read_index_unmerged(&the_index) + +@@ +@@ +- discard_cache() ++ discard_index(&the_index) + +@@ +@@ +- unmerged_cache() ++ unmerged_index(&the_index) + +@@ +expression name; +expression namelen; +@@ +- cache_name_pos(name, namelen) ++ index_name_pos(&the_index, name, namelen) + +@@ +expression ce; +expression option; +@@ +- add_cache_entry(ce, option) ++ add_index_entry(&the_index, ce, option) + +@@ +expression pos; +expression new_name; +@@ +- rename_cache_entry_at(pos, new_name) ++ rename_index_entry_at(&the_index, pos, new_name) + +@@ +expression pos; +@@ +- remove_cache_entry_at(pos) ++ remove_index_entry_at(&the_index, pos) + +@@ +expression path; +@@ +- remove_file_from_cache(path) ++ remove_file_from_index(&the_index, path) + +@@ +expression path; +expression st; +expression flags; +@@ +- add_to_cache(path, st, flags) ++ add_to_index(&the_index, path, st, flags) + +@@ +expression path; +expression flags; +@@ +- add_file_to_cache(path, flags) ++ add_file_to_index(&the_index, path, flags) + +@@ +expression ce; +expression flip; +@@ +-chmod_cache_entry(ce, flip) ++chmod_index_entry(&the_index, ce, flip) + +@@ +expression flags; +@@ +-refresh_cache(flags) ++refresh_index(&the_index, flags, NULL, NULL, NULL) + +@@ +expression ce; +expression st; +expression options; +@@ +-ce_match_stat(ce, st, options) ++ie_match_stat(&the_index, ce, st, options) + +@@ +expression ce; +expression st; +expression options; +@@ +-ce_modified(ce, st, options) ++ie_modified(&the_index, ce, st, options) + +@@ +expression name; +expression namelen; +@@ +-cache_dir_exists(name, namelen) ++index_dir_exists(&the_index, name, namelen) + +@@ +expression name; +expression namelen; +expression igncase; +@@ +-cache_file_exists(name, namelen, igncase) ++index_file_exists(&the_index, name, namelen, igncase) + +@@ +expression name; +expression namelen; +@@ +-cache_name_is_other(name, namelen) ++index_name_is_other(&the_index, name, namelen) + +@@ +@@ +-resolve_undo_clear() ++resolve_undo_clear_index(&the_index) + +@@ +expression at; +@@ +-unmerge_cache_entry_at(at) ++unmerge_index_entry_at(&the_index, at) + +@@ +expression pathspec; +@@ +-unmerge_cache(pathspec) ++unmerge_index(&the_index, pathspec) + +@@ +expression path; +expression sz; +@@ +-read_blob_data_from_cache(path, sz) ++read_blob_data_from_index(&the_index, path, sz)
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
Quoted 8 lines · Nguyễn Thái Ngọc Duy
Index compat macros are going to be removed to expose
the_indexand then reorganized to use the right index instead of simplythe_indexbecause sometimes we want to use a different index.This cocci script can help with the first step. It can be used later on on even builtin/ when we start to reorganize code in there, but for now this is the script that performs all the conversion outside builtin/
I pulled your code and ran make coccicheck and got quite a large patch as a result.
Perhaps reorder the commits in your large patch with this one at the end? It's helpful to see what your mechanical changes are going to be, but let's save it for when make coccicheck is stable.
Quoted 197 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- contrib/coccinelle/index-compat.cocci | 184 ++++++++++++++++++++++++++ 1 file changed, 184 insertions(+)create mode 100644
contrib/coccinelle/index-compat.coccicontrib/coccinelle/index-compat.cocci new file +184
-0@@ -0,0 +1,184 @@ +@@ +@@ +-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 + +@@ +@@ +- read_cache() ++ read_index(&the_index) + +@@ +expression path; +@@ +- read_cache_from(path) ++ read_index_from(&the_index, path, get_git_dir()) + +@@ +expression pathspec; +@@ +- read_cache_preload(pathspec) ++ read_index_preload(&the_index, pathspec) + +@@ +@@ +- is_cache_unborn() ++ is_index_unborn(&the_index) + +@@ +@@ +- read_cache_unmerged() ++ read_index_unmerged(&the_index) + +@@ +@@ +- discard_cache() ++ discard_index(&the_index) + +@@ +@@ +- unmerged_cache() ++ unmerged_index(&the_index) + +@@ +expression name; +expression namelen; +@@ +- cache_name_pos(name, namelen) ++ index_name_pos(&the_index, name, namelen) + +@@ +expression ce; +expression option; +@@ +- add_cache_entry(ce, option) ++ add_index_entry(&the_index, ce, option) + +@@ +expression pos; +expression new_name; +@@ +- rename_cache_entry_at(pos, new_name) ++ rename_index_entry_at(&the_index, pos, new_name) + +@@ +expression pos; +@@ +- remove_cache_entry_at(pos) ++ remove_index_entry_at(&the_index, pos) + +@@ +expression path; +@@ +- remove_file_from_cache(path) ++ remove_file_from_index(&the_index, path) + +@@ +expression path; +expression st; +expression flags; +@@ +- add_to_cache(path, st, flags) ++ add_to_index(&the_index, path, st, flags) + +@@ +expression path; +expression flags; +@@ +- add_file_to_cache(path, flags) ++ add_file_to_index(&the_index, path, flags) + +@@ +expression ce; +expression flip; +@@ +-chmod_cache_entry(ce, flip) ++chmod_index_entry(&the_index, ce, flip) + +@@ +expression flags; +@@ +-refresh_cache(flags) ++refresh_index(&the_index, flags, NULL, NULL, NULL) + +@@ +expression ce; +expression st; +expression options; +@@ +-ce_match_stat(ce, st, options) ++ie_match_stat(&the_index, ce, st, options) + +@@ +expression ce; +expression st; +expression options; +@@ +-ce_modified(ce, st, options) ++ie_modified(&the_index, ce, st, options) + +@@ +expression name; +expression namelen; +@@ +-cache_dir_exists(name, namelen) ++index_dir_exists(&the_index, name, namelen) + +@@ +expression name; +expression namelen; +expression igncase; +@@ +-cache_file_exists(name, namelen, igncase) ++index_file_exists(&the_index, name, namelen, igncase) + +@@ +expression name; +expression namelen; +@@ +-cache_name_is_other(name, namelen) ++index_name_is_other(&the_index, name, namelen) + +@@ +@@ +-resolve_undo_clear() ++resolve_undo_clear_index(&the_index) + +@@ +expression at; +@@ +-unmerge_cache_entry_at(at) ++unmerge_index_entry_at(&the_index, at) + +@@ +expression pathspec; +@@ +-unmerge_cache(pathspec) ++unmerge_index(&the_index, pathspec) + +@@ +expression path; +expression sz; +@@ +-read_blob_data_from_cache(path, sz) ++read_blob_data_from_index(&the_index, path, sz)
Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
Duy,
Here is the patch that was generated by make coccicheck.
Thanks,
-Stolee
-->8--
tmp/cocci-output-206193-4c91ec-add.c renamed from add.c +9 -8
@@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp {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 (&the_index, ce, pathspec,NULL ))continue ; -if (chmod_cache_entry (ce, flip) <0 ) +if (chmod_index_entry (&the_index, ce, flip) <0 )fprintf (stderr,"cannot chmod %cx '%s'\n" , flip, ce->name); } }
@@ -129,8 +129,8 @@ static int renormalize_tracked_files(con {int i, retval =0 ; -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 ;/* do not touch unmerged paths */
@@ -138,7 +138,8 @@ static int renormalize_tracked_files(concontinue ;/* do not touch non blobs */ if (pathspec && !ce_path_match (&the_index, ce, pathspec,NULL ))continue ; - retval |=add_file_to_cache (ce->name, flags |HASH_RENORMALIZE ); + retval |=add_file_to_index (&the_index, ce->name, + flags |HASH_RENORMALIZE ); }return retval;
@@ -230,7 +231,7 @@ static int edit_patch(int argc, const chgit_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, the_repository, prefix);
@@ -445,7 +446,7 @@ int cmd_add(int argc, const char **argv,return 0 ; } -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" ));die_in_unpopulated_submodule (&the_index, prefix);
tmp/cocci-output-206198-3fcbd5-am.c renamed from am.c +10 -10
@@ -1144,7 +1144,7 @@ static void refresh_and_write_cache(voidstruct lock_file lock_file =LOCK_INIT ;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" )); }
@@ -1505,8 +1505,8 @@ static int run_apply(const struct am_staif (index_file) {/* Reload index as apply_all_patches() will have modified it. */ -discard_cache (); -read_cache_from (index_file); +discard_index (&the_index); +read_index_from (&the_index, index_file,get_git_dir ()); }return 0 ;
@@ -1548,8 +1548,8 @@ static int fall_back_threeway(const struif (build_fake_ancestor (state, index_path))return error ("could not build fake ancestor" ); -discard_cache (); -read_cache_from (index_path); +discard_index (&the_index); +read_index_from (&the_index, index_path,get_git_dir ());if (write_index_as_tree (&orig_tree, &the_index, index_path,0 ,NULL ))return error (_ ("Repository lacks necessary blobs to fall back on 3-way merge." ));
@@ -1581,8 +1581,8 @@ static int fall_back_threeway(const strusay (state, stdout,_ ("Falling back to patching base and 3-way merge..." )); -discard_cache (); -read_cache (); +discard_index (&the_index); +read_index (&the_index);/* * This is not so wrong. Depending on which base we picked, orig_tree
@@ -1886,7 +1886,7 @@ static void am_resolve(struct am_state *die_user_resolve (state); } -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {printf_ln (_ ("You still have unmerged paths in your index.\n" "You should 'git add' each file with resolved conflicts to mark them as such.\n" "You might run `git rm` on a file to accept \"deleted by them\" for it." ));
@@ -1925,7 +1925,7 @@ static int fast_forward_to(struct tree *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 ;
@@ -2000,7 +2000,7 @@ static int clean_index(const struct objeif (!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 ;
tmp/cocci-output-206211-cd89a4-check-attr.c renamed from check-attr.c +1 -1
@@ -116,7 +116,7 @@ int cmd_check_attr(int argc, const char 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" ); }
tmp/cocci-output-206216-286c84-check-ignore.c renamed from check-ignore.c +1 -1
@@ -174,7 +174,7 @@ int cmd_check_ignore(int argc, const chadie (_ ("--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 ) +if (!no_index &&read_index (&the_index) <0 )die (_ ("index file corrupt" ));memset (&dir,0 ,sizeof (dir));
tmp/cocci-output-206223-d5d099-checkout-index.c renamed from checkout-index.c +6 -6
@@ -48,7 +48,7 @@ static void write_tempfile_record(conststatic 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 ;
@@ -56,8 +56,8 @@ static int checkout_file(const char *namif (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 ;
@@ -97,8 +97,8 @@ static void checkout_all(const char *preint 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 ;
@@ -185,7 +185,7 @@ int cmd_checkout_index(int argc, const cgit_config (git_default_config,NULL ); prefix_length = prefix ?strlen (prefix) :0 ; -if (read_cache () <0 ) { +if (read_index (&the_index) <0 ) {die ("invalid cache" ); }
tmp/cocci-output-206228-3a013e-checkout.c renamed from checkout.c +34 -32
172 lines not on this page · raw message
tmp/cocci-output-206233-6cec8a-clean.c renamed from clean.c +2 -2
@@ -955,7 +955,7 @@ int cmd_clean(int argc, const char **argif (remove_directories) dir.flags |=DIR_SHOW_IGNORED_TOO |DIR_KEEP_UNTRACKED_CONTENTS ; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" ));if (!ignored)
@@ -978,7 +978,7 @@ int cmd_clean(int argc, const char **argstruct 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)
tmp/cocci-output-206241-02f1a7-commit.c renamed from commit.c +24 -23
132 lines not on this page · raw message
tmp/cocci-output-206251-46b008-diff-files.c renamed from diff-files.c +1 -1
@@ -66,7 +66,7 @@ int cmd_diff_files(int argc, const char (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) rev.combine_merges = rev.dense_combined_merges = 1; -if (read_cache_preload (&rev.diffopt.pathspec) <0 ) { +if (read_index_preload (&the_index, &rev.diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
tmp/cocci-output-206256-83e320-diff-index.c renamed from diff-index.c +2 -2
@@ -48,11 +48,11 @@ int cmd_diff_index(int argc, const charusage (diff_cache_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (&rev.diffopt.pathspec) <0 ) { +if (read_index_preload (&the_index, &rev.diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; } - }else if (read_cache () <0 ) { + }else if (read_index (&the_index) <0 ) {perror ("read_cache" );return -1 ; }
tmp/cocci-output-206261-e5cd9c-diff-tree.c renamed from diff-tree.c +1 -1
@@ -111,7 +111,7 @@ int cmd_diff_tree(int argc, const char *git_config (git_diff_basic_config,NULL );/* no "diff" UI options */ init_revisions (opt, the_repository, prefix); -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); opt->abbrev =0 ; opt->diff =1 ;
tmp/cocci-output-206266-07f964-diff.c renamed from diff.c +7 -6
@@ -146,11 +146,11 @@ static int builtin_diff_index(struct revusage (builtin_diff_usage);if (!cached) {setup_work_tree (); -if (read_cache_preload (&revs->diffopt.pathspec) <0 ) { +if (read_index_preload (&the_index, &revs->diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; } - }else if (read_cache () <0 ) { + }else if (read_index (&the_index) <0 ) {perror ("read_cache" );return -1 ; }
@@ -211,9 +211,10 @@ static void refresh_index_quietly(void) fd =hold_locked_index (&lock_file,0 );if (fd <0 )return ; -discard_cache (); -read_cache (); -refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED ); +discard_index (&the_index); +read_index (&the_index); +refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED ,NULL , +NULL ,NULL );repo_update_index_if_able (the_repository, &lock_file); }
@@ -248,7 +249,7 @@ static int builtin_diff_files(struct rev revs->combine_merges = revs->dense_combined_merges =1 ;setup_work_tree (); -if (read_cache_preload (&revs->diffopt.pathspec) <0 ) { +if (read_index_preload (&the_index, &revs->diffopt.pathspec) <0 ) {perror ("read_cache_preload" );return -1 ; }
tmp/cocci-output-206277-317c6c-fsck.c renamed from fsck.c +7 -7
@@ -798,16 +798,16 @@ int cmd_fsck(int argc, const char **argvif (keep_cache_objects) { verify_index_checksum =1 ; verify_ce_order =1 ; -read_cache (); -for (i =0 ; i < active_nr; i++) { +read_index (&the_index); +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); + blob =lookup_blob (&the_index.cache[i]->oid);if (!blob)continue ; obj = &blob->object;
@@ -815,11 +815,11 @@ int cmd_fsck(int argc, const char **argvif (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 ();
tmp/cocci-output-206296-4e0c70-merge.c renamed from merge.c +9 -9
@@ -338,7 +338,7 @@ static void restore_state(const struct orun_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. */
@@ -630,7 +630,7 @@ static int read_tree_trivial(struct objeif (!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);
@@ -654,7 +654,7 @@ static int try_merge_strategy(const charconst 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 (write_locked_index (&the_index, &lock,COMMIT_LOCK |SKIP_IF_UNCHANGED ))return error (_ ("Unable to write index." ));
@@ -717,8 +717,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;
@@ -812,7 +812,7 @@ static int merge_trivial(struct commit *struct lock_file lock =LOCK_INIT ;hold_locked_index (&lock,LOCK_DIE_ON_ERROR ); -refresh_cache (REFRESH_QUIET ); +refresh_index (&the_index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (write_locked_index (&the_index, &lock,COMMIT_LOCK |SKIP_IF_UNCHANGED ))return error (_ ("Unable to write index." ));
@@ -1237,7 +1237,7 @@ int cmd_merge(int argc, const char **arg goto done; } -if (read_cache_unmerged ()) +if (read_index_unmerged (&the_index))die_resolve_conflict ("merge" );if (file_exists (git_path_merge_head ())) {
@@ -1258,7 +1258,7 @@ int cmd_merge(int argc, const char **argelse 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 ;
@@ -1458,7 +1458,7 @@ int cmd_merge(int argc, const char **arg* 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 );
tmp/cocci-output-206303-7bfaf2-merge-index.c renamed from merge-index.c +7 -7
@@ -13,11 +13,11 @@ static int merge_entry(int pos, const chchar 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))
@@ -27,7 +27,7 @@ static int merge_entry(int pos, const chxsnprintf (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);
@@ -45,7 +45,7 @@ static int merge_entry(int pos, const chstatic 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
@@ -58,8 +58,8 @@ static void merge_one_path(const char *pstatic 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 ;
@@ -78,7 +78,7 @@ int cmd_merge_index(int argc, const charif (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" )) {
tmp/cocci-output-206308-f9d113-merge-ours.c renamed from merge-ours.c +1 -1
@@ -25,7 +25,7 @@ int cmd_merge_ours(int argc, const char* commit. The index must match HEAD, or this merge cannot go * through. */ -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die_errno ("read_cache failed" );if (index_differs_from ("HEAD" ,NULL ,0 ))exit (2 );
tmp/cocci-output-206317-dcc551-mv.c renamed from mv.c +10 -10
@@ -79,7 +79,7 @@ static void prepare_move_submodule(const 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 (&the_index))die (_ ("Please stage your changes to .gitmodules or stash them to proceed" ));
@@ -98,13 +98,13 @@ static int index_range_of_same_dir(constconst 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); 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 ; }
@@ -141,7 +141,7 @@ int cmd_mv(int argc, const char **argv,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 );
@@ -189,7 +189,7 @@ int cmd_mv(int argc, const char **argv, && 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,
@@ -211,7 +211,7 @@ int cmd_mv(int argc, const char **argv, 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 );
@@ -220,7 +220,7 @@ int cmd_mv(int argc, const char **argv, } 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))) {
@@ -288,9 +288,9 @@ int cmd_mv(int argc, const char **argv,if (mode ==WORKING_DIRECTORY )continue ; - pos =cache_name_pos (src,strlen (src)); + pos =index_name_pos (&the_index, src,strlen (src));assert (pos >=0 ); -rename_cache_entry_at (pos, dst); +rename_index_entry_at (&the_index, pos, dst); }if (gitmodules_modified)
tmp/cocci-output-206330-aaaaf5-pull.c renamed from pull.c +2 -2
@@ -864,7 +864,7 @@ int cmd_pull(int argc, const char **argvif (opt_rebase <0 ) opt_rebase =config_get_rebase (); -if (read_cache_unmerged ()) +if (read_index_unmerged (&the_index))die_resolve_conflict ("pull" );if (file_exists (git_path_merge_head ()))
@@ -881,7 +881,7 @@ int cmd_pull(int argc, const char **argvif (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)
tmp/cocci-output-206336-40b38a-read-tree.c renamed from read-tree.c +4 -4
@@ -180,11 +180,11 @@ int cmd_read_tree(int argc, const char **/ 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 ; } -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);for (i =0 ; i < argc; i++) {const char *arg = argv[i];
@@ -220,7 +220,7 @@ int cmd_read_tree(int argc, const char *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 :
@@ -237,7 +237,7 @@ int cmd_read_tree(int argc, const char *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);
tmp/cocci-output-206350-640828-reset.c renamed from reset.c +6 -5
@@ -71,7 +71,7 @@ static int reset_index(const struct obje opts.reset =1 ; } -read_cache_unmerged (); +read_index_unmerged (&the_index);if (reset_type ==KEEP ) {struct object_id head_oid;
@@ -131,7 +131,7 @@ static void update_index_from_diff(strucstruct cache_entry *ce;if (is_missing && !intent_to_add) { -remove_file_from_cache (one->path); +remove_file_from_index (&the_index, one->path);continue ; }
@@ -144,7 +144,8 @@ static void update_index_from_diff(struc 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 ); } }
@@ -187,7 +188,7 @@ static void set_reflog_message(struct ststatic 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]));
@@ -239,7 +240,7 @@ static void parse_args(struct pathspec * } *rev_ret = rev; -if (read_cache () <0 ) +if (read_index (&the_index) <0 )die (_ ("index file corrupt" )); parse_pathspec(pathspec, 0,
tmp/cocci-output-206356-b7ba64-rev-parse.c renamed from rev-parse.c +1 -1
@@ -889,7 +889,7 @@ int cmd_rev_parse(int argc, const char *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 struct object_id *oid = &the_index.split_index->base_oid;
tmp/cocci-output-206362-a79cb3-rm.c renamed from rm.c +12 -12
@@ -32,8 +32,8 @@ static int get_ours_cache_pos(const char {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++; }
@@ -69,13 +69,13 @@ static void submodules_absorb_gitdir_if_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 )continue ; } - ce = active_cache[pos]; + ce = the_index.cache[pos]; if (!S_ISGITLINK(ce->ce_mode) || !file_exists(ce->name) ||
@@ -114,7 +114,7 @@ static int check_local_mod(struct objectint 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
@@ -124,11 +124,11 @@ static int check_local_mod(struct objectif (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 (!is_missing_file_error (errno))
@@ -165,7 +165,7 @@ static int check_local_mod(struct object* 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 |
@@ -267,7 +267,7 @@ int cmd_rm(int argc, const char **argv,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,
@@ -277,8 +277,8 @@ int cmd_rm(int argc, const char **argv, 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 (&the_index, ce, &pathspec, seen))continue ;ALLOC_GROW (list.entry, list.nr +1 , list.alloc);
@@ -342,7 +342,7 @@ int cmd_rm(int argc, const char **argv,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); }
tmp/cocci-output-206373-deb7ed-submodule--helper.c renamed from submodule--helper.c +5 -5
@@ -325,11 +325,11 @@ static int module_list_compute(int argc,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++) { -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(&the_index, pathspec, ce->name, ce_namelen(ce), 0, ps_matched, 1) ||
@@ -338,8 +338,8 @@ static int module_list_compute(int argc,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.
tmp/cocci-output-206382-a11b11-update-index.c renamed from update-index.c +44 -43
250 lines not on this page · raw message
tmp/cocci-output-206411-64fa0f-test-dump-untracked-cache.c renamed from helper/test-dump-untracked-cache.c +1 -1
@@ -48,7 +48,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) {
tmp/cocci-output-206428-a636a2-test-dump-cache-tree.c renamed from helper/test-dump-cache-tree.c +2 -2
@@ -60,10 +60,10 @@ int cmd__dump_cache_tree(int ac, const cstruct 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;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,"" ); }
tmp/cocci-output-206438-8b586f-test-lazy-init-name-hash.c renamed from helper/test-lazy-init-name-hash.c +10 -10
@@ -32,7 +32,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 {
@@ -53,7 +53,7 @@ static void dump_run(void) ce =hashmap_iter_next (&iter_cache); } -discard_cache (); +discard_index (&the_index); }/*
@@ -70,7 +70,7 @@ static uint64_t time_runs(int try_threadfor (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 ();
@@ -93,7 +93,7 @@ static uint64_t time_runs(int try_thread the_index.cache_nr);fflush (stdout); -discard_cache (); +discard_index (&the_index); } avg = sum / count;
@@ -117,9 +117,9 @@ static void analyze_run(void)int i;int nr; -read_cache (); +read_index (&the_index); cache_nr_limit = the_index.cache_nr; -discard_cache (); +discard_index (&the_index); nr = analyze;while (1 ) {
@@ -132,23 +132,23 @@ 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 ); t2s =getnanotime (); sum_single += (t2s - t1s); the_index.cache_nr = cache_nr_limit; -discard_cache (); +discard_index (&the_index); -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 ); 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",
tmp/cocci-output-206449-76a1d5-test-read-cache.c renamed from helper/test-read-cache.c +2 -2
@@ -8,8 +8,8 @@ int cmd__read_cache(int argc, const char cnt =strtol (argv[1 ],NULL ,0 );setup_git_directory ();for (i =0 ; i < cnt; i++) { -read_cache (); -discard_cache (); +read_index (&the_index); +discard_index (&the_index); }return 0 ; }
tmp/cocci-output-206458-4e21e5-test-scrap-cache-tree.c renamed from helper/test-scrap-cache-tree.c +2 -2
@@ -10,9 +10,9 @@ int cmd__scrap_cache_tree(int ac, constsetup_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 ; + the_index.cache_tree =NULL ;if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))die ("unable to write index file" );return 0 ;
tmp/cocci-output-206472-8a0fe8-test-write-cache.c renamed from helper/test-write-cache.c +1 -1
@@ -9,7 +9,7 @@ int cmd__write_cache(int argc, const chaif (argc ==2 ) cnt =strtol (argv[1 ],NULL ,0 );setup_git_directory (); -read_cache (); +read_index (&the_index);for (i =0 ; i < cnt; i++) {hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR );if (write_locked_index (&the_index, &index_lock,COMMIT_LOCK ))
Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
Quoted 11 lines · Derrick Stolee
Duy,
Here is the patch that was generated by
make coccicheck.Thanks,
-Stolee-->8--
---
builtin/add.c
Ah right. This is on purpose. I think I mentioned in the commit message that builtin/ is not touched. Do we run 'make coccicheck' automatically somewhere? If true, I need to move this script elsewhere because it's meant to run manually. You run it when you intend to do more manual fixups afterwards. For builtin/, I think I'll wait until 'struct repository *' conversion is complete then maybe fix them one by one.
Quoted 18 lines
+++
/tmp/cocci-output-206193-4c91ec-add.ctmp/cocci-output-206193-4c91ec-add.c renamed from add.c +3
-3@@ -38,13 +38,13 @@ static void chmod_pathspec(struct pathsp {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 (&the_index, ce, pathspec,NULL ))continue ; -if (chmod_cache_entry (ce, flip) <0 ) +if (chmod_index_entry (&the_index, ce, flip) <0 )fprintf (stderr,"cannot chmod %cx '%s'\n" , flip, ce->name); } }
Signature · 1 line
Duy
Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
Quoted 10 lines · Duy Nguyen
Quoted 9 lines · Derrick Stolee
Duy,
Here is the patch that was generated by
make coccicheck.Thanks,
-Stolee-->8--
Quoted 8 lines
Quoted 1 line
---
builtin/add.cAh right. This is on purpose. I think I mentioned in the commit message that builtin/ is not touched. Do we run 'make coccicheck' automatically somewhere? If true, I need to move this script elsewhere because it's meant to run manually. You run it when you intend to do more manual fixups afterwards. For builtin/, I think I'll wait until 'struct repository *' conversion is complete then maybe fix them one by one.
I don't think it is part of the CI runs, but some community members run this themselves on 'next' and 'master'.
I'm CC'ing Szeder, as he has contributed a fix to my own Coccinelle script [1].
[1] https://public-inbox.org/git/[email protected]/
[PATCH] coccinelle: avoid wrong transformation suggestions from commit.cocci
Re: [PATCH 01/15] contrib: add cocci script to replace index compat macros
Quoted 10 lines · Derrick Stolee
Quoted 6 lines · Duy Nguyen
Do we run 'make coccicheck'
automatically somewhere? If true, I need to move this script elsewhere because it's meant to run manually. You run it when you intend to do more manual fixups afterwards. For builtin/, I think I'll wait until 'struct repository *' conversion is complete then maybe fix them one by one.
Quoted 2 lines
I don't think it is part of the CI runs, but some community members run this themselves on 'next' and 'master'.
Travis CI does run 'make coccicheck' already, that's the "StaticAnalysis" build job.
Alas, it's not particularly useful as it is, because Coccinelle's and in turn 'make coccicheck's exit code only indicates that Coccinelle managed to finish its analysis without any errors (e.g. no unknown --options, no missing files, no syntax errors in the semantic patches, etc.), but it doesn't indicate whether it found any undesired code patterns to transform or not.
I have been sitting on two patches implementing two different approaches to improve this situation for several months now (sorry :) I think I'll just pick the shorter-simpler of the two, and submit it shortly.
PATCH 2/15 apply.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- apply.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
apply.c +19 -15
@@ -3378,7 +3378,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
@@ -3511,10 +3512,10 @@ static int load_current(struct apply_state *state,if (!patch->is_new)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 = active_cache[pos]; + ce = the_index.cache[pos];if (lstat (name, &st)) {if (errno !=ENOENT )return error_errno ("%s" , name);
@@ -3680,13 +3681,14 @@ 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;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 ;
@@ -3735,7 +3737,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)
@@ -3824,7 +3826,8 @@ 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 {
@@ -3999,9 +4002,10 @@ 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, +get_git_dir ());else -return read_cache (); +return read_index (&the_index); }/* This function tries to read the object name from the current index */
@@ -4012,10 +4016,10 @@ 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, &active_cache[pos]->oid); +oidcpy (oid, &the_index.cache[pos]->oid);return 0 ; }
@@ -4243,7 +4247,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)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) {
@@ -4297,7 +4301,7 @@ static int add_index_file(struct apply_state *state, "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); }
@@ -4431,7 +4435,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 ;
@@ -4441,7 +4445,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);
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
Re: [PATCH 02/15] apply.c: stop using index compat macros
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- apply.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)
Until all the codepaths that reach these callsites to index_* functions from cmd_main() are converted to pass "struct index_state *" throughout, a step like this patch does fundamentally changes nothing. The only two issues worth addressing in this area still remain. All the lines we see here still depend on the existence of "the_index" instance, and they can only operate on that single "the_index" instance and nothing else.
It is true that the dependency has been made more explicit, but it already is explicit (to see them you just say "no-the-index-macros" and see what fails to compile).
I see others are enthused with this series, but seeing the changes like these I am not all that impressed.
Would it become hard to review if we combine this step *and* the next logical step (i.e. pass the "struct index_state" throughout the callflow) into a single patch? The functions in apply.c are fairly well isolated and there won't be all that heavy interaction with the outside world if we convert this file (and it alone) without touchning the other files. If a division in that direction is possible, it may make a better orgainzation (i.e. instead of doing whole-tree superficial conversion that needs to be fixed up again later, do a deep full conversion on selected files before going on to next set of files).
Re: [PATCH 02/15] apply.c: stop using index compat macros
Quoted 15 lines · Junio C Hamano
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- apply.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-)Until all the codepaths that reach these callsites to index_* functions from
cmd_main()are converted to pass "structindex_state*" throughout, a step like this patch does fundamentally changes nothing. The only two issues worth addressing in this area still remain. All the lines we see here still depend on the existence of "the_index" instance, and they can only operate on that single "the_index" instance and nothing else.
Quoted 6 lines
It is true that the dependency has been made more explicit, but it already is explicit (to see them you just say "no-the-index-macros" and see what fails to compile).
I see others are enthused with this series, but seeing the changes like these I am not all that impressed.
I agree there is nothing to be impressed about these patches. These, standalone, are worthless changes. I would not do this if I could not delete all these the_index by the end. The changes are separated this way in order to reduce diff noise (indentation, function name changes) in later patches.
Quoted 7 lines
Would it become hard to review if we combine this step *and* the next logical step (i.e. pass the "struct
index_state" throughout the callflow) into a single patch? The functions inapply.care fairly well isolated and there won't be all that heavy interaction with the outside world if we convert this file (and it alone) without touchning the other files.
A singe patch conversion would look like below. But for that to happen, convert.c, rerere, ws.c and read-cache.c have to be converted first to not use the_index. A single patch to convert apply.c probably pulls a lot more outside changes than just apply.c
Quoted 4 lines
If a division in that direction is possible, it may make a better orgainzation (i.e. instead of doing whole-tree superficial conversion that needs to be fixed up again later, do a deep full conversion on selected files before going on to next set of files).
I think that's the direction in the following patches, where I try to kick the_index out of one file each time until they are gone.
I'm ok with dropping these patches and incorporate them in the "real conversion" patches too. Let me know which way you want.
Anyway the "everything in apply.c" patch would look like this, which is a combined patch of the following commits on my branch [1]
18d1848077 read-cache.c: kill read_index()e8445d01a5 repository.c: replace hold_locked_index() with repo_hold_locked_index() cc970ac179 ws.c: remove implicit dependency on the_indexb8a14120c4 rerere.c: remove implicit dependency on the_index 6b68ac65dc ll-merge.c: remove implicit dependency on the_index 5d990e1b71 apply.c: use apply_state->repo->index instead of the_index cb3f1ad8e8 apply.c: make init_apply_state() take a struct repository a0bcf49024 apply.c: pass struct apply_state to more functions 4265838aec apply.c: use the right index instead of the_index 4fbbdbca80 read-cache.c: remove an implicit dependency on the_index ef8bd1e81d convert.c: remove an implicit dependency on the_index
[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index
-- 8< --
apply.c +48 -36
@@ -75,10 +75,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state, }int init_apply_state (struct apply_state *state, +struct repository *repo,const char *prefix) {memset (state,0 ,sizeof (*state)); state->prefix = prefix; + state->repo = repo; state->apply =1 ; state->line_termination ='\n' ; state->p_value =1 ;
@@ -2126,10 +2128,12 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long siif (!use_patch (state, patch)) patch->ws_rule =0 ; +else if (patch->new_name) + patch->ws_rule =whitespace_rule (state->repo->index, + patch->new_name);else - patch->ws_rule =whitespace_rule (patch->new_name - ? patch->new_name - : patch->old_name); + patch->ws_rule =whitespace_rule (state->repo->index, + patch->old_name); patchsize = parse_single_patch(state, buffer + offset + hdrsize,
@@ -3371,14 +3375,16 @@ static struct patch *previous_patch(struct apply_state *state,return previous; } -static int verify_index_match (const struct cache_entry *ce,struct stat *st) +static int verify_index_match (struct apply_state *state, +const struct cache_entry *ce, +struct stat *st) {if (S_ISGITLINK (ce->ce_mode)) {if (!S_ISDIR (st->st_mode))return -1 ;return 0 ; } -return ie_match_stat (&the_index, ce, st, +return ie_match_stat (state->repo->index, ce, st,CE_MATCH_IGNORE_VALID |CE_MATCH_IGNORE_SKIP_WORKTREE ); }
@@ -3460,7 +3466,8 @@ static int load_preimage(struct apply_state *state,return 0 ; } -static int three_way_merge(struct image *image, +static int three_way_merge(struct apply_state *state, + struct image *image, char *path, const struct object_id *base, const struct object_id *ours,
@@ -3476,7 +3483,9 @@ static int three_way_merge(struct image *image, status =ll_merge (&result, path, &base_file,"base" , &our_file,"ours" , - &their_file,"theirs" ,NULL ); + &their_file,"theirs" , + state->repo->index, +NULL );free (base_file.ptr);free (our_file.ptr);free (their_file.ptr);
@@ -3512,17 +3521,17 @@ static int load_current(struct apply_state *state,if (!patch->is_new)BUG ("patch to %s is not a creation" , patch->old_name); - pos =index_name_pos (&the_index, name,strlen (name)); + pos =index_name_pos (state->repo->index, name,strlen (name));if (pos <0 )return error (_ ("%s: does not exist in index" ), name); - ce = the_index.cache[pos]; + ce = state->repo->index->cache[pos];if (lstat (name, &st)) {if (errno !=ENOENT )return error_errno ("%s" , name); -if (checkout_target (&the_index, ce, &st)) +if (checkout_target (state->repo->index, ce, &st))return -1 ; } -if (verify_index_match (ce, &st)) +if (verify_index_match (state, ce, &st))return error (_ ("%s: does not match index" ), name); status =load_patch_target (state, &buf, ce, &st, patch, name, mode);
@@ -3588,7 +3597,7 @@ static int try_threeway(struct apply_state *state,clear_image (&tmp_image);/* in-core three-way merge between post and our using pre as base */ - status =three_way_merge (image, patch->new_name, + status =three_way_merge (state, image, patch->new_name, &pre_oid, &our_oid, &post_oid);if (status <0 ) {if (state->apply_verbosity > verbosity_silent)
@@ -3681,19 +3690,19 @@ static int check_preimage(struct apply_state *state, }if (state->check_index && !previous) { -int pos =index_name_pos (&the_index, old_name, +int pos =index_name_pos (state->repo->index, old_name,strlen (old_name));if (pos <0 ) {if (patch->is_new <0 ) goto is_new;return error (_ ("%s: does not exist in index" ), old_name); } - *ce = the_index.cache[pos]; + *ce = state->repo->index->cache[pos];if (stat_ret <0 ) { -if (checkout_target (&the_index, *ce, st)) +if (checkout_target (state->repo->index, *ce, st))return -1 ; } -if (!state->cached &&verify_index_match (*ce, st)) +if (!state->cached &&verify_index_match (state, *ce, st))return error (_ ("%s: does not match index" ), old_name);if (state->cached) st_mode = (*ce)->ce_mode;
@@ -3737,7 +3746,7 @@ static int check_to_create(struct apply_state *state,struct stat nst;if (state->check_index && -index_name_pos (&the_index, new_name,strlen (new_name)) >=0 && +index_name_pos (state->repo->index, new_name,strlen (new_name)) >=0 && !ok_if_exists)return EXISTS_IN_INDEX ;if (state->cached)
@@ -3826,7 +3835,7 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *naif (state->check_index) {struct cache_entry *ce; - ce =index_file_exists (&the_index, name->buf, + ce =index_file_exists (state->repo->index, name->buf, name->len, ignore_case);if (ce &&S_ISLNK (ce->ce_mode))return 1 ;
@@ -4002,10 +4011,10 @@ 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_index_from (&the_index, state->index_file, +return read_index_from (state->repo->index, state->index_file,get_git_dir ());else -return read_index (&the_index); +return repo_read_index (state->repo); }/* This function tries to read the object name from the current index */
@@ -4016,10 +4025,10 @@ static int get_current_oid(struct apply_state *state, const char *path,if (read_apply_cache (state) <0 )return -1 ; - pos =index_name_pos (&the_index, path,strlen (path)); + pos =index_name_pos (state->repo->index, path,strlen (path));if (pos <0 )return -1 ; -oidcpy (oid, &the_index.cache[pos]->oid); +oidcpy (oid, &state->repo->index->cache[pos]->oid);return 0 ; }
@@ -4094,9 +4103,9 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)return error (_ ("sha1 information is lacking or useless " "(%s)." ), name); - ce =make_cache_entry (patch->old_mode, oid.hash, name,0 ,0 ); + ce =make_index_entry (&result, patch->old_mode, oid.hash, name,0 ,0 );if (!ce) -return error (_ ("make_cache_entry failed for path '%s'" ), +return error (_ ("make_index_entry failed for path '%s'" ), name);if (add_index_entry (&result, ce,ADD_CACHE_OK_TO_ADD )) {free (ce);
@@ -4247,7 +4256,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)static int remove_file (struct apply_state *state,struct patch *patch,int rmdir_empty) {if (state->update_index) { -if (remove_file_from_index (&the_index, patch->old_name) <0 ) +if (remove_file_from_index (state->repo->index, patch->old_name) <0 )return error (_ ("unable to remove %s from index" ), patch->old_name); }if (!state->cached) {
@@ -4301,7 +4310,7 @@ static int add_index_file(struct apply_state *state, "for newly created file %s"), path); } } -if (add_index_entry (&the_index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) { +if (add_index_entry (state->repo->index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) {free (ce);return error (_ ("unable to add cache entry for %s" ), path); }
@@ -4315,7 +4324,9 @@ static int add_index_file(struct apply_state *state,* 0 if everything went well * 1 if a recoverable error happened */ -static int try_create_file (const char *path,unsigned int mode,const char *buf,unsigned long size) +static int try_create_file (struct apply_state *state,const char *path, +unsigned int mode,const char *buf, +unsigned long size) {int fd, res;struct strbuf nbuf =STRBUF_INIT ;
@@ -4337,7 +4348,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,if (fd <0 )return 1 ; -if (convert_to_working_tree (path, buf, size, &nbuf)) { +if (convert_to_working_tree (state->repo->index, path, buf, size, &nbuf)) { size = nbuf.len; buf = nbuf.buf; }
@@ -4373,7 +4384,7 @@ static int create_one_file(struct apply_state *state,if (state->cached)return 0 ; - res =try_create_file (path, mode, buf, size); + res =try_create_file (state, path, mode, buf, size);if (res <0 )return -1 ;if (!res)
@@ -4382,7 +4393,7 @@ static int create_one_file(struct apply_state *state,if (errno ==ENOENT ) {if (safe_create_leading_directories (path))return 0 ; - res =try_create_file (path, mode, buf, size); + res =try_create_file (state, path, mode, buf, size);if (res <0 )return -1 ;if (!res)
@@ -4404,7 +4415,7 @@ static int create_one_file(struct apply_state *state,for (;;) {char newpath[PATH_MAX ];mksnpath (newpath,sizeof (newpath),"%s~%u" , path, nr); - res =try_create_file (newpath, mode, buf, size); + res =try_create_file (state, newpath, mode, buf, size);if (res <0 )return -1 ;if (!res) {
@@ -4435,7 +4446,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_index (&the_index, patch->new_name); +remove_file_from_index (state->repo->index, patch->new_name);for (stage =1 ; stage <4 ; stage++) {if (is_null_oid (&patch->threeway_stage[stage -1 ]))continue ;
@@ -4445,7 +4456,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_index_entry (&the_index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) { +if (add_index_entry (state->repo->index, ce,ADD_CACHE_OK_TO_ADD ) <0 ) {free (ce);return error (_ ("unable to add cache entry for %s" ), patch->new_name);
@@ -4619,7 +4630,7 @@ static int write_out_results(struct apply_state *state, struct patch *list) }string_list_clear (&cpath,0 ); -rerere (0 ); +rerere (state->repo,0 ); }return errs;
@@ -4697,7 +4708,8 @@ static int apply_patch(struct apply_state *state, state->index_file, LOCK_DIE_ON_ERROR); else - hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR); + repo_hold_locked_index(state->repo, &state->lock_file, +LOCK_DIE_ON_ERROR ); }if (state->check_index &&read_apply_cache (state) <0 ) {
@@ -4893,7 +4905,7 @@ int apply_all_patches(struct apply_state *state, }if (state->update_index) { - res =write_locked_index (&the_index, &state->lock_file,COMMIT_LOCK ); + res =write_locked_index (state->repo->index, &state->lock_file,COMMIT_LOCK );if (res) {error (_ ("Unable to write new index file" )); res =-128 ;
-- 8< --
Re: [PATCH 02/15] apply.c: stop using index compat macros
Quoted 3 lines · Duy Nguyen
A singe patch conversion would look like below. But for that to happen,
convert.c, rerere,ws.candread-cache.chave to be converted first to not usethe_index.
Yes, that was pretty much what I was driving at. I do not have any trouble seeing a patch that converts callees that are deep in the callchain and are meant to serve helpers to make them capable of working on arbitrary in-core index instance. That's a welcome change that allows us to reuse them in more context (namely, by callers that want to work on istate that is not the_index themselves). Skipping the "intermediate" step like this patch would force us to focus on converting these lower-layer dependencies.
Re: [PATCH 02/15] apply.c: stop using index compat macros
Quoted 7 lines · Junio C Hamano
Quoted 3 lines · Duy Nguyen
A singe patch conversion would look like below. But for that to happen,
convert.c, rerere,ws.candread-cache.chave to be converted first to not usethe_index.
Quoted 8 lines
Yes, that was pretty much what I was driving at. I do not have any trouble seeing a patch that converts callees that are deep in the callchain and are meant to serve helpers to make them capable of working on arbitrary in-core index instance. That's a welcome change that allows us to reuse them in more context (namely, by callers that want to work on istate that is not
the_indexthemselves). Skipping the "intermediate" step like this patch would force us to focus on converting these lower-layer dependencies.
OK I'll drop part one and incorporate the changes in later patches.
Signature · 1 line
Duy
PATCH 3/15 blame.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- blame.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
blame.c +10 -9
@@ -85,11 +85,11 @@ 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 < 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);
@@ -159,7 +159,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 ;
@@ -240,14 +240,14 @@ 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 (); -read_cache (); +discard_index (&the_index); +read_index (&the_index); 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 = 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 ;
@@ -259,7 +259,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);
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 4/15 check-racy.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- check-racy.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
check-racy.c +5 -5
@@ -6,9 +6,9 @@ int main(int ac, char **av)int dirty, clean, racy; dirty = clean = racy =0 ; -read_cache (); -for (i =0 ; i < active_nr; i++) { -struct cache_entry *ce = active_cache[i]; +read_index (&the_index); +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)) {
@@ -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++;
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 5/15 diff-lib.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- diff-lib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff-lib.c +4 -4
@@ -70,7 +70,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)) {struct diff_flags orig_flags = diffopt->flags;if (!diffopt->flags.override_submodule_config)
@@ -98,10 +98,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 struct object_id *old_oid, *new_oid;
@@ -145,7 +145,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))
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 6/15 diff.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- diff.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff.c +6 -6
@@ -3460,7 +3460,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in* 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
@@ -3483,10 +3483,10 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, inreturn 0 ; len =strlen (name); - pos =cache_name_pos (name, len); + pos =index_name_pos (&the_index, 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
@@ -3506,7 +3506,7 @@ static int reuse_worktree_file(const char *name, const struct object_id *oid, in* 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 ;
@@ -4216,14 +4216,14 @@ 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 * when it fails, so we do not have to worry about * cleaning it up ourselves either. */ -read_cache (); +read_index (&the_index); }if (hexsz < options->abbrev) options->abbrev = hexsz;/* full */
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 7/15 entry.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- entry.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
entry.c +2 -1
@@ -421,7 +421,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
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 8/15 merge-recursive.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- merge-recursive.c | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-)
merge-recursive.c +33 -32
@@ -319,7 +319,7 @@ static int add_cacheinfo(struct merge_options *o,if (!ce)return err (o,_ ("add_cacheinfo failed for path '%s'; merge aborting." ), path); - ret =add_cache_entry (ce, options); + ret =add_index_entry (&the_index, ce, options);if (refresh) {struct cache_entry *nce;
@@ -327,7 +327,7 @@ static int add_cacheinfo(struct merge_options *o,if (!nce)return err (o,_ ("add_cacheinfo failed to refresh for path '%s'; merge aborting." ), path);if (nce != ce) - ret =add_cache_entry (nce, options); + ret =add_index_entry (&the_index, nce, options); }return ret; }
@@ -365,7 +365,7 @@ static int unpack_trees_start(struct merge_options *o,init_tree_desc_from_tree (t+2 , merge); rc =unpack_trees (3 , t, &o->unpack_opts); -cache_tree_free (&active_cache_tree); +cache_tree_free (&the_index.cache_tree);/* * Update the_index to match the new results, AFTER saving a copy
@@ -390,11 +390,11 @@ 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 < 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);
@@ -402,16 +402,16 @@ struct tree *write_tree_from_memory(struct merge_options *o)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->oid); + result =lookup_tree (&the_index.cache_tree->oid);return result; }
@@ -488,10 +488,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 ;
@@ -651,7 +651,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))
@@ -707,13 +707,14 @@ 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) {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 &&strcmp (path, ce->name))return 0 ; }
@@ -772,12 +773,12 @@ 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; -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 ; }
@@ -839,19 +840,19 @@ static int would_lose_untracked(const char *path)* update_file()/would_lose_untracked(); see every comment in this * file which mentions "update_stages". */ -int pos =cache_name_pos (path,strlen (path)); +int pos =index_name_pos (&the_index, path,strlen (path));if (pos <0 ) pos =-1 - pos; -while (pos < active_nr && - !strcmp (path, active_cache[pos]->name)) { +while (pos < the_index.cache_nr && + !strcmp (path, the_index.cache[pos]->name)) {/* * If stage #0, it is definitely tracked. * If it has stage #2 then it was tracked * before this merge started. All other * cases the path was not tracked. */ -switch (ce_stage (active_cache[pos])) { +switch (ce_stage (the_index.cache[pos])) {case 0 :case 2 :return 0 ;
@@ -1466,7 +1467,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 {
@@ -1527,7 +1528,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,
@@ -1662,14 +1663,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 ;
@@ -3063,7 +3064,7 @@ static int merge_content(struct merge_options *o,if (df_conflict_remains || is_dirty) {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))
@@ -3220,7 +3221,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);
@@ -3284,7 +3285,7 @@ int merge_trees(struct merge_options *o,return -1 ; } -if (unmerged_cache ()) { +if (unmerged_index (&the_index)) {struct string_list *entries;struct rename_info re_info;int i;
@@ -3415,7 +3416,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" ;
@@ -3431,9 +3432,9 @@ 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_cache (); +read_index (&the_index); o->ancestor ="merged common ancestors" ; clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 9/15 merge.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- merge.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
merge.c +7 -7
@@ -36,12 +36,12 @@ int index_has_changes(struct strbuf *sb)diff_flush (&opt);return opt.flags.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; } }
@@ -66,10 +66,10 @@ 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 (); -if (read_cache () <0 ) +discard_index (&the_index); +if (read_index (&the_index) <0 )die (_ ("failed to read the cache" )); -resolve_undo_clear (); +resolve_undo_clear_index (&the_index);return ret; }
@@ -85,7 +85,7 @@ int checkout_fast_forward(const struct object_id *head,struct dir_struct dir;struct lock_file lock_file =LOCK_INIT ; -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 ;
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 10/15 rerere.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- rerere.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
rerere.c +18 -18
@@ -524,7 +524,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 ;
@@ -532,13 +532,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) &&
@@ -548,7 +548,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; }
@@ -567,12 +567,12 @@ 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;) { +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);
@@ -600,12 +600,12 @@ 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;) { +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);
@@ -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);
@@ -964,16 +964,16 @@ 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 ; -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 ;
@@ -1102,7 +1102,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 );
@@ -1114,7 +1114,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.18.0.rc0.333.g22e6ee6cdf
PATCH 11/15 revision.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- revision.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
revision.c +7 -7
@@ -1354,7 +1354,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) {struct worktree **worktrees, **p; -read_cache (); +read_index (&the_index);do_add_index_objects_to_pending (revs, &the_index);if (revs->single_worktree)
@@ -1495,10 +1495,10 @@ static void prepare_show_merge(struct rev_info *revs)free_commit_list (bases); head->object.flags |=SYMMETRIC_LEFT ; -if (!active_nr) -read_cache (); -for (i =0 ; i < active_nr; i++) { -const struct cache_entry *ce = active_cache[i]; +if (!the_index.cache_nr) +read_index (&the_index); +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 )) {
@@ -1507,8 +1507,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);
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 12/15 sequencer.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- sequencer.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
sequencer.c +16 -16
@@ -435,7 +435,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."),
@@ -467,7 +467,7 @@ static int fast_forward_to(const struct object_id *to, const struct object_id *fstruct 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 */
@@ -500,12 +500,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++; } }
@@ -525,7 +525,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,if (hold_locked_index (&index_lock,LOCK_REPORT_ON_ERROR ) <0 )return -1 ; -read_cache (); +read_index (&the_index);init_merge_options (&o); o.ancestor = base ? base_label :"(empty tree)" ;
@@ -571,16 +571,16 @@ static int do_recursive_merge(struct commit *base, struct commit *next,static struct object_id *get_cache_tree_oid (void ) { -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 )) {error (_ ("unable to update cache tree" ));return NULL ; } -return &active_cache_tree->oid; +return &the_index.cache_tree->oid; }static int is_index_unchanged (void )
@@ -1644,7 +1644,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, NULL, 0))return error_dirty_index (opts); } -discard_cache (); +discard_index (&the_index);if (!commit->parents) parent =NULL ;
@@ -2637,7 +2637,7 @@ static int do_exec(const char *command_line) child_env.argv);/* force re-reading of the cache */ -if (discard_cache () <0 ||read_cache () <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 );
@@ -2801,7 +2801,7 @@ static int do_reset(const char *name, int len, struct replay_opts *opts) unpack_tree_opts.merge =1 ; unpack_tree_opts.update =1 ; -if (read_cache_unmerged ()) { +if (read_index_unmerged (&the_index)) {rollback_lock_file (&lock);strbuf_release (&ref_name);return error_resolve_conflict (_ (action_name (opts)));
@@ -2991,7 +2991,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,commit_list_insert (j->item, &reversed);free_commit_list (bases); -read_cache (); +read_index (&the_index);init_merge_options (&o); o.branch1 ="HEAD" ; o.branch2 = ref_name.buf;
@@ -3016,7 +3016,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,*/ ret = !ret; -if (active_cache_changed && +if (the_index.cache_changed &&write_locked_index (&the_index, &lock,COMMIT_LOCK )) { ret =error (_ ("merge: Unable to write new index file" )); goto leave_merge;
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 13/15 sha1-name.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- sha1-name.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
sha1-name.c +11 -11
@@ -1560,11 +1560,11 @@ 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 < 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"
@@ -1576,11 +1576,11 @@ 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 < 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"
@@ -1672,13 +1672,13 @@ static int get_oid_with_context_1(const char *name,if (flags &GET_OID_RECORD_PATH ) oc->path =xstrdup (cp); -if (!active_cache) -read_cache (); - pos =cache_name_pos (cp, namelen); +if (!the_index.cache) +read_index (&the_index); + pos =index_name_pos (&the_index, 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 ;
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
PATCH 14/15 wt-status.c: stop using index compat macros
In reply to Nguyễn Thái Ngọc Duy--- wt-status.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
wt-status.c +12 -12
@@ -499,14 +499,14 @@ 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 ; 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 ));
@@ -642,10 +642,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 ;
@@ -702,7 +702,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);
@@ -710,7 +710,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);
@@ -2180,11 +2180,11 @@ 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 < 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 ;
@@ -2333,7 +2333,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 );
@@ -2356,7 +2356,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.18.0.rc0.333.g22e6ee6cdf
PATCH 15/15 cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
In reply to Nguyễn Thái Ngọc DuyFrom now on, by default index compat macros are off because they could hide the_index dependency. Only those in builtin can use it (and even so should be avoided if possible).
--- attr.c | 1 - builtin/add.c | 1 + builtin/am.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/commit.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/fsck.c | 1 + builtin/ls-files.c | 1 - builtin/merge-index.c | 1 + builtin/merge-ours.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/reset.c | 1 + builtin/rev-parse.c | 1 + builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + builtin/update-index.c | 1 + cache.h | 2 +- convert.c | 1 - dir.c | 1 - name-hash.c | 1 - pathspec.c | 1 - read-cache.c | 1 - submodule.c | 1 - t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-tool.h | 2 ++ tree.c | 1 - unpack-trees.c | 1 - 38 files changed, 29 insertions(+), 11 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 "config.h" #include "exec-cmd.h"
builtin/add.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) 2006 Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h"
builtin/am.c +1 -0
@@ -3,6 +3,7 @@* * Based on git-am.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h"
builtin/check-attr.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h"
builtin/check-ignore.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h"
builtin/checkout-index.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) 2005 Linus Torvalds * */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h"
builtin/checkout.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "checkout.h"
builtin/clean.c +1 -0
@@ -6,6 +6,7 @@* Based on git-clean.sh by Pavel Roskin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h"
builtin/commit.c +1 -0
@@ -5,6 +5,7 @@* Based on git-commit.sh by Junio C Hamano and Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h"
builtin/describe.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h"
builtin/diff-files.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h"
builtin/diff-index.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h"
builtin/diff-tree.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h"
builtin/diff.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h"
builtin/fsck.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "repository.h"
builtin/ls-files.c +0 -1
@@ -5,7 +5,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h"
builtin/merge-index.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "run-command.h"
builtin/merge-ours.c +1 -0
@@ -7,6 +7,7 @@* * Pretend we resolved the heads, but declare our tree trumps everybody else. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" #include "builtin.h" #include "diff.h"
builtin/merge.c +1 -0
@@ -6,6 +6,7 @@* Based on git-merge.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "parse-options.h"
builtin/mv.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) 2006 Johannes Schindelin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "pathspec.h"
builtin/pull.c +1 -0
@@ -5,6 +5,7 @@* * Fetch one or more remote refs and merge it/them into the current HEAD. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h"
builtin/read-tree.c +1 -0
@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h"
builtin/reset.c +1 -0
@@ -7,6 +7,7 @@* * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h"
builtin/rev-parse.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "commit.h"
builtin/rm.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds 2006 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h"
builtin/submodule--helper.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "repository.h" #include "cache.h"
builtin/update-index.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h"
cache.h +1 -1
@@ -339,7 +339,7 @@ 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 +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS #define active_cache (the_index.cache)#define active_nr (the_index.cache_nr)#define active_alloc (the_index.cache_alloc)
convert.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "attr.h"
dir.c +0 -1
@@ -7,7 +7,6 @@* Copyright (C) Linus Torvalds, 2005-2006 * Junio Hamano, 2005-2006 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h"
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 {
pathspec.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h"
read-cache.c +0 -1
@@ -3,7 +3,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "tempfile.h"
submodule.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h"
t/helper/test-dump-untracked-cache.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "dir.h"
t/helper/test-tool.h +2 -0
@@ -1,6 +1,8 @@#ifndef __TEST_TOOL_H__#define __TEST_TOOL_H__ +#define USE_THE_INDEX_COMPATIBILITY_MACROS +int cmd__chmtime (int argc,const char **argv);int cmd__config (int argc,const char **argv);int cmd__ctype (int argc,const char **argv);
tree.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h"
unpack-trees.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "argv-array.h" #include "repository.h"
Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
Re: [PATCH 15/15] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
Quoted 3 lines · Nguyễn Thái Ngọc Duy
From now on, by default index compat macros are off because they could hide
the_indexdependency. Only those in builtin can use it (and even so should be avoided if possible).
This is awesome! Now there aren't any compat macros left in the lib code and the next set of patches has a good base to work from the eliminate the_index (which I assume based on other mails from you will become part of the new USE_THE_INDEX_COMPATIBILITY_MACROS macro once its eliminated from the lib code).
Quoted 459 lines
Signed-off-by Nguyễn Thái Ngọc Duy <[email protected]>--- attr.c | 1 - builtin/add.c | 1 + builtin/am.c | 1 + builtin/check-attr.c | 1 + builtin/check-ignore.c | 1 + builtin/checkout-index.c | 1 + builtin/checkout.c | 1 + builtin/clean.c | 1 + builtin/commit.c | 1 + builtin/describe.c | 1 + builtin/diff-files.c | 1 + builtin/diff-index.c | 1 + builtin/diff-tree.c | 1 + builtin/diff.c | 1 + builtin/fsck.c | 1 + builtin/ls-files.c | 1 - builtin/merge-index.c | 1 + builtin/merge-ours.c | 1 + builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/reset.c | 1 + builtin/rev-parse.c | 1 + builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + builtin/update-index.c | 1 + cache.h | 2 +- convert.c | 1 - dir.c | 1 - name-hash.c | 1 - pathspec.c | 1 - read-cache.c | 1 - submodule.c | 1 - t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-tool.h | 2 ++ tree.c | 1 - unpack-trees.c | 1 - 38 files changed, 29 insertions(+), 11 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 "config.h" #include "exec-cmd.h" builtin/add.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) 2006 Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" builtin/am.c +1
-0@@ -3,6 +3,7 @@* * Based on git-am.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" builtin/check-attr.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" builtin/check-ignore.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" builtin/checkout-index.c +1
-0@@ -4,6 +4,7 @@* Copyright (C) 2005 Linus Torvalds * */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" builtin/checkout.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "checkout.h" builtin/clean.c +1
-0@@ -6,6 +6,7 @@* Based on git-clean.sh by Pavel Roskin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h" builtin/commit.c +1
-0@@ -5,6 +5,7 @@* Based on git-commit.sh by Junio C Hamano and Linus Torvalds */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" builtin/describe.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" builtin/diff-files.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" builtin/diff-index.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" builtin/diff-tree.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h" builtin/diff.c +1
-0@@ -3,6 +3,7 @@* * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" builtin/fsck.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "repository.h" builtin/ls-files.c +0
-1@@ -5,7 +5,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h" builtin/merge-index.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "run-command.h" builtin/merge-ours.c +1
-0@@ -7,6 +7,7 @@* * Pretend we resolved the heads, but declare our tree trumps everybody else. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" #include "builtin.h" #include "diff.h" builtin/merge.c +1
-0@@ -6,6 +6,7 @@* Based on git-merge.sh by Junio C Hamano. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "parse-options.h" builtin/mv.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) 2006 Johannes Schindelin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "pathspec.h" builtin/pull.c +1
-0@@ -5,6 +5,7 @@* * Fetch one or more remote refs and merge it/them into the current HEAD. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" builtin/read-tree.c +1
-0@@ -4,6 +4,7 @@* Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" builtin/reset.c +1
-0@@ -7,6 +7,7 @@* * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" builtin/rev-parse.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "commit.h" builtin/rm.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds 2006 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.h" builtin/submodule--helper.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "repository.h" #include "cache.h" builtin/update-index.c +1
-0@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "lockfile.h" cache.h +1
-1@@ -339,7 +339,7 @@ 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 +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS #define active_cache (the_index.cache)#define active_nr (the_index.cache_nr)#define active_alloc (the_index.cache_alloc)convert.c +0
-1@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "attr.h" dir.c +0
-1@@ -7,7 +7,6 @@* Copyright (C) Linus Torvalds, 2005-2006 * Junio Hamano, 2005-2006 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h" 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 {pathspec.c +0
-1@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "dir.h" read-cache.c +0
-1@@ -3,7 +3,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "tempfile.h" submodule.c +0
-1@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" t/helper/test-dump-untracked-cache.c +1
-0@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "dir.h" t/helper/test-tool.h +2
-0@@ -1,6 +1,8 @@#ifndef __TEST_TOOL_H__#define __TEST_TOOL_H__ +#define USE_THE_INDEX_COMPATIBILITY_MACROS +int cmd__chmtime (int argc,const char **argv);int cmd__config (int argc,const char **argv);int cmd__ctype (int argc,const char **argv);tree.c +0
-1@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "cache-tree.h" #include "tree.h" unpack-trees.c +0
-1@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "argv-array.h" #include "repository.h" Signature · 1 line
2.18.0.rc0.333.g22e6ee6cdf
Signature · 1 line
Brandon Williams
Quoted 9 lines · Nguyễn Thái Ngọc Duy
This is the beginning of the end of
the_index. The problem withthe_indexis it lets library code anywhere access it freely. This is not good because from high level you may not realize thatthe_indexis being used while you don't want to touch index at all, or you want to use a different index instead.This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
You post this small little patch about unpack-trees.c, mentioning you don't know if it's even correct, and bait me into reviewing it and then spring on me that it's actually nearly 100 patches that need
review... Very sneaky. ;-)
Quoted 4 lines
This is the first part, which kills the use of index compat macros outside builtin/ and expose
the_indexin all library code. Later on we will banthe_indexfrom one file each time until it's gone for good.
Quoted 8 lines
"struct
index_state*" will be passed from builtin/ through the call chain to the function that needs it. In some cases, "struct repository *" will be passed instead when the whole operation spans more than just the index. By the end,the_indexbecomes part of "index compat macros" and cannot be used outside builtin/Part one is mechanical conversion with the help of coccinelle. The only real patches are the first and the last one.
Thanks for the nice division. I read through all 15 patches, though I looked at the first and the last a bit closer. I'm not familiar with coccinelle yet, but it at least looked relatively straightforward; would be good to have someone else double check that patch. Other than that, the changes look good to me.
Thanks for working on this!
Quoted 9 lines · Elijah Newren
Quoted 6 lines · Nguyễn Thái Ngọc Duy
This is the beginning of the end of
the_index. The problem withthe_indexis it lets library code anywhere access it freely. This is not good because from high level you may not realize thatthe_indexis being used while you don't want to touch index at all, or you want to use a different index instead.
Quoted 8 lines
Quoted 3 lines
This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
You post this small little patch about
unpack-trees.c, mentioning you don't know if it's even correct, and bait me into reviewing it and then spring on me that it's actually nearly 100 patches that need
review... Very sneaky. ;-)
To be fair, it's all Brandon's fault. If he didn't kick the_index out of dir.c, it would not conflict with one of my out-of-tree patches in unpack-trees.c, catch my attention and make me go down this rabbit hole :D
Signature · 1 line
Duy
Quoted 19 lines · Duy Nguyen
Quoted 9 lines · Elijah Newren
Quoted 6 lines · Nguyễn Thái Ngọc Duy
This is the beginning of the end of
the_index. The problem withthe_indexis it lets library code anywhere access it freely. This is not good because from high level you may not realize thatthe_indexis being used while you don't want to touch index at all, or you want to use a different index instead.Quoted 8 lines
Quoted 3 lines
This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
You post this small little patch about
unpack-trees.c, mentioning you don't know if it's even correct, and bait me into reviewing it and then spring on me that it's actually nearly 100 patches that need
review... Very sneaky. ;-)
Quoted 4 lines
To be fair, it's all Brandon's fault. If he didn't kick
the_indexout ofdir.c, it would not conflict with one of my out-of-tree patches inunpack-trees.c, catch my attention and make me go down this rabbit hole :D
Haha well this is something I've wanted to do for over a year now, glad you've decided to run with it :)
I guess I've gotten pretty good at getting people to go down rabbit holes. First Stefan with the object store refactoring and now you with the index stuff. All because I wanted git to be more object oriented and have less global state ;)
Signature · 1 line
Brandon Williams
Quoted 25 lines · Brandon Williams
Quoted 19 lines · Duy Nguyen
Quoted 9 lines · Elijah Newren
Quoted 6 lines · Nguyễn Thái Ngọc Duy
This is the beginning of the end of
the_index. The problem withthe_indexis it lets library code anywhere access it freely. This is not good because from high level you may not realize thatthe_indexis being used while you don't want to touch index at all, or you want to use a different index instead.Quoted 8 lines
Quoted 3 lines
This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
You post this small little patch about
unpack-trees.c, mentioning you don't know if it's even correct, and bait me into reviewing it and then spring on me that it's actually nearly 100 patches that need
review... Very sneaky. ;-)Quoted 4 lines
To be fair, it's all Brandon's fault. If he didn't kick
the_indexout ofdir.c, it would not conflict with one of my out-of-tree patches inunpack-trees.c, catch my attention and make me go down this rabbit hole :D
Quoted 8 lines
Haha well this is something I've wanted to do for over a year now, glad you've decided to run with it :)
I guess I've gotten pretty good at getting people to go down rabbit holes. First Stefan with the object store refactoring and now you with the index stuff. All because I wanted git to be more object oriented and have less global state ;)
Let me join the chorus of voices excited to see someone finally taking the plunge to do this! I'm very happy about seeing this taken through to "the end of the_index."
Quoted 20 lines · Nguyễn Thái Ngọc Duy
This is the beginning of the end of
the_index. The problem withthe_indexis it lets library code anywhere access it freely. This is not good because from high level you may not realize thatthe_indexis being used while you don't want to touch index at all, or you want to use a different index instead.This is a long series, 86 patches [1], so I'm going to split and submit it in 15-20 patches at a time. The first two parts are trivial though and could be safely fast tracked if needed.
This is the first part, which kills the use of index compat macros outside builtin/ and expose
the_indexin all library code. Later on we will banthe_indexfrom one file each time until it's gone for good."struct
index_state*" will be passed from builtin/ through the call chain to the function that needs it. In some cases, "struct repository *" will be passed instead when the whole operation spans more than just the index. By the end,the_indexbecomes part of "index compat macros" and cannot be used outside builtin/
Quoted 4 lines
Part one is mechanical conversion with the help of coccinelle. The only real patches are the first and the last one.
[1] https://gitlab.com/pclouds/git/commits/really-kill-the-index
This is a good series, and a good goal!
Outside of dropping [PATCH 01/15] until all the changes are applied, this patch looks like a good, mechanical change.
There are a lot of cross-cutting changes happening right now, between this series of series and Stefan's series of series. Hopefully after 2.18 is cut, a lot of these can graduate to master quickly. Personally, I find it difficult to base a patch off of multiple in-progress branches and would rather work off of a "known good" point like the tip of master.
Thanks,
-Stolee
Quoted 3 lines · Derrick Stolee
Personally,
I find it difficult to base a patch off of multiple in-progress branches and would rather work off of a "known good" point like the tip of master.
You should always base your patches on 'master' (or even 'maint' if it's bug fixes that have a chance of entering 'maint'). We all we face conflicts at some point (mostly when we rebase after something gets merged to master; or things are merged on 'pu'). But git-rerere should keep conflict resolution easy (most of the time). I also expect Junio to kick and scream when patch series conflict badly on 'pu' and he will decide which one goes first and kick others out temporarily.
Signature · 1 line
Duy