nd/the-index-final small update
cover nd/the-index-final small update
This was noticed by Ramsay [1] and I almost forgot.
[1] http://public-inbox.org/git/[email protected]
Range-diff:
1: 4478671442 ! 1: 971d2839ab cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
@@ -2,12 +2,11 @@
cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
- >From now on, by default index compat macros are off because they could
+ From 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).
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
- Signed-off-by: Junio C Hamano <[email protected]>
diff --git a/attr.c b/attr.c
--- a/attr.c
@@ -590,6 +589,15 @@
diff --git a/repository.c b/repository.c
--- a/repository.c
+++ b/repository.c
+@@
++/*
++ * not really _using_ the compat macros, just make sure the_index
++ * declaration matches the definition in this file.
++ */
++#define USE_THE_INDEX_COMPATIBILITY_MACROS
+ #include "cache.h"
+ #include "repository.h"
+ #include "object-store.h"
@@
/* The main repository */
static struct repository the_repo;Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 1/11 grep: use grep_opt->repo instead of explict repo argument
This command is probably the first one that operates on a repository other than the_repository, in f9ee2fcdfa (grep: recurse in-process using 'struct repository' - 2017-08-02). An explicit 'struct repository *' was added in that commit to pass around the repository that we're supposed to grep from.
Since 38bbc2ea39 (grep.c: remove implicit dependency on the_index - 2018-09-21). 'struct grep_opt *' carries in itself a repository parameter for grepping. We should now be able to reuse grep_opt to hold the submodule repo instead of a separate argument, which is just room for mistakes.
While at there, use the right reference instead of the_repository and the_index in this code. I was a bit careless in my attempt to kick the_repository / the_index out of library code. It's normally safe to just stick the_repository / the_index in bultin/ code, but it's not the case for grep.
--- builtin/grep.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-)
builtin/grep.c +24 -17
@@ -393,18 +393,20 @@ static void run_pager(struct grep_opt *opt, const char *prefix)exit (status); } -static int grep_cache (struct grep_opt *opt,struct repository *repo, +static int grep_cache (struct grep_opt *opt,const struct pathspec *pathspec,int cached);static int grep_tree (struct grep_opt *opt,const struct pathspec *pathspec,struct tree_desc *tree,struct strbuf *base,int tn_len, -int check_attr,struct repository *repo); +int check_attr); -static int grep_submodule (struct grep_opt *opt,struct repository *superproject, +static int grep_submodule (struct grep_opt *opt,const struct pathspec *pathspec,const struct object_id *oid,const char *filename,const char *path) { +struct repository *superproject = opt->repo;struct repository submodule; +struct grep_opt subopt;int hit;/*
@@ -440,6 +442,9 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,add_to_alternates_memory (submodule.objects->odb->path);grep_read_unlock (); +memcpy (&subopt, opt,sizeof (subopt)); + subopt.repo = &submodule; +if (oid) {struct object *object;struct tree_desc tree;
@@ -461,21 +466,22 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,strbuf_addch (&base,'/' );init_tree_desc (&tree, data, size); - hit =grep_tree (opt, pathspec, &tree, &base, base.len, - object->type ==OBJ_COMMIT , &submodule); + hit =grep_tree (&subopt, pathspec, &tree, &base, base.len, + object->type ==OBJ_COMMIT );strbuf_release (&base);free (data); }else { - hit =grep_cache (opt, &submodule, pathspec,1 ); + hit =grep_cache (&subopt, pathspec,1 ); }repo_clear (&submodule);return hit; } -static int grep_cache (struct grep_opt *opt,struct repository *repo, +static int grep_cache (struct grep_opt *opt,const struct pathspec *pathspec,int cached) { +struct repository *repo = opt->repo;int hit =0 ;int nr;struct strbuf name =STRBUF_INIT ;
@@ -513,7 +519,7 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo, } }else if (recurse_submodules &&S_ISGITLINK (ce->ce_mode) &&submodule_path_match (repo->index, pathspec, name.buf,NULL )) { - hit |=grep_submodule (opt, repo, pathspec,NULL , ce->name, ce->name); + hit |=grep_submodule (opt, pathspec,NULL , ce->name, ce->name); }else {continue ; }
@@ -535,8 +541,9 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,static int grep_tree (struct grep_opt *opt,const struct pathspec *pathspec,struct tree_desc *tree,struct strbuf *base,int tn_len, -int check_attr,struct repository *repo) +int check_attr) { +struct repository *repo = opt->repo;int hit =0 ;enum interesting match = entry_not_interesting;struct name_entry entry;
@@ -582,10 +589,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,strbuf_addch (base,'/' );init_tree_desc (&sub, data, size); hit |=grep_tree (opt, pathspec, &sub, base, tn_len, - check_attr, repo); + check_attr);free (data); }else if (recurse_submodules &&S_ISGITLINK (entry.mode)) { - hit |=grep_submodule (opt, repo, pathspec, entry.oid, + hit |=grep_submodule (opt, pathspec, entry.oid, base->buf, base->buf + tn_len); }
@@ -627,7 +634,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, }init_tree_desc (&tree, data, size); hit =grep_tree (opt, pathspec, &tree, &base, base.len, - obj->type ==OBJ_COMMIT , the_repository); + obj->type ==OBJ_COMMIT );strbuf_release (&base);free (data);return hit;
@@ -644,12 +651,12 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,for (i =0 ; i < nr; i++) {struct object *real_obj; - real_obj =deref_tag (the_repository, list->objects[i].item, + real_obj =deref_tag (opt->repo, list->objects[i].item,NULL ,0 );/* load the gitmodules file for this rev */ if (recurse_submodules) { -submodule_free (the_repository); +submodule_free (opt->repo);gitmodules_config_oid (&real_obj->oid); } if (grep_object(opt, pathspec, real_obj, list->objects[i].name,
@@ -674,9 +681,9 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,if (exc_std)setup_standard_excludes (&dir); -fill_directory (&dir, &the_index, pathspec); +fill_directory (&dir, opt->repo->index, pathspec);for (i =0 ; i < dir.nr; i++) { -if (!dir_path_match (&the_index, dir.entries[i], pathspec,0 ,NULL )) +if (!dir_path_match (opt->repo->index, dir.entries[i], pathspec,0 ,NULL ))continue ; hit |=grep_file (opt, dir.entries[i]->name);if (hit && opt->status_only)
@@ -1117,7 +1124,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)if (!cached)setup_work_tree (); - hit =grep_cache (&opt, the_repository, &pathspec, cached); + hit =grep_cache (&opt, &pathspec, cached); }else {if (cached)die (_ ("both --cached and trees are given" ));
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 2/11 notes-utils.c: remove the_repository references
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 2 +- builtin/commit.c | 2 +- builtin/notes.c | 21 +++++++++++++-------- notes-merge.c | 4 ++-- notes-utils.c | 17 ++++++++++------- notes-utils.h | 11 ++++++++--- sequencer.c | 7 ++++--- sequencer.h | 3 ++- 8 files changed, 41 insertions(+), 26 deletions(-)
builtin/am.c +1 -1
@@ -527,7 +527,7 @@ static int copy_notes_for_rebase(const struct am_state *state) } finish: -finish_copy_notes_for_rewrite (c, msg); +finish_copy_notes_for_rewrite (the_repository, c, msg);fclose (fp);strbuf_release (&sb);return ret;
builtin/commit.c +1 -1
@@ -1674,7 +1674,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)run_command_v_opt (argv_gc_auto,RUN_GIT_CMD );run_commit_hook (use_editor,get_index_file (),"post-commit" ,NULL );if (amend && !no_post_rewrite) { -commit_post_rewrite (current_head, &oid); +commit_post_rewrite (the_repository, current_head, &oid); }if (!quiet) {unsigned int flags =0 ;
builtin/notes.c +13 -8
@@ -330,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd) }if (!rewrite_cmd) { -commit_notes (t, msg); +commit_notes (the_repository, t, msg);free_notes (t); }else { -finish_copy_notes_for_rewrite (c, msg); +finish_copy_notes_for_rewrite (the_repository, c, msg); }strbuf_release (&buf);return ret;
@@ -469,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)write_note_data (&d, &new_note);if (add_note (t, &object, &new_note, combine_notes_overwrite))BUG ("combine_notes_overwrite failed" ); -commit_notes (t,"Notes added by 'git notes add'" ); +commit_notes (the_repository, t, +"Notes added by 'git notes add'" ); }else {fprintf (stderr,_ ("Removing note for object %s\n" ),oid_to_hex (&object));remove_note (t, object.hash); -commit_notes (t,"Notes removed by 'git notes add'" ); +commit_notes (the_repository, t, +"Notes removed by 'git notes add'" ); }free_note_data (&d);
@@ -552,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)if (add_note (t, &object, from_note, combine_notes_overwrite))BUG ("combine_notes_overwrite failed" ); -commit_notes (t,"Notes added by 'git notes copy'" ); +commit_notes (the_repository, t, +"Notes added by 'git notes copy'" ); out:free_notes (t);return retval;
@@ -636,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)remove_note (t, object.hash); logmsg =xstrfmt ("Notes removed by 'git notes %s'" , argv[0 ]); } -commit_notes (t, logmsg); +commit_notes (the_repository, t, logmsg);free (logmsg);free_note_data (&d);
@@ -937,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)strbuf_release (&sb); }if (!retval) -commit_notes (t,"Notes removed by 'git notes remove'" ); +commit_notes (the_repository, t, +"Notes removed by 'git notes remove'" );free_notes (t);return retval; }
@@ -965,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)prune_notes (t, (verbose ?NOTES_PRUNE_VERBOSE :0 ) | (show_only ?NOTES_PRUNE_VERBOSE |NOTES_PRUNE_DRYRUN :0 ) );if (!show_only) -commit_notes (t,"Notes removed by 'git notes prune'" ); +commit_notes (the_repository, t, +"Notes removed by 'git notes prune'" );free_notes (t);return 0 ; }
notes-merge.c +2 -2
@@ -649,7 +649,7 @@ int notes_merge(struct notes_merge_options *o,struct commit_list *parents =NULL ;commit_list_insert (remote, &parents);/* LIFO order */ commit_list_insert (local, &parents); -create_notes_commit (local_tree, parents, o->commit_msg.buf, +create_notes_commit (o->repo, local_tree, parents, o->commit_msg.buf, o->commit_msg.len, result_oid); }
@@ -724,7 +724,7 @@ int notes_merge_commit(struct notes_merge_options *o,strbuf_setlen (&path, baselen); } -create_notes_commit (partial_tree, partial_commit->parents, msg, +create_notes_commit (o->repo, partial_tree, partial_commit->parents, msg,strlen (msg), result_oid);unuse_commit_buffer (partial_commit, buffer);if (o->verbosity >=4 )
notes-utils.c +10 -7
@@ -5,7 +5,9 @@#include "notes-utils.h" #include "repository.h" -void create_notes_commit (struct notes_tree *t,struct commit_list *parents, +void create_notes_commit (struct repository *r, +struct notes_tree *t, +struct commit_list *parents,const char *msg,size_t msg_len,struct object_id *result_oid) {
@@ -20,8 +22,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,/* Deduce parent commit from t->ref */ struct object_id parent_oid;if (!read_ref (t->ref, &parent_oid)) { -struct commit *parent =lookup_commit (the_repository, - &parent_oid); +struct commit *parent =lookup_commit (r, &parent_oid);if (parse_commit (parent))die ("Failed to find/parse commit %s" , t->ref);commit_list_insert (parent, &parents);
@@ -34,7 +35,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,die ("Failed to commit notes tree to database" ); } -void commit_notes (struct notes_tree *t,const char *msg) +void commit_notes (struct repository *r,struct notes_tree *t,const char *msg) {struct strbuf buf =STRBUF_INIT ;struct object_id commit_oid;
@@ -50,7 +51,7 @@ void commit_notes(struct notes_tree *t, const char *msg)strbuf_addstr (&buf, msg);strbuf_complete_line (&buf); -create_notes_commit (t,NULL , buf.buf, buf.len, &commit_oid); +create_notes_commit (r, t,NULL , buf.buf, buf.len, &commit_oid);strbuf_insert (&buf,0 ,"notes: " ,7 );/* commit message starts at index 7 */ update_ref (buf.buf, t->update_ref, &commit_oid,NULL ,0 ,UPDATE_REFS_DIE_ON_ERR );
@@ -171,11 +172,13 @@ int copy_note_for_rewrite(struct notes_rewrite_cfg *c,return ret; } -void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c,const char *msg) +void finish_copy_notes_for_rewrite (struct repository *r, +struct notes_rewrite_cfg *c, +const char *msg) {int i;for (i =0 ; c->trees[i]; i++) { -commit_notes (c->trees[i], msg); +commit_notes (r, c->trees[i], msg);free_notes (c->trees[i]); }free (c->trees);
notes-utils.h +8 -3
@@ -5,6 +5,7 @@struct commit_list ;struct object_id ; +struct repository ;/* * Create new notes commit from the given notes tree
@@ -17,11 +18,13 @@ struct object_id;* * The resulting commit SHA1 is stored in result_sha1. */ -void create_notes_commit (struct notes_tree *t,struct commit_list *parents, +void create_notes_commit (struct repository *r, +struct notes_tree *t, +struct commit_list *parents,const char *msg,size_t msg_len,struct object_id *result_oid); -void commit_notes (struct notes_tree *t,const char *msg); +void commit_notes (struct repository *r,struct notes_tree *t,const char *msg);enum notes_merge_strategy {NOTES_MERGE_RESOLVE_MANUAL =0 ,
@@ -45,6 +48,8 @@ int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);struct notes_rewrite_cfg *init_copy_notes_for_rewrite (const char *cmd);int copy_note_for_rewrite (struct notes_rewrite_cfg *c,const struct object_id *from_obj,const struct object_id *to_obj); -void finish_copy_notes_for_rewrite (struct notes_rewrite_cfg *c,const char *msg); +void finish_copy_notes_for_rewrite (struct repository *r, +struct notes_rewrite_cfg *c, +const char *msg);#endif
sequencer.c +4 -3
@@ -1115,7 +1115,8 @@ static int run_rewrite_hook(const struct object_id *oldoid,return finish_command (&proc); } -void commit_post_rewrite (const struct commit *old_head, +void commit_post_rewrite (struct repository *r, +const struct commit *old_head,const struct object_id *new_head) {struct notes_rewrite_cfg *cfg;
@@ -1124,7 +1125,7 @@ void commit_post_rewrite(const struct commit *old_head,if (cfg) {/* we are amending, so old_head is not NULL */ copy_note_for_rewrite (cfg, &old_head->object.oid, new_head); -finish_copy_notes_for_rewrite (cfg,"Notes added by 'git commit --amend'" ); +finish_copy_notes_for_rewrite (r, cfg,"Notes added by 'git commit --amend'" ); }run_rewrite_hook (&old_head->object.oid, new_head); }
@@ -1405,7 +1406,7 @@ static int try_to_commit(struct repository *r, }if (flags &AMEND_MSG ) -commit_post_rewrite (current_head, oid); +commit_post_rewrite (r, current_head, oid); out:free_commit_extra_headers (extra);
sequencer.h +2 -1
@@ -124,7 +124,8 @@ int update_head_with_reflog(const struct commit *old_head,const struct object_id *new_head, const char *action, const struct strbuf *msg, struct strbuf *err); -void commit_post_rewrite (const struct commit *current_head, +void commit_post_rewrite (struct repository *r, +const struct commit *current_head,const struct object_id *new_head);int prepare_branch_to_be_rebased (struct replay_opts *opts,const char *commit);
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 3/11 repository.c: replace hold_locked_index() with repo_hold_locked_index()
In reply to Nguyễn Thái Ngọc Duyhold_locked_index() assumes the index path at $GIT_DIR/index. This is not good for places that take an arbitrary index_state instead of the_index, which is basically everywhere except builtin/.
Replace it with repo_hold_locked_index(). hold_locked_index() remains as a wrapper around repo_hold_locked_index() to reduce changes in builtin/
--- apply.c | 3 ++- cache.h | 2 +- merge-recursive.c | 2 +- merge.c | 2 +- read-cache.c | 5 ----- repository.c | 10 ++++++++++ repository.h | 4 ++++ rerere.c | 2 +- sequencer.c | 10 +++++----- wt-status.c | 2 +- 10 files changed, 26 insertions(+), 16 deletions(-)
apply.c +2 -1
@@ -4712,7 +4712,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 ) {
cache.h +1 -1
@@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);#define unmerge_cache_entry_at (at) unmerge_index_entry_at(&the_index, at)#define unmerge_cache (pathspec) unmerge_index(&the_index, pathspec)#define read_blob_data_from_cache (path, sz) read_blob_data_from_index(&the_index, (path), (sz)) +#define hold_locked_index (lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))#endif #define TYPE_BITS 3
@@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach*/ extern void update_index_if_able (struct index_state *,struct lock_file *); -extern int hold_locked_index (struct lock_file *,int );extern void set_alternate_index_output (const char *);extern int verify_index_checksum;
merge-recursive.c +1 -1
@@ -3643,7 +3643,7 @@ int merge_recursive_generic(struct merge_options *o, } } -hold_locked_index (&lock,LOCK_DIE_ON_ERROR ); +repo_hold_locked_index (the_repository, &lock,LOCK_DIE_ON_ERROR ); clean =merge_recursive (o, head_commit, next_commit, ca, result);if (clean <0 ) {
merge.c +1 -1
@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,refresh_index (r->index,REFRESH_QUIET ,NULL ,NULL ,NULL ); -if (hold_locked_index (&lock_file,LOCK_REPORT_ON_ERROR ) <0 ) +if (repo_hold_locked_index (r, &lock_file,LOCK_REPORT_ON_ERROR ) <0 )return -1 ;memset (&trees,0 ,sizeof (trees));
read-cache.c +0 -5
@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,return 0 ; } -int hold_locked_index (struct lock_file *lk,int lock_flags) -{ -return hold_lock_file_for_update (lk,get_index_file (), lock_flags); -} -int read_index (struct index_state *istate) {return read_index_from (istate,get_index_file (),get_git_dir ());
repository.c +10 -0
@@ -3,6 +3,7 @@#include "object-store.h" #include "config.h" #include "object.h" +#include "lockfile.h" #include "submodule-config.h" /* The main repository */
@@ -263,3 +264,12 @@ int repo_read_index(struct repository *repo)return read_index_from (repo->index, repo->index_file, repo->gitdir); } + +int repo_hold_locked_index (struct repository *repo, +struct lock_file *lf, +int flags) +{ +if (!repo->index_file) +BUG ("the repo hasn't been setup" ); +return hold_lock_file_for_update (lf, repo->index_file, flags); +}
repository.h +4 -0
@@ -6,6 +6,7 @@struct config_set ;struct git_hash_algo ;struct index_state ; +struct lock_file ;struct raw_object_store ;struct submodule_cache ;
@@ -130,5 +131,8 @@ void repo_clear(struct repository *repo);* populated then the number of entries will simply be returned. */ int repo_read_index (struct repository *repo); +int repo_hold_locked_index (struct repository *repo, +struct lock_file *lf, +int flags);#endif /* REPOSITORY_H */
rerere.c +1 -1
@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)struct lock_file index_lock =LOCK_INIT ;int i; -hold_locked_index (&index_lock,LOCK_DIE_ON_ERROR ); +repo_hold_locked_index (r, &index_lock,LOCK_DIE_ON_ERROR );for (i =0 ; i < update->nr; i++) {struct string_list_item *item = &update->items[i];
sequencer.c +5 -5
@@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r,char **xopt;struct lock_file index_lock =LOCK_INIT ; -if (hold_locked_index (&index_lock,LOCK_REPORT_ON_ERROR ) <0 ) +if (repo_hold_locked_index (r, &index_lock,LOCK_REPORT_ON_ERROR ) <0 )return -1 ;read_index (r->index);
@@ -1992,8 +1992,8 @@ static int read_and_refresh_cache(struct repository *r, struct replay_opts *opts) {struct lock_file index_lock =LOCK_INIT ; -int index_fd =hold_locked_index (&index_lock,0 ); -if (read_index (r->index) <0 ) { +int index_fd =repo_hold_locked_index (r, &index_lock,0 ); +if (repo_read_index (r) <0 ) {rollback_lock_file (&index_lock);return error (_ ("git %s: failed to read the index" ),_ (action_name (opts)));
@@ -2978,7 +2978,7 @@ static int do_reset(struct repository *r,struct unpack_trees_options unpack_tree_opts;int ret =0 ; -if (hold_locked_index (&lock,LOCK_REPORT_ON_ERROR ) <0 ) +if (repo_hold_locked_index (r, &lock,LOCK_REPORT_ON_ERROR ) <0 )return -1 ;if (len ==10 && !strncmp ("[new root]" , name, len)) {
@@ -3096,7 +3096,7 @@ static int do_merge(struct repository *r,static struct lock_file lock;const char *p; -if (hold_locked_index (&lock,LOCK_REPORT_ON_ERROR ) <0 ) { +if (repo_hold_locked_index (r, &lock,LOCK_REPORT_ON_ERROR ) <0 ) { ret =-1 ; goto leave_merge; }
wt-status.c +1 -1
@@ -2375,7 +2375,7 @@ int require_clean_work_tree(struct repository *r,struct lock_file lock_file =LOCK_INIT ;int err =0 , fd; - fd =hold_locked_index (&lock_file,0 ); + fd =repo_hold_locked_index (r, &lock_file,0 );refresh_index (r->index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (0 <= fd)update_index_if_able (r->index, &lock_file);
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 4/11 checkout: avoid the_index when possible
In reply to Nguyễn Thái Ngọc Duy--- builtin/checkout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/checkout.c +1 -1
@@ -284,7 +284,7 @@ static int checkout_paths(const struct checkout_opts *opts,return run_add_interactive (revision,"--patch=checkout" , &opts->pathspec); -hold_locked_index (&lock_file,LOCK_DIE_ON_ERROR ); +repo_hold_locked_index (the_repository, &lock_file,LOCK_DIE_ON_ERROR );if (read_cache_preload (&opts->pathspec) <0 )return error (_ ("index file corrupt" ));
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 5/11 read-cache.c: kill read_index()
In reply to Nguyễn Thái Ngọc Duyread_index() shares the same problem as hold_locked_index(): it assumes $GIT_DIR/index. Move all call sites to repo_read_index() instead. read_index_preload() and read_index_unmerged() are also killed as a consequence.
--- apply.c | 2 +- blame.c | 4 ++-- builtin/am.c | 2 +- builtin/commit.c | 2 +- builtin/diff-tree.c | 2 +- builtin/rebase.c | 8 ++++---- cache.h | 11 +++-------- merge-recursive.c | 2 +- merge.c | 2 +- preload-index.c | 11 ++++++----- read-cache.c | 11 ++++------- repository.h | 6 ++++++ rerere.c | 6 +++--- revision.c | 4 ++-- sequencer.c | 20 ++++++++++---------- sha1-name.c | 6 +++--- 16 files changed, 49 insertions(+), 50 deletions(-)
apply.c +1 -1
@@ -4019,7 +4019,7 @@ static int read_apply_cache(struct apply_state *state)return read_index_from (state->repo->index, state->index_file,get_git_dir ()); else - return read_index(state->repo->index); + return repo_read_index(state->repo); }/* This function tries to read the object name from the current index */
blame.c +2 -2
@@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,unsigned mode;struct strbuf msg =STRBUF_INIT ; -read_index (r->index); +repo_read_index (r);time (&now); commit =alloc_commit_node (r); commit->object.parsed =1 ;
@@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,* want to run "diff-index --cached". */ discard_index (r->index); -read_index (r->index); +repo_read_index (r); len =strlen (path);if (!mode) {
builtin/am.c +1 -1
@@ -2278,7 +2278,7 @@ int cmd_am(int argc, const char **argv, const char *prefix)/* Ensure a valid committer ident can be constructed */ git_committer_info (IDENT_STRICT ); -if (read_index_preload (&the_index,NULL ,0 ) <0 ) +if (repo_read_index_preload (the_repository,NULL ,0 ) <0 )die (_ ("failed to read the index" ));if (in_progress) {
builtin/commit.c +1 -1
@@ -1367,7 +1367,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)if (status_format !=STATUS_FORMAT_PORCELAIN && status_format !=STATUS_FORMAT_PORCELAIN_V2 ) progress_flag =REFRESH_PROGRESS ; -read_index (&the_index); +repo_read_index (the_repository);refresh_index (&the_index,REFRESH_QUIET |REFRESH_UNMERGED |progress_flag, &s.pathspec,NULL ,NULL );
builtin/diff-tree.c +1 -1
@@ -165,7 +165,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)if (opt->diffopt.detect_rename) {if (!the_index.cache) -read_index (&the_index); +repo_read_index (the_repository); opt->diffopt.setup |=DIFF_SETUP_USE_SIZE_CACHE ; }while (fgets (line,sizeof (line), stdin)) {
builtin/rebase.c +4 -4
@@ -576,7 +576,7 @@ static int reset_head(struct object_id *oid, const char *action,if (!detach_head) unpack_tree_opts.reset =1 ; -if (read_index_unmerged (the_repository->index) <0 ) { +if (repo_read_index_unmerged (the_repository) <0 ) { ret =error (_ ("could not read index" )); goto leave_reset_head; }
@@ -1015,7 +1015,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)die (_ ("Cannot read HEAD" )); fd =hold_locked_index (&lock_file,0 ); -if (read_index (the_repository->index) <0 ) +if (repo_read_index (the_repository) <0 )die (_ ("could not read index" ));refresh_index (the_repository->index,REFRESH_QUIET ,NULL ,NULL ,NULL );
@@ -1368,7 +1368,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)get_fork_point (options.upstream_name, head); } -if (read_index (the_repository->index) <0 ) +if (repo_read_index (the_repository) <0 )die (_ ("could not read index" ));if (options.autostash) {
@@ -1423,7 +1423,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)putchar ('\n' );if (discard_index (the_repository->index) <0 || -read_index (the_repository->index) <0 ) +repo_read_index (the_repository) <0 )die (_ ("could not read index" )); } }
cache.h +3 -8
@@ -408,11 +408,11 @@ void validate_cache_entries(const struct index_state *istate);#define active_cache_changed (the_index.cache_changed)#define active_cache_tree (the_index.cache_tree) -#define read_cache () read_index(&the_index) +#define read_cache () repo_read_index(the_repository)#define read_cache_from (path) read_index_from(&the_index, (path), (get_git_dir())) -#define read_cache_preload (pathspec) read_index_preload(&the_index, (pathspec), 0) +#define read_cache_preload (pathspec) repo_read_index_preload(the_repository, (pathspec), 0)#define is_cache_unborn () is_index_unborn(&the_index) -#define read_cache_unmerged () read_index_unmerged(&the_index) +#define read_cache_unmerged () repo_read_index_unmerged(the_repository)#define discard_cache () discard_index(&the_index)#define unmerged_cache () unmerged_index(&the_index)#define cache_name_pos (name, namelen) index_name_pos(&the_index,(name),(namelen))
@@ -661,19 +661,14 @@ extern int daemonize(void);/* Initialize and use the cache information */ struct lock_file ; -extern int read_index (struct index_state *);extern void preload_index (struct index_state *index,const struct pathspec *pathspec,unsigned int refresh_flags); -extern int read_index_preload (struct index_state *, -const struct pathspec *pathspec, -unsigned int refresh_flags);extern int do_read_index (struct index_state *istate,const char *path,int must_exist);/* for testting only! */ extern int read_index_from (struct index_state *,const char *path,const char *gitdir);extern int is_index_unborn (struct index_state *); -extern int read_index_unmerged (struct index_state *);/* For use with `write_locked_index()`. */ #define COMMIT_LOCK (1 << 0)
merge-recursive.c +1 -1
@@ -3576,7 +3576,7 @@ int merge_recursive(struct merge_options *o,discard_cache ();if (!o->call_depth) -read_cache (); +repo_read_index (the_repository); o->ancestor ="merged common ancestors" ; clean = merge_trees(o, get_commit_tree(h1), get_commit_tree(h2),
merge.c +1 -1
@@ -37,7 +37,7 @@ int try_merge_command(struct repository *r,argv_array_clear (&args);discard_index (r->index); -if (read_index (r->index) <0 ) +if (repo_read_index (r) <0 )die (_ ("failed to read the cache" ));resolve_undo_clear_index (r->index);
preload-index.c +6 -5
@@ -8,6 +8,7 @@#include "config.h" #include "progress.h" #include "thread-utils.h" +#include "repository.h" /* * Mostly randomly chosen maximum thread counts: we
@@ -146,12 +147,12 @@ void preload_index(struct index_state *index,trace_performance_leave ("preload index" ); } -int read_index_preload (struct index_state *index, -const struct pathspec *pathspec, -unsigned int refresh_flags) +int repo_read_index_preload (struct repository *repo, +const struct pathspec *pathspec, +unsigned int refresh_flags) { -int retval =read_index (index); +int retval =repo_read_index (repo); -preload_index (index, pathspec, refresh_flags); +preload_index (repo->index, pathspec, refresh_flags);return retval; }
read-cache.c +4 -7
@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,return 0 ; } -int read_index (struct index_state *istate) -{ -return read_index_from (istate,get_index_file (),get_git_dir ()); -} - static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, unsigned int version, struct ondisk_cache_entry *ondisk,
@@ -3218,12 +3213,14 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,* state can call this and check its return value, instead of calling * read_cache(). */ -int read_index_unmerged (struct index_state *istate) +int repo_read_index_unmerged (struct repository *repo) { +struct index_state *istate;int i;int unmerged =0 ; -read_index (istate); +repo_read_index (repo); + istate = repo->index;for (i =0 ; i < istate->cache_nr; i++) {struct cache_entry *ce = istate->cache[i];struct cache_entry *new_ce;
repository.h +6 -0
@@ -7,6 +7,7 @@ struct config_set;struct git_hash_algo ;struct index_state ;struct lock_file ; +struct pathspec ;struct raw_object_store ;struct submodule_cache ;
@@ -135,4 +136,9 @@ int repo_hold_locked_index(struct repository *repo,struct lock_file *lf, int flags); +int repo_read_index_preload (struct repository *, +const struct pathspec *pathspec, +unsigned refresh_flags); +int repo_read_index_unmerged (struct repository *); +#endif /* REPOSITORY_H */
rerere.c +3 -3
@@ -561,7 +561,7 @@ static int find_conflict(struct repository *r, struct string_list *conflict) {int i; -if (read_index (r->index) <0 ) +if (repo_read_index (r) <0 )return error (_ ("index file corrupt" ));for (i =0 ; i < r->index->cache_nr;) {
@@ -595,7 +595,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)if (setup_rerere (r, merge_rr,RERERE_READONLY ))return 0 ; -if (read_index (r->index) <0 ) +if (repo_read_index (r) <0 )return error (_ ("index file corrupt" ));for (i =0 ; i < r->index->cache_nr;) {
@@ -1107,7 +1107,7 @@ int rerere_forget(struct repository *r, struct pathspec *pathspec)struct string_list conflict =STRING_LIST_INIT_DUP ;struct string_list merge_rr =STRING_LIST_INIT_DUP ; -if (read_index (r->index) <0 ) +if (repo_read_index (r) <0 )return error (_ ("index file corrupt" )); fd =setup_rerere (r, &merge_rr,RERERE_NOAUTOUPDATE );
revision.c +2 -2
@@ -1384,7 +1384,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags) {struct worktree **worktrees, **p; -read_index (revs->repo->index); +repo_read_index (revs->repo);do_add_index_objects_to_pending (revs, revs->repo->index, flags);if (revs->single_worktree)
@@ -1530,7 +1530,7 @@ static void prepare_show_merge(struct rev_info *revs) head->object.flags |=SYMMETRIC_LEFT ;if (!istate->cache_nr) -read_index (istate); +repo_read_index (revs->repo);for (i =0 ; i < istate->cache_nr; i++) {const struct cache_entry *ce = istate->cache[i];if (!ce_stage (ce))
sequencer.c +10 -10
@@ -446,9 +446,9 @@ static struct tree *empty_tree(struct repository *r)return lookup_tree (r, the_hash_algo->empty_tree); } -static int error_dirty_index (struct index_state *istate,struct replay_opts *opts) +static int error_dirty_index (struct repository *repo,struct replay_opts *opts) { -if (read_index_unmerged (istate)) +if (repo_read_index_unmerged (repo))return error_resolve_conflict (_ (action_name (opts))); error(_("your local changes would be overwritten by %s."),
@@ -483,7 +483,7 @@ static int fast_forward_to(struct repository *r,struct strbuf sb =STRBUF_INIT ;struct strbuf err =STRBUF_INIT ; -read_index (r->index); +repo_read_index (r);if (checkout_fast_forward (r, from, to,1 ))return -1 ;/* the callee should have complained already */
@@ -543,7 +543,7 @@ static int do_recursive_merge(struct repository *r,if (repo_hold_locked_index (r, &index_lock,LOCK_REPORT_ON_ERROR ) <0 )return -1 ; -read_index (r->index); +repo_read_index (r);init_merge_options (&o); o.ancestor = base ? base_label :"(empty tree)" ;
@@ -1766,7 +1766,7 @@ static int do_pick_commit(struct repository *r,oidcpy (&head, the_hash_algo->empty_tree);if (index_differs_from (r, unborn ?empty_tree_oid_hex () :"HEAD" ,NULL ,0 )) -return error_dirty_index (r->index, opts); +return error_dirty_index (r, opts); }discard_index (r->index);
@@ -2854,7 +2854,7 @@ static int do_exec(struct repository *r, const char *command_line) child_env.argv);/* force re-reading of the cache */ -if (discard_index (r->index) <0 ||read_index (r->index) <0 ) +if (discard_index (r->index) <0 ||repo_read_index (r) <0 )return error (_ ("could not read index" )); dirty =require_clean_work_tree (r,"rebase" ,NULL ,1 ,1 );
@@ -3023,7 +3023,7 @@ static int do_reset(struct repository *r, unpack_tree_opts.merge =1 ; unpack_tree_opts.update =1 ; -if (read_index_unmerged (r->index)) { +if (repo_read_index_unmerged (r)) {rollback_lock_file (&lock);strbuf_release (&ref_name);return error_resolve_conflict (_ (action_name (opts)));
@@ -3277,7 +3277,7 @@ static int do_merge(struct repository *r,/* force re-reading of the cache */ if (!ret && (discard_index (r->index) <0 || -read_index (r->index) <0 )) +repo_read_index (r) <0 )) ret =error (_ ("could not read index" )); goto leave_merge; }
@@ -3299,7 +3299,7 @@ static int do_merge(struct repository *r,commit_list_insert (j->item, &reversed);free_commit_list (bases); -read_index (r->index); +repo_read_index (r);init_merge_options (&o); o.branch1 ="HEAD" ; o.branch2 = ref_name.buf;
@@ -3972,7 +3972,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) goto release_todo_list; }if (index_differs_from (r,"HEAD" ,NULL ,0 )) { - res =error_dirty_index (r->index, opts); + res =error_dirty_index (r, opts); goto release_todo_list; } todo_list.current++;
sha1-name.c +3 -3
@@ -1723,9 +1723,9 @@ 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) +repo_read_index (the_repository); + pos =index_name_pos (&the_index, cp, namelen);if (pos <0 ) pos = -pos -1 ;while (pos < active_nr) {
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 6/11 read-cache.c: replace update_index_if_able with repo_&
In reply to Nguyễn Thái Ngọc Duy--- builtin/commit.c | 2 +- builtin/describe.c | 2 +- builtin/diff.c | 2 +- builtin/rebase.c | 5 ++--- cache.h | 6 ------ read-cache.c | 14 ++++++++------ repository.h | 6 ++++++ wt-status.c | 2 +- 8 files changed, 20 insertions(+), 19 deletions(-)
builtin/commit.c +1 -1
@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)wt_status_collect (&s);if (0 <= fd) -update_index_if_able (&the_index, &index_lock); +repo_update_index_if_able (the_repository, &index_lock);if (s.relative_paths) s.prefix = prefix;
builtin/describe.c +1 -1
@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) NULL, NULL, NULL); fd =hold_locked_index (&index_lock,0 );if (0 <= fd) -update_index_if_able (&the_index, &index_lock); +repo_update_index_if_able (the_repository, &index_lock);repo_init_revisions (the_repository, &revs, prefix);argv_array_pushv (&args, diff_index_args);
builtin/diff.c +1 -1
@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)discard_cache ();read_cache ();refresh_cache (REFRESH_QUIET |REFRESH_UNMERGED ); -update_index_if_able (&the_index, &lock_file); +repo_update_index_if_able (the_repository, &lock_file); }static int builtin_diff_files (struct rev_info *revs,int argc,const char **argv)
builtin/rebase.c +2 -3
@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)refresh_index (the_repository->index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (0 <= fd) -update_index_if_able (the_repository->index, - &lock_file); +repo_update_index_if_able (the_repository, &lock_file);rollback_lock_file (&lock_file);if (has_unstaged_changes (the_repository,1 )) {
@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) fd =hold_locked_index (&lock_file,0 );refresh_cache (REFRESH_QUIET );if (0 <= fd) -update_index_if_able (&the_index, &lock_file); +repo_update_index_if_able (the_repository, &lock_file);rollback_lock_file (&lock_file); if (has_unstaged_changes(the_repository, 1) ||
cache.h +0 -6
@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);extern int refresh_index (struct index_state *,unsigned int flags,const struct pathspec *pathspec,char *seen,const char *header_msg);extern struct cache_entry *refresh_cache_entry (struct index_state *,struct cache_entry *,unsigned int ); -/* -* Opportunistically update the index but do not complain if we can't. -* The lockfile is always committed or rolled back. -*/ -extern void update_index_if_able (struct index_state *,struct lock_file *); -extern void set_alternate_index_output (const char *);extern int verify_index_checksum;
read-cache.c +8 -6
@@ -2654,9 +2654,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)return 0 ; } -static int verify_index (const struct index_state *istate) +static int repo_verify_index (struct repository *repo) { -return verify_index_from (istate,get_index_file ()); +return verify_index_from (repo->index, repo->index_file); }static int has_racy_timestamp (struct index_state *istate)
@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)return 0 ; } -void update_index_if_able (struct index_state *istate,struct lock_file *lockfile) +void repo_update_index_if_able (struct repository *repo, +struct lock_file *lockfile) { -if ((istate->cache_changed ||has_racy_timestamp (istate)) && -verify_index (istate)) -write_locked_index (istate, lockfile,COMMIT_LOCK ); +if ((repo->index->cache_changed || +has_racy_timestamp (repo->index)) && +repo_verify_index (repo)) +write_locked_index (repo->index, lockfile,COMMIT_LOCK );else rollback_lock_file (lockfile); }
repository.h +6 -0
@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,const struct pathspec *pathspec, unsigned refresh_flags);int repo_read_index_unmerged (struct repository *); +/* +* Opportunistically update the index but do not complain if we can't. +* The lockfile is always committed or rolled back. +*/ +void repo_update_index_if_able (struct repository *,struct lock_file *); +#endif /* REPOSITORY_H */
wt-status.c +1 -1
@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r, fd =repo_hold_locked_index (r, &lock_file,0 );refresh_index (r->index,REFRESH_QUIET ,NULL ,NULL ,NULL );if (0 <= fd) -update_index_if_able (r->index, &lock_file); +repo_update_index_if_able (r, &lock_file);rollback_lock_file (&lock_file);if (has_unstaged_changes (r, ignore_submodules)) {
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 7/11 sha1-name.c: remove implicit dependency on the_index
In reply to Nguyễn Thái Ngọc DuyThis kills the_index dependency in get_oid_with_context() but for get_oid() and friends, they still assume the_repository (which also means the_index).
Unfortunately the widespread use of get_oid() will make it hard to make the conversion now. We probably will add repo_get_oid() at some point and limit the use of get_oid() in builtin/ instead of forcing all get_oid() call sites to carry struct repository.
--- builtin/cat-file.c | 6 ++-- builtin/grep.c | 3 +- builtin/log.c | 3 +- builtin/rev-parse.c | 3 +- cache.h | 4 ++- list-objects-filter-options.c | 2 +- revision.c | 8 +++--- sha1-name.c | 54 +++++++++++++++++++++-------------- 8 files changed, 50 insertions(+), 33 deletions(-)
builtin/cat-file.c +4 -2
@@ -73,7 +73,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,if (unknown_type) flags |=OBJECT_INFO_ALLOW_UNKNOWN_TYPE ; -if (get_oid_with_context (obj_name,GET_OID_RECORD_PATH , +if (get_oid_with_context (the_repository, obj_name, +GET_OID_RECORD_PATH , &oid, &obj_context))die ("Not a valid object name %s" , obj_name);
@@ -382,7 +383,8 @@ static void batch_one_object(const char *obj_name,int flags = opt->follow_symlinks ?GET_OID_FOLLOW_SYMLINKS :0 ;enum follow_symlinks_result result; - result =get_oid_with_context (obj_name, flags, &data->oid, &ctx); + result =get_oid_with_context (the_repository, obj_name, + flags, &data->oid, &ctx);if (result !=FOUND ) {switch (result) {case MISSING_OBJECT :
builtin/grep.c +2 -1
@@ -1021,7 +1021,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)break ; } -if (get_oid_with_context (arg,GET_OID_RECORD_PATH , +if (get_oid_with_context (the_repository, arg, +GET_OID_RECORD_PATH , &oid, &oc)) {if (seen_dashdash)die (_ ("unable to resolve revision: %s" ), arg);
builtin/log.c +2 -1
@@ -508,7 +508,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c !rev->diffopt.flags.allow_textconv)return stream_blob_to_fd (1 , oid,NULL ,0 ); -if (get_oid_with_context (obj_name,GET_OID_RECORD_PATH , +if (get_oid_with_context (the_repository, obj_name, +GET_OID_RECORD_PATH , &oidc, &obj_context))die (_ ("Not a valid object name %s" ), obj_name); if (!obj_context.path ||
builtin/rev-parse.c +2 -1
@@ -933,7 +933,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) name++; type =REVERSED ; } -if (!get_oid_with_context (name, flags, &oid, &unused)) { +if (!get_oid_with_context (the_repository, name, + flags, &oid, &unused)) {if (verify) revs_count++;else
cache.h +3 -1
@@ -1328,7 +1328,9 @@ extern int get_oid_tree(const char *str, struct object_id *oid);extern int get_oid_treeish (const char *str,struct object_id *oid);extern int get_oid_blob (const char *str,struct object_id *oid);extern void maybe_die_on_misspelt_object_name (const char *name,const char *prefix); -extern int get_oid_with_context (const char *str,unsigned flags,struct object_id *oid,struct object_context *oc); +extern int get_oid_with_context (struct repository *repo,const char *str, +unsigned flags,struct object_id *oid, +struct object_context *oc);typedef int each_abbrev_fn (const struct object_id *oid,void *);
list-objects-filter-options.c +1 -1
@@ -71,7 +71,7 @@ static int gently_parse_list_objects_filter(* command, but DO NOT complain if we don't have the blob or * ref locally. */ -if (!get_oid_with_context (v0,GET_OID_BLOB , +if (!get_oid_with_context (the_repository, v0,GET_OID_BLOB , &sparse_oid, &oc)) filter_options->sparse_oid_value =oiddup (&sparse_oid); filter_options->choice =LOFC_SPARSE_OID ;
revision.c +4 -4
@@ -1589,8 +1589,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,if (!*b_name) b_name ="HEAD" ; -if (get_oid_with_context (a_name, oc_flags, &a_oid, a_oc) || -get_oid_with_context (b_name, oc_flags, &b_oid, b_oc)) +if (get_oid_with_context (revs->repo, a_name, oc_flags, &a_oid, a_oc) || +get_oid_with_context (revs->repo, b_name, oc_flags, &b_oid, b_oc))return -1 ;if (!cant_be_filename) {
@@ -1724,7 +1724,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsiif (revarg_opt &REVARG_COMMITTISH ) get_sha1_flags |=GET_OID_COMMITTISH ; -if (get_oid_with_context (arg, get_sha1_flags, &oid, &oc)) +if (get_oid_with_context (revs->repo, arg, get_sha1_flags, &oid, &oc))return revs->ignore_missing ?0 :-1 ;if (!cant_be_filename)verify_non_filename (revs->prefix, arg);
@@ -2453,7 +2453,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sstruct object_id oid;struct object *object;struct object_context oc; -if (get_oid_with_context (revs->def,0 , &oid, &oc)) +if (get_oid_with_context (revs->repo, revs->def,0 , &oid, &oc))diagnose_missing_default (revs->def); object =get_reference (revs, revs->def, &oid,0 );add_pending_object_with_mode (revs, object, revs->def, oc.mode);
sha1-name.c +32 -22
142 lines not on this page · raw message
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 8/11 merge-recursive.c: remove implicit dependency on the_index
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 2 +- builtin/checkout.c | 2 +- builtin/merge-recursive.c | 2 +- builtin/merge.c | 2 +- merge-recursive.c | 148 ++++++++++++++++++++------------------ merge-recursive.h | 6 +- sequencer.c | 4 +- 7 files changed, 91 insertions(+), 75 deletions(-)
builtin/am.c +1 -1
@@ -1545,7 +1545,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa* changes. */ -init_merge_options (&o); +init_merge_options (&o, the_repository); o.branch1 ="HEAD" ; their_tree_name =xstrfmt ("%.*s" ,linelen (state->msg), state->msg);
builtin/checkout.c +1 -1
@@ -670,7 +670,7 @@ static int merge_working_tree(const struct checkout_opts *opts,* a pain; plumb in an option to set * o.renormalize? */ -init_merge_options (&o); +init_merge_options (&o, the_repository); o.verbosity =0 ; work =write_tree_from_memory (&o);
builtin/merge-recursive.c +1 -1
@@ -28,7 +28,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)struct merge_options o;struct commit *result; -init_merge_options (&o); +init_merge_options (&o, the_repository);if (argv[0 ] &&ends_with (argv[0 ],"-subtree" )) o.subtree_shift ="" ;
builtin/merge.c +1 -1
@@ -702,7 +702,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,return 2 ; } -init_merge_options (&o); +init_merge_options (&o, the_repository);if (!strcmp (strategy,"subtree" )) o.subtree_shift ="" ;
merge-recursive.c +80 -68
465 lines not on this page · raw message
merge-recursive.h +5 -1
@@ -6,6 +6,8 @@struct commit ; +struct repository ; +struct merge_options {const char *ancestor;const char *branch1;
@@ -34,6 +36,7 @@ struct merge_options {struct string_list df_conflict_file_set;struct unpack_trees_options unpack_opts;struct index_state orig_index; +struct repository *repo; };/*
@@ -92,7 +95,8 @@ int merge_recursive_generic(struct merge_options *o,const struct object_id **ca, struct commit **result); -void init_merge_options (struct merge_options *o); +void init_merge_options (struct merge_options *o, +struct repository *repo);struct tree *write_tree_from_memory (struct merge_options *o);int parse_merge_opt (struct merge_options *out,const char *s);
sequencer.c +2 -2
@@ -545,7 +545,7 @@ static int do_recursive_merge(struct repository *r,repo_read_index (r); -init_merge_options (&o); +init_merge_options (&o, r); o.ancestor = base ? base_label :"(empty tree)" ; o.branch1 ="HEAD" ; o.branch2 = next ? next_label :"(empty tree)" ;
@@ -3300,7 +3300,7 @@ static int do_merge(struct repository *r,free_commit_list (bases);repo_read_index (r); -init_merge_options (&o); +init_merge_options (&o, r); o.branch1 ="HEAD" ; o.branch2 = ref_name.buf; o.buffer_output =2 ;
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 9/11 merge-recursive.c: remove implicit dependency on the_repository
In reply to Nguyễn Thái Ngọc Duy--- merge-recursive.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-)
merge-recursive.c +24 -21
@@ -146,7 +146,8 @@ static int err(struct merge_options *o, const char *err, ...)return -1 ; } -static struct tree *shift_tree_object (struct tree *one,struct tree *two, +static struct tree *shift_tree_object (struct repository *repo, +struct tree *one,struct tree *two,const char *subtree_shift) {struct object_id shifted;
@@ -159,12 +160,14 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, }if (oideq (&two->object.oid, &shifted))return two; -return lookup_tree (the_repository, &shifted); +return lookup_tree (repo, &shifted); } -static struct commit *make_virtual_commit (struct tree *tree,const char *comment) +static struct commit *make_virtual_commit (struct repository *repo, +struct tree *tree, +const char *comment) { -struct commit *commit =alloc_commit_node (the_repository); +struct commit *commit =alloc_commit_node (repo);set_merge_remote_desc (commit, comment, (struct object *)commit); commit->maybe_tree = tree;
@@ -445,7 +448,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)return NULL ; } - result =lookup_tree (the_repository, &istate->cache_tree->oid); + result =lookup_tree (o->repo, &istate->cache_tree->oid);return result; }
@@ -1208,9 +1211,9 @@ static int merge_submodule(struct merge_options *o,return 0 ; } -if (!(commit_base =lookup_commit_reference (the_repository, base)) || - !(commit_a =lookup_commit_reference (the_repository, a)) || - !(commit_b =lookup_commit_reference (the_repository, b))) { +if (!(commit_base =lookup_commit_reference (o->repo, base)) || + !(commit_a =lookup_commit_reference (o->repo, a)) || + !(commit_b =lookup_commit_reference (o->repo, b))) {output (o,1 ,_ ("Failed to merge submodule %s (commits not present)" ), path);return 0 ; }
@@ -3416,8 +3419,8 @@ int merge_trees(struct merge_options *o, }if (o->subtree_shift) { - merge =shift_tree_object (head, merge, o->subtree_shift); - common =shift_tree_object (head, common, o->subtree_shift); + merge =shift_tree_object (o->repo, head, merge, o->subtree_shift); + common =shift_tree_object (o->repo, head, common, o->subtree_shift); }if (oid_eq (&common->object.oid, &merge->object.oid)) {
@@ -3553,8 +3556,8 @@ int merge_recursive(struct merge_options *o,/* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree =lookup_tree (the_repository, the_repository->hash_algo->empty_tree); - merged_common_ancestors =make_virtual_commit (tree,"ancestor" ); + tree =lookup_tree (o->repo, o->repo->hash_algo->empty_tree); + merged_common_ancestors =make_virtual_commit (o->repo, tree,"ancestor" ); }for (iter = ca; iter; iter = iter->next) {
@@ -3598,7 +3601,7 @@ int merge_recursive(struct merge_options *o, }if (o->call_depth) { - *result =make_virtual_commit (mrtree,"merged tree" ); + *result =make_virtual_commit (o->repo, mrtree,"merged tree" );commit_list_insert (h1, &(*result)->parents);commit_list_insert (h2, &(*result)->parents->next); }
@@ -3611,17 +3614,17 @@ int merge_recursive(struct merge_options *o,return clean; } -static struct commit *get_ref (const struct object_id *oid,const char *name) +static struct commit *get_ref (struct repository *repo,const struct object_id *oid, +const char *name) {struct object *object; - object =deref_tag (the_repository,parse_object (the_repository, oid), - name, -strlen (name)); + object =deref_tag (repo,parse_object (repo, oid), + name,strlen (name));if (!object)return NULL ;if (object->type ==OBJ_TREE ) -return make_virtual_commit ((struct tree *)object, name); +return make_virtual_commit (repo, (struct tree *)object, name);if (object->type !=OBJ_COMMIT )return NULL ;if (parse_commit ((struct commit *)object))
@@ -3638,15 +3641,15 @@ int merge_recursive_generic(struct merge_options *o, {int clean;struct lock_file lock =LOCK_INIT ; -struct commit *head_commit =get_ref (head, o->branch1); -struct commit *next_commit =get_ref (merge, o->branch2); +struct commit *head_commit =get_ref (o->repo, head, o->branch1); +struct commit *next_commit =get_ref (o->repo, merge, o->branch2);struct commit_list *ca =NULL ;if (base_list) {int i;for (i =0 ; i < num_base_list; ++i) {struct commit *base; -if (!(base =get_ref (base_list[i],oid_to_hex (base_list[i])))) +if (!(base =get_ref (o->repo, base_list[i],oid_to_hex (base_list[i]))))return err (o,_ ("Could not parse object '%s'" ),oid_to_hex (base_list[i]));commit_list_insert (base, &ca);
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 10/11 read-cache.c: remove the_* from index_has_changes()
In reply to Nguyễn Thái Ngọc Duy--- builtin/am.c | 6 +++--- cache.h | 6 +++--- merge-recursive.c | 2 +- read-cache.c | 12 +++++------- 4 files changed, 12 insertions(+), 14 deletions(-)
builtin/am.c +3 -3
@@ -1719,7 +1719,7 @@ static void am_run(struct am_state *state, int resume)refresh_and_write_cache (); -if (index_has_changes (&the_index,NULL , &sb)) { +if (repo_index_has_changes (the_repository,NULL , &sb)) {write_state_bool (state,"dirtyindex" ,1 );die (_ ("Dirty index: cannot apply patches (dirty: %s)" ), sb.buf); }
@@ -1777,7 +1777,7 @@ static void am_run(struct am_state *state, int resume)* the result may have produced the same tree as ours. */ if (!apply_status && - !index_has_changes (&the_index,NULL ,NULL )) { + !repo_index_has_changes (the_repository,NULL ,NULL )) {say (state, stdout,_ ("No changes -- Patch already applied." )); goto next; }
@@ -1831,7 +1831,7 @@ static void am_resolve(struct am_state *state)say (state, stdout,_ ("Applying: %.*s" ),linelen (state->msg), state->msg); -if (!index_has_changes (&the_index,NULL ,NULL )) { +if (!repo_index_has_changes (the_repository,NULL ,NULL )) {printf_ln (_ ("No changes - did you forget to use 'git add'?\n" "If there is nothing left to stage, chances are that something else\n" "already introduced the same changes; you might want to skip this patch." ));
cache.h +3 -3
@@ -706,9 +706,9 @@ extern int unmerged_index(const struct index_state *);* provided, the space-separated list of files that differ will be appended * to it. */ -extern int index_has_changes (struct index_state *istate, -struct tree *tree, -struct strbuf *sb); +extern int repo_index_has_changes (struct repository *repo, +struct tree *tree, +struct strbuf *sb);extern int verify_path (const char *path,unsigned mode);extern int strcmp_offset (const char *s1,const char *s2,size_t *first_change);
merge-recursive.c +1 -1
@@ -3412,7 +3412,7 @@ int merge_trees(struct merge_options *o,int code, clean;struct strbuf sb =STRBUF_INIT ; -if (!o->call_depth &&index_has_changes (istate, head, &sb)) { +if (!o->call_depth &&repo_index_has_changes (o->repo, head, &sb)) {err (o,_ ("Your local changes to the following files would be overwritten by merge:\n %s" ), sb.buf);return -1 ;
read-cache.c +5 -7
@@ -2365,22 +2365,20 @@ int unmerged_index(const struct index_state *istate)return 0 ; } -int index_has_changes (struct index_state *istate, -struct tree *tree, -struct strbuf *sb) +int repo_index_has_changes (struct repository *repo, +struct tree *tree, +struct strbuf *sb) { +struct index_state *istate = repo->index;struct object_id cmp;int i; -if (istate != &the_index) { -BUG ("index_has_changes cannot yet accept istate != &the_index; do_diff_cache needs updating first." ); - }if (tree) cmp = tree->object.oid;if (tree || !get_oid_tree ("HEAD" , &cmp)) {struct diff_options opt; -repo_diff_setup (the_repository, &opt); +repo_diff_setup (repo, &opt); opt.flags.exit_with_status =1 ;if (!sb) opt.flags.quick =1 ;
Signature · 1 line
2.20.1.560.g70ca8b83ee
PATCH 11/11 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/blame.c | 3 ++- builtin/cat-file.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/clone.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/difftool.c | 1 + builtin/fsck.c | 1 + builtin/grep.c | 1 + builtin/hash-object.c | 3 ++- builtin/log.c | 1 + builtin/ls-files.c | 1 - builtin/merge-index.c | 1 + builtin/merge-ours.c | 1 + builtin/merge-tree.c | 4 +++- builtin/merge.c | 1 + builtin/mv.c | 1 + builtin/pack-objects.c | 2 +- builtin/pull.c | 1 + builtin/read-tree.c | 1 + builtin/rebase--interactive.c | 1 + builtin/rebase.c | 1 + builtin/replace.c | 2 +- builtin/reset.c | 1 + builtin/rev-parse.c | 1 + builtin/rm.c | 1 + builtin/submodule--helper.c | 1 + builtin/update-index.c | 1 + builtin/write-tree.c | 1 + cache-tree.h | 2 +- cache.h | 6 +++--- convert.c | 1 - dir.c | 1 - git.c | 4 ++-- name-hash.c | 1 - pathspec.c | 1 - read-cache.c | 2 -- repository.c | 6 ++++++ submodule.c | 1 - t/helper/test-dump-fsmonitor.c | 4 ++-- t/helper/test-dump-untracked-cache.c | 1 + t/helper/test-tool.h | 1 + tree.c | 1 - unpack-trees.c | 1 - 55 files changed, 58 insertions(+), 24 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/blame.c +2 -1
@@ -1007,7 +1007,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)long bottom, top;if (parse_range_arg (range_list.items[range_i].string, nth_line_cb, &sb, lno, anchor, - &bottom, &top, sb.path, &the_index)) + &bottom, &top, sb.path, + the_repository->index))usage (blame_usage);if ((!lno && (top || bottom)) || lno < bottom) die(Q_("file %s has only %lu line",
builtin/cat-file.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 "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/clone.c +1 -0
@@ -8,6 +8,7 @@* Clone a repository into a different directory that does not yet exist. */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" #include "lockfile.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/difftool.c +1 -0
@@ -11,6 +11,7 @@* * Copyright (C) 2016 Johannes Schindelin */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.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/grep.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (c) 2006 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "config.h"
builtin/hash-object.c +2 -1
@@ -40,7 +40,8 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,if (fstat (fd, &st) <0 || (literally ?hash_literally (&oid, fd, type, flags) - :index_fd (&the_index, &oid, fd, &st,type_from_string (type), path, flags))) + :index_fd (the_repository->index, &oid, fd, &st, +type_from_string (type), path, flags)))die ((flags &HASH_WRITE_OBJECT ) ?"Unable to add %s to database" :"Unable to hash %s" , path);
builtin/log.c +1 -0
@@ -4,6 +4,7 @@* (C) Copyright 2006 Linus Torvalds * 2006 Junio Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "refs.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-tree.c +3 -1
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "tree-walk.h" #include "xdiff-interface.h"
@@ -76,7 +77,8 @@ static void *result(struct merge_list *entry, unsigned long *size) their =NULL ;if (entry) their = entry->blob; -return merge_blobs (&the_index, path, base, our, their, size); +return merge_blobs (the_repository->index, path, + base, our, their, size); }static void *origin (struct merge_list *entry,unsigned long *size)
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/pack-objects.c +1 -1
@@ -970,7 +970,7 @@ static int no_try_delta(const char *path)if (!check) check =attr_check_initl ("delta" ,NULL ); -git_check_attr (&the_index, path, check); +git_check_attr (the_repository->index, path, check);if (ATTR_FALSE (check->items[0 ].value))return 1 ;return 0 ;
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/rebase--interactive.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h"
builtin/rebase.c +1 -0
@@ -4,6 +4,7 @@* Copyright (c) 2018 Pratik Karki */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "run-command.h" #include "exec-cmd.h"
builtin/replace.c +1 -1
@@ -295,7 +295,7 @@ static int import_object(struct object_id *oid, enum object_type type,close (fd);return -1 ; } -if (index_fd (&the_index, oid, fd, &st, type,NULL , flags) <0 ) +if (index_fd (the_repository->index, oid, fd, &st, type,NULL , flags) <0 )return error (_ ("unable to write object to database" ));/* index_fd close()s fd for us */ }
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"
builtin/write-tree.c +1 -0
@@ -3,6 +3,7 @@* * Copyright (C) Linus Torvalds, 2005 */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "cache.h" #include "config.h"
cache-tree.h +1 -1
@@ -51,7 +51,7 @@ void prime_cache_tree(struct repository *, struct index_state *, struct tree *);int cache_tree_matches_traversal (struct cache_tree *,struct name_entry *ent,struct traverse_info *info); -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS static inline int write_cache_as_tree (struct object_id *oid,int flags,const char *prefix) {return write_index_as_tree (oid, &the_index,get_index_file (), flags, prefix);
cache.h +3 -3
@@ -338,8 +338,6 @@ struct index_state {struct mem_pool *ce_mem_pool; }; -extern struct index_state the_index; -/* Name hashing */ extern int test_lazy_init_name_hash (struct index_state *istate,int try_threaded);extern void add_name_hash (struct index_state *istate,struct cache_entry *ce);
@@ -401,7 +399,9 @@ struct cache_entry *dup_cache_entry(const struct cache_entry *ce, struct index_s*/ void validate_cache_entries (const struct index_state *istate); -#ifndef NO_THE_INDEX_COMPATIBILITY_MACROS +#ifdef USE_THE_INDEX_COMPATIBILITY_MACROS +extern struct index_state the_index; +#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 "object-store.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"
git.c +2 -2
@@ -417,9 +417,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)trace_argv_printf (argv,"trace: built-in: git" ); -validate_cache_entries (&the_index); +validate_cache_entries (the_repository->index); status = p->fn (argc, argv, prefix); -validate_cache_entries (&the_index); +validate_cache_entries (the_repository->index);if (status)return status;
name-hash.c +0 -1
@@ -5,7 +5,6 @@* * Copyright (C) 2008 Linus Torvalds */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "thread-utils.h"
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 -2
@@ -3,7 +3,6 @@* * Copyright (C) Linus Torvalds, 2005 */ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "diff.h"
@@ -95,7 +94,6 @@ static struct mem_pool *find_mem_pool(struct index_state *istate)return *pool_ptr; } -struct index_state the_index;static const char *alternate_index_output;static void set_index_entry (struct index_state *istate,int nr,struct cache_entry *ce)
repository.c +6 -0
@@ -1,3 +1,8 @@ +/* +* not really _using_ the compat macros, just make sure the_index +* declaration matches the definition in this file. +*/ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h" #include "object-store.h"
@@ -9,6 +14,7 @@/* The main repository */ static struct repository the_repo;struct repository *the_repository; +struct index_state the_index;void initialize_the_repository (void ) {
submodule.c +0 -1
@@ -1,4 +1,3 @@ -#define NO_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "repository.h"
t/helper/test-dump-fsmonitor.c +2 -2
@@ -3,11 +3,11 @@int cmd__dump_fsmonitor (int ac,const char **av) { -struct index_state *istate = &the_index; +struct index_state *istate = the_repository->index;int i;setup_git_directory (); -if (do_read_index (istate,get_index_file (),0 ) <0 ) +if (do_read_index (istate, the_repository->index_file,0 ) <0 )die ("unable to read index file" );if (!istate->fsmonitor_last_update) {printf ("no fsmonitor\n" );
t/helper/test-dump-untracked-cache.c +1 -0
@@ -1,3 +1,4 @@ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "test-tool.h" #include "cache.h" #include "dir.h"
t/helper/test-tool.h +1 -0
@@ -1,6 +1,7 @@#ifndef TEST_TOOL_H #define TEST_TOOL_H +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "git-compat-util.h" int cmd__chmtime (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.20.1.560.g70ca8b83ee
Quoted 3 lines · Nguyễn Thái Ngọc Duy
This was noticed by Ramsay [1] and I almost forgot.
Not forgetting is good ;-)
Quoted 9 lines
diff --git a/repository.c b/repository.c
--- a/repository.c
+++ b/repository.c
+@@
++/*
++ * not really _using_ the compat macros, just make sure the_index
++ * declaration matches the definition in this file.
++ */
++#define USE_THE_INDEX_COMPATIBILITY_MACROSHmph, that's an interesting trick.
Thanks, will replace.
Quoted 6 lines
+ #include "
cache.h"
+ #include "repository.h"
+ #include "object-store.h"
@@
/* The main repository */
static struct repositorythe_repo;