Skip to contentSkip to conversation

Kill the_index, final part

PATCH In review Nguyễn Thái Ngọc Duy 2 participants 22 messages Oct 19, 2018 – Oct 29, 2018

lore
Share & tools
lore
#0 lore raw

cover Kill the_index, final part

Stefan I see you start removing more references of the_repository in another series (haven't really looked at it yet) so this is just heads up so we could coordinate if needed. Still WIP, not really ready for review yet.

This series removes use of the_index outside builtin/ and t/helper/. The only the_index reference left is in repository.c. The macro NO_THE_REPOSITORY_COMPATIBILITY_MACROS is now flipped to USE_THE_INDEX_COMPATIBILITY_MACROS. "the_index" is forbidden by default.

After this I think we can start pushing the_repository outside library code. Then perhaps clean them up in builtin code too and you can finally get rid of it. But I don't think that'll happen in a year's time.

Nguyễn Thái Ngọc Duy (19):
wt-status.c: remove implicit dependency on the_index wt-status.c: remove implicit dependency the_repository list-objects-filter.c: remove implicit dependency on the_index list-objects.c: remove implicit dependency on the_index sequencer.c: remove implicit dependency on the_index sequencer.c: remove implicit dependency on the_repository notes-merge.c: remove implicit dependency on the_index notes-merge.c: remove implicit dependency the_repository repository.c: replace hold_locked_index() with repo_hold_locked_index()
checkout: avoid the_index when possible
read-cache.c: kill read_index()
read-cache.c: replace update_index_if_able with repo_& transport.c: remove implicit dependency on the_index sha1-name.c: remove implicit dependency on the_index merge-recursive.c: remove implicit dependency on the_index merge-recursive.c: remove implicit dependency on the_repository read-cache.c: remove the_* from index_has_changes() cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
Flip NO_THE_REPOSITORY_COMPATIBILITY_MACROS

 apply.c                              |   5 +-
 attr.c                               |   1 -
 blame.c                              |   4 +-
 builtin/add.c                        |   1 +
 builtin/am.c                         |  11 +-
 builtin/blame.c                      |   3 +-
 builtin/cat-file.c                   |   7 +-
 builtin/check-attr.c                 |   1 +
 builtin/check-ignore.c               |   1 +
 builtin/checkout-index.c             |   1 +
 builtin/checkout.c                   |   5 +-
 builtin/clean.c                      |   1 +
 builtin/clone.c                      |   1 +
 builtin/commit.c                     |  10 +-
 builtin/describe.c                   |   3 +-
 builtin/diff-files.c                 |   1 +
 builtin/diff-index.c                 |   1 +
 builtin/diff-tree.c                  |   3 +-
 builtin/diff.c                       |   3 +-
 builtin/difftool.c                   |   1 +
 builtin/fsck.c                       |   1 +
 builtin/grep.c                       |   4 +-
 builtin/hash-object.c                |   3 +-
 builtin/log.c                        |   4 +-
 builtin/ls-files.c                   |   1 -
 builtin/merge-index.c                |   1 +
 builtin/merge-ours.c                 |   1 +
 builtin/merge-recursive.c            |   2 +-
 builtin/merge-tree.c                 |   3 +-
 builtin/merge.c                      |   5 +-
 builtin/mv.c                         |   1 +
 builtin/notes.c                      |   2 +-
 builtin/pack-objects.c               |   2 +-
 builtin/pull.c                       |   4 +-
 builtin/push.c                       |   3 +-
 builtin/read-tree.c                  |   1 +
 builtin/rebase--helper.c             |  15 +-
 builtin/replace.c                    |   2 +-
 builtin/reset.c                      |   1 +
 builtin/rev-parse.c                  |   4 +-
 builtin/revert.c                     |   6 +-
 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                              |  35 +--
 convert.c                            |   1 -
 diff.h                               |   2 +-
 dir.c                                |   1 -
 git.c                                |   4 +-
 list-objects-filter-options.c        |   2 +-
 list-objects-filter.c                |   7 +-
 list-objects-filter.h                |   1 +
 list-objects.c                       |   3 +
 merge-recursive.c                    | 194 ++++++------
 merge-recursive.h                    |   6 +-
 merge.c                              |   4 +-
 name-hash.c                          |   1 -
 notes-merge.c                        |  16 +-
 notes-merge.h                        |   6 +-
 pathspec.c                           |   1 -
 preload-index.c                      |  11 +-
 read-cache.c                         |  44 ++-
 ref-filter.c                         |   2 +-
 repository.c                         |   9 +
 repository.h                         |  16 +
 rerere.c                             |   8 +-
 rerere.h                             |   2 +-
 revision.c                           |  12 +-
 revision.h                           |   2 +-
 sequencer.c                          | 435 +++++++++++++++------------
 sequencer.h                          |  27 +-
 sha1-name.c                          |  56 ++--
 submodule.c                          |   1 -
 t/helper/test-dump-fsmonitor.c       |   4 +-
 t/helper/test-dump-untracked-cache.c |   1 +
 t/helper/test-tool.h                 |   1 +
 transport.c                          |   7 +-
 transport.h                          |   3 +-
 tree.c                               |   1 -
 unpack-trees.c                       |   1 -
 wt-status.c                          |  97 +++---
 wt-status.h                          |  21 +-
 84 files changed, 673 insertions(+), 508 deletions(-)
Signature · 1 line
2.19.1.647.g708186aaf9
#1 lore raw

PATCH 1/19 wt-status.c: remove implicit dependency on the_index

---
 builtin/commit.c |  2 +-
 builtin/pull.c   |  3 +-
 sequencer.c      |  6 ++--
 wt-status.c      | 77 +++++++++++++++++++++++++++---------------------
 wt-status.h      | 17 +++++++----
 5 files changed, 62 insertions(+), 43 deletions(-)
builtin/commit.c +1 -1
index 074bd9a551..379d8c5cdf 100644
@@ -185,7 +185,7 @@ static void determine_whence(struct wt_status *s)
 
 static void status_init_config(struct wt_status *s, config_fn_t fn)
 {
-	wt_status_prepare(s);
+	wt_status_prepare(s, the_repository);
 	init_diff_ui_defaults();
 	git_config(fn, s);
 	determine_whence(s);
builtin/pull.c +2 -1
index 798ecf7faf..9b0fce07ca 100644
@@ -888,7 +888,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 			die(_("Updating an unborn branch with changes added to the index."));
 
 		if (!autostash)
-			require_clean_work_tree(N_("pull with rebase"),
+			require_clean_work_tree(the_repository,
+				N_("pull with rebase"),
 				_("please commit or stash them."), 1, 0);
 
 		if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs))
sequencer.c +3 -3
index 0c164d5f98..90435593a4 100644
@@ -2712,7 +2712,7 @@ static int do_exec(const char *command_line)
 	if (discard_cache() < 0 || read_cache() < 0)
 		return error(_("could not read index"));
 
-	dirty = require_clean_work_tree("rebase", NULL, 1, 1);
+	dirty = require_clean_work_tree(the_repository, "rebase", NULL, 1, 1);
 
 	if (status) {
 		warning(_("execution failed: %s\n%s"
@@ -3583,10 +3583,10 @@ static int commit_staged_changes(struct replay_opts *opts,
 	unsigned int flags = ALLOW_EMPTY | EDIT_MSG;
 	unsigned int final_fixup = 0, is_clean;
 
-	if (has_unstaged_changes(1))
+	if (has_unstaged_changes(the_repository, 1))
 		return error(_("cannot rebase: You have unstaged changes."));
 
-	is_clean = !has_uncommitted_changes(0);
+	is_clean = !has_uncommitted_changes(the_repository, 0);
 
 	if (file_exists(rebase_path_amend())) {
 		struct strbuf rev = STRBUF_INIT;
wt-status.c +44 -33

227 lines not on this page · raw message

wt-status.h +12 -5
index 1fcf93afbf..84653595e3 100644
@@ -7,6 +7,7 @@
 #include "pathspec.h"
 #include "remote.h"
 
+struct repository;
 struct worktree;
 
 enum color_wt_status {
@@ -83,6 +84,7 @@ struct wt_status_state {
 };
 
 struct wt_status {
+	struct repository *repo;
 	int is_initial;
 	char *branch;
 	const char *reference;
@@ -128,7 +130,7 @@ struct wt_status {
 
 size_t wt_status_locate_end(const char *s, size_t len);
 void wt_status_add_cut_line(FILE *fp);
-void wt_status_prepare(struct wt_status *s);
+void wt_status_prepare(struct wt_status *s, struct repository *repo);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 void wt_status_collect_free_buffers(struct wt_status *s);
@@ -144,9 +146,14 @@ __attribute__((format (printf, 3, 4)))
 void status_printf(struct wt_status *s, const char *color, const char *fmt, ...);
 
 /* The following functions expect that the caller took care of reading the index. */
-int has_unstaged_changes(int ignore_submodules);
-int has_uncommitted_changes(int ignore_submodules);
-int require_clean_work_tree(const char *action, const char *hint,
-	int ignore_submodules, int gently);
+int has_unstaged_changes(struct repository *repo,
+			 int ignore_submodules);
+int has_uncommitted_changes(struct repository *repo,
+			    int ignore_submodules);
+int require_clean_work_tree(struct repository *repo,
+			    const char *action,
+			    const char *hint,
+			    int ignore_submodules,
+			    int gently);
 
 #endif /* STATUS_H */
Signature · 1 line
2.19.1.647.g708186aaf9
#2 lore raw

PATCH 2/19 wt-status.c: remove implicit dependency the_repository

In reply to Nguyễn Thái Ngọc Duy
---
 ref-filter.c |  2 +-
 wt-status.c  | 18 ++++++++++--------
 wt-status.h  |  4 +++-
 3 files changed, 14 insertions(+), 10 deletions(-)
ref-filter.c +1 -1
index 2a05619211..d6d3923eb2 100644
@@ -1412,7 +1412,7 @@ char *get_head_description(void)
 	struct strbuf desc = STRBUF_INIT;
 	struct wt_status_state state;
 	memset(&state, 0, sizeof(state));
-	wt_status_get_state(&state, 1);
+	wt_status_get_state(the_repository, &state, 1);
 	if (state.rebase_in_progress ||
 	    state.rebase_interactive_in_progress) {
 		if (state.branch)
wt-status.c +10 -8
index 0378bc2a48..3632276236 100644
@@ -756,7 +756,7 @@ void wt_status_collect(struct wt_status *s)
 		wt_status_collect_changes_index(s);
 	wt_status_collect_untracked(s);
 
-	wt_status_get_state(&s->state, s->branch && !strcmp(s->branch, "HEAD"));
+	wt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, "HEAD"));
 	if (s->state.merge_in_progress && !has_unmerged(s))
 		s->committable = 1;
 }
@@ -1483,7 +1483,8 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
 	return 1;
 }
 
-static void wt_status_get_detached_from(struct wt_status_state *state)
+static void wt_status_get_detached_from(struct repository *r,
+					struct wt_status_state *state)
 {
 	struct grab_1st_switch_cbdata cb;
 	struct commit *commit;
@@ -1500,7 +1501,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
 	    /* sha1 is a commit? match without further lookup */
 	    (oideq(&cb.noid, &oid) ||
 	     /* perhaps sha1 is a tag, try to dereference to a commit */
-	     ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
+	     ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&
 	      oideq(&cb.noid, &commit->object.oid)))) {
 		const char *from = ref;
 		if (!skip_prefix(from, "refs/tags/", &from))
@@ -1557,30 +1558,31 @@ int wt_status_check_bisect(const struct worktree *wt,
 	return 0;
 }
 
-void wt_status_get_state(struct wt_status_state *state,
+void wt_status_get_state(struct repository *r,
+			 struct wt_status_state *state,
 			 int get_detached_from)
 {
 	struct stat st;
 	struct object_id oid;
 
-	if (!stat(git_path_merge_head(the_repository), &st)) {
+	if (!stat(git_path_merge_head(r), &st)) {
 		state->merge_in_progress = 1;
 	} else if (wt_status_check_rebase(NULL, state)) {
 		;		/* all set */
-	} else if (!stat(git_path_cherry_pick_head(the_repository), &st) &&
+	} else if (!stat(git_path_cherry_pick_head(r), &st) &&
 			!get_oid("CHERRY_PICK_HEAD", &oid)) {
 		state->cherry_pick_in_progress = 1;
 		oidcpy(&state->cherry_pick_head_oid, &oid);
 	}
 	wt_status_check_bisect(NULL, state);
-	if (!stat(git_path_revert_head(the_repository), &st) &&
+	if (!stat(git_path_revert_head(r), &st) &&
 	    !get_oid("REVERT_HEAD", &oid)) {
 		state->revert_in_progress = 1;
 		oidcpy(&state->revert_head_oid, &oid);
 	}
 
 	if (get_detached_from)
-		wt_status_get_detached_from(state);
+		wt_status_get_detached_from(r, state);
 }
 
 static void wt_longstatus_print_state(struct wt_status *s)
wt-status.h +3 -1
index 84653595e3..9dde7091f6 100644
@@ -134,7 +134,9 @@ void wt_status_prepare(struct wt_status *s, struct repository *repo);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
 void wt_status_collect_free_buffers(struct wt_status *s);
-void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
+void wt_status_get_state(struct repository *repo,
+			 struct wt_status_state *state,
+			 int get_detached_from);
 int wt_status_check_rebase(const struct worktree *wt,
 			   struct wt_status_state *state);
 int wt_status_check_bisect(const struct worktree *wt,
Signature · 1 line
2.19.1.647.g708186aaf9
#3 lore raw

PATCH 3/19 list-objects-filter.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy
---
 list-objects-filter.c | 7 +++++--
 list-objects-filter.h | 1 +
 list-objects.c        | 3 +++
 3 files changed, 9 insertions(+), 2 deletions(-)
list-objects-filter.c +5 -2
index a0ba78b20c..8825e2a5ab 100644
@@ -38,6 +38,7 @@ static enum list_objects_filter_result filter_blobs_none(
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
+	struct index_state *istate,
 	void *filter_data_)
 {
 	struct filter_blobs_none_data *filter_data = filter_data_;
@@ -94,6 +95,7 @@ static enum list_objects_filter_result filter_blobs_limit(
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
+	struct index_state *istate,
 	void *filter_data_)
 {
 	struct filter_blobs_limit_data *filter_data = filter_data_;
@@ -200,6 +202,7 @@ static enum list_objects_filter_result filter_sparse(
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
+	struct index_state *istate,
 	void *filter_data_)
 {
 	struct filter_sparse_data *filter_data = filter_data_;
@@ -216,7 +219,7 @@ static enum list_objects_filter_result filter_sparse(
 		dtype = DT_DIR;
 		val = is_excluded_from_list(pathname, strlen(pathname),
 					    filename, &dtype, &filter_data->el,
-					    &the_index);
+					    istate);
 		if (val < 0)
 			val = filter_data->array_frame[filter_data->nr].defval;
 
@@ -279,7 +282,7 @@ static enum list_objects_filter_result filter_sparse(
 		dtype = DT_REG;
 		val = is_excluded_from_list(pathname, strlen(pathname),
 					    filename, &dtype, &filter_data->el,
-					    &the_index);
+					    istate);
 		if (val < 0)
 			val = frame->defval;
 		if (val > 0) {
list-objects-filter.h +1 -0
index a6f6b4990b..dfa29595d1 100644
@@ -58,6 +58,7 @@ typedef enum list_objects_filter_result (*filter_object_fn)(
 	struct object *obj,
 	const char *pathname,
 	const char *filename,
+	struct index_state *istate,
 	void *filter_data);
 
 typedef void (*filter_free_fn)(void *filter_data);
list-objects.c +3 -0
index 0c2989d5ca..f9d36dabf2 100644
@@ -51,6 +51,7 @@ static void process_blob(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn)
 		r = filter_fn(LOFS_BLOB, obj,
 			      path->buf, &path->buf[pathlen],
+			      &the_index,
 			      filter_data);
 	if (r & LOFR_MARK_SEEN)
 		obj->flags |= SEEN;
@@ -136,6 +137,7 @@ static void process_tree(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn)
 		r = filter_fn(LOFS_BEGIN_TREE, obj,
 			      base->buf, &base->buf[baselen],
+			      &the_index,
 			      filter_data);
 	if (r & LOFR_MARK_SEEN)
 		obj->flags |= SEEN;
@@ -175,6 +177,7 @@ static void process_tree(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn) {
 		r = filter_fn(LOFS_END_TREE, obj,
 			      base->buf, &base->buf[baselen],
+			      &the_index,
 			      filter_data);
 		if (r & LOFR_MARK_SEEN)
 			obj->flags |= SEEN;
Signature · 1 line
2.19.1.647.g708186aaf9
#4 lore raw

PATCH 4/19 list-objects.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy
---
 list-objects.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
list-objects.c +3 -3
index f9d36dabf2..c3a1a9b004 100644
@@ -51,7 +51,7 @@ static void process_blob(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn)
 		r = filter_fn(LOFS_BLOB, obj,
 			      path->buf, &path->buf[pathlen],
-			      &the_index,
+			      revs->repo->index,
 			      filter_data);
 	if (r & LOFR_MARK_SEEN)
 		obj->flags |= SEEN;
@@ -137,7 +137,7 @@ static void process_tree(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn)
 		r = filter_fn(LOFS_BEGIN_TREE, obj,
 			      base->buf, &base->buf[baselen],
-			      &the_index,
+			      revs->repo->index,
 			      filter_data);
 	if (r & LOFR_MARK_SEEN)
 		obj->flags |= SEEN;
@@ -177,7 +177,7 @@ static void process_tree(struct rev_info *revs,
 	if (!(obj->flags & USER_GIVEN) && filter_fn) {
 		r = filter_fn(LOFS_END_TREE, obj,
 			      base->buf, &base->buf[baselen],
-			      &the_index,
+			      revs->repo->index,
 			      filter_data);
 		if (r & LOFR_MARK_SEEN)
 			obj->flags |= SEEN;
Signature · 1 line
2.19.1.647.g708186aaf9
#6 lore raw

PATCH 6/19 sequencer.c: remove implicit dependency on the_repository

In reply to Nguyễn Thái Ngọc Duy

Note that the_hash_algo stays, even if we can easily replace it with repo->hash_algo. My reason is I still believe tying hash_algo to a struct repository is a wrong move. But if I'm wrong, we can always go for another round of conversion.

---
 builtin/rebase--helper.c |  10 ++--
 builtin/revert.c         |   2 +-
 sequencer.c              | 108 +++++++++++++++++++++------------------
 sequencer.h              |  12 ++---
 4 files changed, 70 insertions(+), 62 deletions(-)
builtin/rebase--helper.c +5 -5
index b66cd8cd41..605fcaa89c 100644
@@ -76,14 +76,14 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!sequencer_make_script(the_repository, stdout,
 					       argc, argv, flags);
 	if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
-		return !!transform_todos(flags);
+		return !!transform_todos(the_repository, flags);
 	if (command == CHECK_TODO_LIST && argc == 1)
-		return !!check_todo_list();
+		return !!check_todo_list(the_repository);
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
-		return !!skip_unnecessary_picks();
+		return !!skip_unnecessary_picks(the_repository);
 	if (command == REARRANGE_SQUASH && argc == 1)
-		return !!rearrange_squash();
+		return !!rearrange_squash(the_repository);
 	if (command == ADD_EXEC && argc == 2)
-		return !!sequencer_add_exec_commands(argv[1]);
+		return !!sequencer_add_exec_commands(the_repository, argv[1]);
 	usage_with_options(builtin_rebase_helper_usage, options);
 }
builtin/revert.c +1 -1
index cd9f068195..1fa75b2773 100644
@@ -201,7 +201,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 	if (cmd == 'c')
 		return sequencer_continue(the_repository, opts);
 	if (cmd == 'a')
-		return sequencer_rollback(opts);
+		return sequencer_rollback(the_repository, opts);
 	return sequencer_pick_revisions(the_repository, opts);
 }
 
sequencer.c +58 -50

357 lines not on this page · raw message

sequencer.h +6 -6
index ad151e95c7..1232157da2 100644
@@ -68,7 +68,7 @@ void sequencer_init_config(struct replay_opts *opts);
 int sequencer_pick_revisions(struct repository *repo,
 			     struct replay_opts *opts);
 int sequencer_continue(struct repository *repo, struct replay_opts *opts);
-int sequencer_rollback(struct replay_opts *opts);
+int sequencer_rollback(struct repository *repo, struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
 #define TODO_LIST_KEEP_EMPTY (1U << 0)
@@ -85,11 +85,11 @@ int sequencer_make_script(struct repository *repo, FILE *out,
 			  int argc, const char **argv,
 			  unsigned flags);
 
-int sequencer_add_exec_commands(const char *command);
-int transform_todos(unsigned flags);
-int check_todo_list(void);
-int skip_unnecessary_picks(void);
-int rearrange_squash(void);
+int sequencer_add_exec_commands(struct repository *repo, const char *command);
+int transform_todos(struct repository *repo, unsigned flags);
+int check_todo_list(struct repository *repo);
+int skip_unnecessary_picks(struct repository *repo);
+int rearrange_squash(struct repository *repo);
 
 extern const char sign_off_header[];
 
Signature · 1 line
2.19.1.647.g708186aaf9
#5 lore raw

PATCH 5/19 sequencer.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy

Since we're going to pass 'struct repository *' around most of the time instead of 'struct index_state *' because most sequencer.c operations need more than just the index, the_repository is replaced as well in the functions that now take 'struct repository *'. the_repository is still present in this file, but total clean up will be done later. It's not the main focus of this patch.

---
 builtin/commit.c         |   3 +-
 builtin/merge.c          |   2 +-
 builtin/rebase--helper.c |   5 +-
 builtin/revert.c         |   4 +-
 sequencer.c              | 319 ++++++++++++++++++++++-----------------
 sequencer.h              |  15 +-
 6 files changed, 197 insertions(+), 151 deletions(-)
builtin/commit.c +2 -1
index 379d8c5cdf..f7bbba944d 100644
@@ -1679,7 +1679,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			flags |= SUMMARY_INITIAL_COMMIT;
 		if (author_date_is_interesting())
 			flags |= SUMMARY_SHOW_AUTHOR_DATE;
-		print_commit_summary(prefix, &oid, flags);
+		print_commit_summary(the_repository, prefix,
+				     &oid, flags);
 	}
 
 	UNLEAK(err);
builtin/merge.c +1 -1
index 4aa6071598..db22119c93 100644
@@ -896,7 +896,7 @@ static int suggest_conflicts(void)
 	filename = git_path_merge_msg(the_repository);
 	fp = xfopen(filename, "a");
 
-	append_conflicts_hint(&msgbuf);
+	append_conflicts_hint(&the_index, &msgbuf);
 	fputs(msgbuf.buf, fp);
 	strbuf_release(&msgbuf);
 	fclose(fp);
builtin/rebase--helper.c +3 -2
index f7c2a5fdc8..b66cd8cd41 100644
@@ -69,11 +69,12 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			  "--rebase-merges"));
 
 	if (command == CONTINUE && argc == 1)
-		return !!sequencer_continue(&opts);
+		return !!sequencer_continue(the_repository, &opts);
 	if (command == ABORT && argc == 1)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(stdout, argc, argv, flags);
+		return !!sequencer_make_script(the_repository, stdout,
+					       argc, argv, flags);
 	if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
 		return !!transform_todos(flags);
 	if (command == CHECK_TODO_LIST && argc == 1)
builtin/revert.c +2 -2
index c93393c89b..cd9f068195 100644
@@ -199,10 +199,10 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
 		return ret;
 	}
 	if (cmd == 'c')
-		return sequencer_continue(opts);
+		return sequencer_continue(the_repository, opts);
 	if (cmd == 'a')
 		return sequencer_rollback(opts);
-	return sequencer_pick_revisions(opts);
+	return sequencer_pick_revisions(the_repository, opts);
 }
 
 int cmd_revert(int argc, const char **argv, const char *prefix)
sequencer.c +179 -140

901 lines not on this page · raw message

sequencer.h +10 -5
index c986bc8251..ad151e95c7 100644
@@ -5,6 +5,7 @@
 #include "strbuf.h"
 
 struct commit;
+struct repository;
 
 const char *git_path_commit_editmsg(void);
 const char *git_path_seq_dir(void);
@@ -64,8 +65,9 @@ struct replay_opts {
 
 /* Call this to setup defaults before parsing command line options */
 void sequencer_init_config(struct replay_opts *opts);
-int sequencer_pick_revisions(struct replay_opts *opts);
-int sequencer_continue(struct replay_opts *opts);
+int sequencer_pick_revisions(struct repository *repo,
+			     struct replay_opts *opts);
+int sequencer_continue(struct repository *repo, struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
@@ -79,7 +81,8 @@ int sequencer_remove_state(struct replay_opts *opts);
  * commits should be rebased onto the new base, this flag needs to be passed.
  */
 #define TODO_LIST_REBASE_COUSINS (1U << 4)
-int sequencer_make_script(FILE *out, int argc, const char **argv,
+int sequencer_make_script(struct repository *repo, FILE *out,
+			  int argc, const char **argv,
 			  unsigned flags);
 
 int sequencer_add_exec_commands(const char *command);
@@ -98,7 +101,7 @@ extern const char sign_off_header[];
  */
 void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag);
 
-void append_conflicts_hint(struct strbuf *msgbuf);
+void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf);
 int message_is_empty(const struct strbuf *sb,
 		     enum commit_msg_cleanup_mode cleanup_mode);
 int template_untouched(const struct strbuf *sb, const char *template_file,
@@ -112,6 +115,8 @@ void commit_post_rewrite(const struct commit *current_head,
 
 #define SUMMARY_INITIAL_COMMIT   (1 << 0)
 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)
-void print_commit_summary(const char *prefix, const struct object_id *oid,
+void print_commit_summary(struct repository *repo,
+			  const char *prefix,
+			  const struct object_id *oid,
 			  unsigned int flags);
 #endif
Signature · 1 line
2.19.1.647.g708186aaf9
#8 lore raw

PATCH 8/19 notes-merge.c: remove implicit dependency the_repository

In reply to Nguyễn Thái Ngọc Duy
---
 notes-merge.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
notes-merge.c +2 -2
index c3bee1a87d..b6a998bfd4 100644
@@ -558,7 +558,7 @@ int notes_merge(struct notes_merge_options *o,
 	else if (!check_refname_format(o->local_ref, 0) &&
 		is_null_oid(&local_oid))
 		local = NULL; /* local_oid == null_oid indicates unborn ref */
-	else if (!(local = lookup_commit_reference(the_repository, &local_oid)))
+	else if (!(local = lookup_commit_reference(o->repo, &local_oid)))
 		die("Could not parse local commit %s (%s)",
 		    oid_to_hex(&local_oid), o->local_ref);
 	trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid));
@@ -576,7 +576,7 @@ int notes_merge(struct notes_merge_options *o,
 			die("Failed to resolve remote notes ref '%s'",
 			    o->remote_ref);
 		}
-	} else if (!(remote = lookup_commit_reference(the_repository, &remote_oid))) {
+	} else if (!(remote = lookup_commit_reference(o->repo, &remote_oid))) {
 		die("Could not parse remote commit %s (%s)",
 		    oid_to_hex(&remote_oid), o->remote_ref);
 	}
Signature · 1 line
2.19.1.647.g708186aaf9
#7 lore raw

PATCH 7/19 notes-merge.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy
---
 builtin/notes.c |  2 +-
 notes-merge.c   | 12 +++++++-----
 notes-merge.h   |  6 +++++-
 3 files changed, 13 insertions(+), 7 deletions(-)
builtin/notes.c +1 -1
index c05cd004ab..d8bd01656a 100644
@@ -808,7 +808,7 @@ static int merge(int argc, const char **argv, const char *prefix)
 		usage_with_options(git_notes_merge_usage, options);
 	}
 
-	init_notes_merge_options(&o);
+	init_notes_merge_options(&o, the_repository);
 	o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
 
 	if (do_abort)
notes-merge.c +7 -5
index bd05d50b05..c3bee1a87d 100644
@@ -18,11 +18,13 @@ struct notes_merge_pair {
 	struct object_id obj, base, local, remote;
 };
 
-void init_notes_merge_options(struct notes_merge_options *o)
+void init_notes_merge_options(struct notes_merge_options *o,
+			      struct repository *repo)
 {
 	memset(o, 0, sizeof(struct notes_merge_options));
 	strbuf_init(&(o->commit_msg), 0);
 	o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT;
+	o->repo = repo;
 }
 
 static int path_to_oid(const char *path, struct object_id *oid)
@@ -127,7 +129,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
 	trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n",
 	       oid_to_hex(base), oid_to_hex(remote));
 
-	repo_diff_setup(the_repository, &opt);
+	repo_diff_setup(o->repo, &opt);
 	opt.flags.recursive = 1;
 	opt.output_format = DIFF_FORMAT_NO_OUTPUT;
 	diff_setup_done(&opt);
@@ -190,7 +192,7 @@ static void diff_tree_local(struct notes_merge_options *o,
 	trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n",
 	       len, oid_to_hex(base), oid_to_hex(local));
 
-	repo_diff_setup(the_repository, &opt);
+	repo_diff_setup(o->repo, &opt);
 	opt.flags.recursive = 1;
 	opt.output_format = DIFF_FORMAT_NO_OUTPUT;
 	diff_setup_done(&opt);
@@ -350,7 +352,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,
 
 	status = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,
 			  &local, o->local_ref, &remote, o->remote_ref,
-			  &the_index, NULL);
+			  o->repo->index, NULL);
 
 	free(base.ptr);
 	free(local.ptr);
@@ -711,7 +713,7 @@ int notes_merge_commit(struct notes_merge_options *o,
 		/* write file as blob, and add to partial_tree */
 		if (stat(path.buf, &st))
 			die_errno("Failed to stat '%s'", path.buf);
-		if (index_path(&the_index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
+		if (index_path(o->repo->index, &blob_oid, path.buf, &st, HASH_WRITE_OBJECT))
 			die("Failed to write blob object from '%s'", path.buf);
 		if (add_note(partial_tree, &obj_oid, &blob_oid, NULL))
 			die("Failed to add resolved note '%s' to notes tree",
notes-merge.h +5 -1
index 6c74e9385b..fe70cbd5e8 100644
@@ -7,6 +7,8 @@
 struct commit;
 struct object_id;
 
+struct repository;
+
 #define NOTES_MERGE_WORKTREE "NOTES_MERGE_WORKTREE"
 
 enum notes_merge_verbosity {
@@ -15,6 +17,7 @@ enum notes_merge_verbosity {
 };
 
 struct notes_merge_options {
+	struct repository *repo;
 	const char *local_ref;
 	const char *remote_ref;
 	struct strbuf commit_msg;
@@ -23,7 +26,8 @@ struct notes_merge_options {
 	unsigned has_worktree:1;
 };
 
-void init_notes_merge_options(struct notes_merge_options *o);
+void init_notes_merge_options(struct notes_merge_options *o,
+			      struct repository *repo);
 
 /*
  * Merge notes from o->remote_ref into o->local_ref
Signature · 1 line
2.19.1.647.g708186aaf9
#9 lore raw

PATCH 9/19 repository.c: replace hold_locked_index() with repo_hold_locked_index()

In reply to Nguyễn Thái Ngọc Duy

hold_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 ++-
 builtin/clone.c   | 1 +
 cache.h           | 2 +-
 merge-recursive.c | 2 +-
 merge.c           | 2 +-
 read-cache.c      | 5 -----
 repository.c      | 8 ++++++++
 repository.h      | 4 ++++
 rerere.c          | 2 +-
 sequencer.c       | 8 ++++----
 wt-status.c       | 2 +-
 11 files changed, 24 insertions(+), 15 deletions(-)
apply.c +2 -1
index fdae1d423b..122e6ddf92 100644
@@ -4710,7 +4710,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) {
builtin/clone.c +1 -0
index 15b142d646..dfefe85770 100644
@@ -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"
cache.h +1 -1
index 59c8a93046..ef2483ce45 100644
@@ -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
@@ -826,7 +827,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
index c0fb83d285..c186812ff2 100644
@@ -3510,7 +3510,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
index 91008f7602..dbbc9d9f80 100644
@@ -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
index 1df5c16dbc..7ad3330942 100644
@@ -1726,11 +1726,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 +8 -0
index 5dd1486718..39b5a80d43 100644
@@ -3,6 +3,7 @@
 #include "object-store.h"
 #include "config.h"
 #include "object.h"
+#include "lockfile.h"
 #include "submodule-config.h"
 
 /* The main repository */
@@ -257,3 +258,10 @@ 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)
+{
+	return hold_lock_file_for_update(lf, repo->index_file, flags);
+}
repository.h +4 -0
index 9f16c42c1e..968330218f 100644
@@ -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
index 887e26d45b..13927de7e0 100644
@@ -702,7 +702,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 +4 -4
index 2c2ea2b45d..ced05cd73d 100644
@@ -535,7 +535,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);
@@ -1935,7 +1935,7 @@ 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);
+	int index_fd = repo_hold_locked_index(r, &index_lock, 0);
 	if (read_index_preload(r->index, NULL, 0) < 0) {
 		rollback_lock_file(&index_lock);
 		return error(_("git %s: failed to read the index"),
@@ -2866,7 +2866,7 @@ static int do_reset(struct repository *r,
 	struct unpack_trees_options unpack_tree_opts;
 	int ret = 0, i;
 
-	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)) {
@@ -2981,7 +2981,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
index 3632276236..da28921772 100644
@@ -2371,7 +2371,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.19.1.647.g708186aaf9
#10 lore raw

PATCH 10/19 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
index acdafc6e4c..38b28c20e2 100644
@@ -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.19.1.647.g708186aaf9
#12 lore raw

PATCH 12/19 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 +-
 cache.h            |  6 ------
 read-cache.c       | 14 ++++++++------
 repository.h       |  6 ++++++
 wt-status.c        |  2 +-
 7 files changed, 18 insertions(+), 16 deletions(-)
builtin/commit.c +1 -1
index 7eda5e4b7e..d7afaa9ed4 100644
@@ -1392,7 +1392,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
index c48c34e866..cff8ec3d65 100644
@@ -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
index f0393bba23..ec78920ee2 100644
@@ -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)
cache.h +0 -6
index d9303ae25f..73bf68d8a5 100644
@@ -816,12 +816,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
index 8844f723e9..46e5e4000a 100644
@@ -2661,9 +2661,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)
@@ -2679,11 +2679,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
index cc3879add4..6fe1c089db 100644
@@ -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
index da28921772..bdc4c36f93 100644
@@ -2374,7 +2374,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.19.1.647.g708186aaf9
#13 lore raw

PATCH 13/19 transport.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy

note, there's still another hidden dependency related to this: even though we pass a repo to transport_push() we still use is_bare_repository() which pretty much assumes the_repository (and some other global state).

---
 builtin/push.c | 3 ++-
 transport.c    | 7 ++++---
 transport.h    | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)
builtin/push.c +2 -1
index d09a42062c..efb3e38a8d 100644
@@ -355,7 +355,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs,
 
 	if (verbosity > 0)
 		fprintf(stderr, _("Pushing to %s\n"), transport->url);
-	err = transport_push(transport, rs, flags, &reject_reasons);
+	err = transport_push(the_repository, transport,
+			     rs, flags, &reject_reasons);
 	if (err != 0) {
 		fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR));
 		error(_("failed to push some refs to '%s'"), transport->url);
transport.c +4 -3
index f4ffbd96cb..b86b2b12c6 100644
@@ -1105,7 +1105,8 @@ static int run_pre_push_hook(struct transport *transport,
 	return ret;
 }
 
-int transport_push(struct transport *transport,
+int transport_push(struct repository *repo,
+		   struct transport *transport,
 		   struct refspec *rs, int flags,
 		   unsigned int *reject_reasons)
 {
@@ -1172,7 +1173,7 @@ int transport_push(struct transport *transport,
 					oid_array_append(&commits,
 							  &ref->new_oid);
 
-			if (!push_unpushed_submodules(&the_index,
+			if (!push_unpushed_submodules(repo->index,
 						      &commits,
 						      transport->remote,
 						      rs,
@@ -1197,7 +1198,7 @@ int transport_push(struct transport *transport,
 					oid_array_append(&commits,
 							  &ref->new_oid);
 
-			if (find_unpushed_submodules(&the_index,
+			if (find_unpushed_submodules(repo->index,
 						     &commits,
 						     transport->remote->name,
 						     &needs_pushing)) {
transport.h +2 -1
index 9baeca2d7a..f2ee7c4f49 100644
@@ -223,7 +223,8 @@ void transport_set_verbosity(struct transport *transport, int verbosity,
 #define REJECT_FETCH_FIRST     0x08
 #define REJECT_NEEDS_FORCE     0x10
 
-int transport_push(struct transport *connection,
+int transport_push(struct repository *repo,
+		   struct transport *connection,
 		   struct refspec *rs, int flags,
 		   unsigned int * reject_reasons);
 
Signature · 1 line
2.19.1.647.g708186aaf9
#11 lore raw

PATCH 11/19 read-cache.c: kill read_index()

In reply to Nguyễn Thái Ngọc Duy

read_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 +-
 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         | 22 +++++++++++-----------
 sha1-name.c         |  6 +++---
 15 files changed, 46 insertions(+), 47 deletions(-)
apply.c +1 -1
index 122e6ddf92..f5d507a64f 100644
@@ -4017,7 +4017,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
index d84c937780..6e3de62379 100644
@@ -183,7 +183,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(the_repository);
 	commit->object.parsed = 1;
@@ -265,7 +265,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
index 3ee9a9d2a9..d2af94500c 100644
@@ -2328,7 +2328,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
index f7bbba944d..7eda5e4b7e 100644
@@ -1363,7 +1363,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_preload(&the_index, &s.pathspec, progress_flag);
+	repo_read_index_preload(the_repository, &s.pathspec, progress_flag);
 	refresh_index(&the_index,
 		      REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
 		      &s.pathspec, NULL, NULL);
builtin/diff-tree.c +1 -1
index ef996126d7..42bc1eb41d 100644
@@ -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)) {
cache.h +3 -8
index ef2483ce45..d9303ae25f 100644
@@ -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))
@@ -659,16 +659,11 @@ extern int daemonize(void);
 
 /* Initialize and use the cache information */
 struct lock_file;
-extern int read_index(struct index_state *);
-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
index c186812ff2..b025c10e31 100644
@@ -3443,7 +3443,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
index dbbc9d9f80..7c1d756c3f 100644
@@ -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
index 9e7152ab14..5327c59923 100644
@@ -7,6 +7,7 @@
 #include "fsmonitor.h"
 #include "config.h"
 #include "progress.h"
+#include "repository.h"
 
 #ifdef NO_PTHREADS
 static void preload_index(struct index_state *index,
@@ -153,12 +154,12 @@ static void preload_index(struct index_state *index,
 }
 #endif
 
-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
index 7ad3330942..8844f723e9 100644
@@ -1726,11 +1726,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,
@@ -3196,12 +3191,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
index 968330218f..cc3879add4 100644
@@ -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
index 13927de7e0..7abf7c8d41 100644
@@ -558,7 +558,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;) {
@@ -592,7 +592,7 @@ int rerere_remaining(struct repository *r, struct string_list *merge_rr)
 
 	if (setup_rerere(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;) {
@@ -1104,7 +1104,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(&merge_rr, RERERE_NOAUTOUPDATE);
revision.c +2 -2
index b5108b75ab..3138c11ec5 100644
@@ -1372,7 +1372,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);
 
 	if (revs->single_worktree)
@@ -1518,7 +1518,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 +11 -11
index ced05cd73d..3620a42649 100644
@@ -441,9 +441,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."),
@@ -478,7 +478,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 */
 
@@ -538,7 +538,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)";
@@ -1709,7 +1709,7 @@ static int do_pick_commit(struct repository *r,
 			oidcpy(&head, the_hash_algo->empty_tree);
 		if (index_differs_from(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);
 
@@ -1936,7 +1936,7 @@ static int read_and_refresh_cache(struct repository *r,
 {
 	struct lock_file index_lock = LOCK_INIT;
 	int index_fd = repo_hold_locked_index(r, &index_lock, 0);
-	if (read_index_preload(r->index, NULL, 0) < 0) {
+	if (repo_read_index_preload(r, NULL, 0) < 0) {
 		rollback_lock_file(&index_lock);
 		return error(_("git %s: failed to read the index"),
 			_(action_name(opts)));
@@ -2742,7 +2742,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);
@@ -2908,7 +2908,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)));
@@ -3162,7 +3162,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;
 	}
@@ -3184,7 +3184,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;
@@ -3785,7 +3785,7 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
 				goto release_todo_list;
 		}
 		if (index_differs_from("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
index faa60f69e3..8669ad0b47 100644
@@ -1749,9 +1749,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.19.1.647.g708186aaf9
#14 lore raw

PATCH 14/19 sha1-name.c: remove implicit dependency on the_index

In reply to Nguyễn Thái Ngọc Duy

This 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
index 8d97c84725..17faea8846 100644
@@ -66,7 +66,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);
 
@@ -374,7 +375,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
index d8508ddf79..9d40b5c073 100644
@@ -1006,7 +1006,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
index 061d4fd864..ed28e81a22 100644
@@ -506,7 +506,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
index 455f62246d..38d7d8fd74 100644
@@ -932,7 +932,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
index 73bf68d8a5..91c092cf76 100644
@@ -1327,7 +1327,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
index c0e2bd6a06..a683a75a35 100644
@@ -59,7 +59,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
index 3138c11ec5..ebbf382e3f 100644
@@ -1577,8 +1577,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) {
@@ -1712,7 +1712,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 	if (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);
@@ -2440,7 +2440,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		struct 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.19.1.647.g708186aaf9
#16 lore raw

PATCH 16/19 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
index 184945ae67..ad0a5b0202 100644
@@ -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;
@@ -420,7 +423,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;
 }
@@ -1200,9 +1203,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;
 	}
@@ -3286,8 +3289,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)) {
@@ -3423,8 +3426,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) {
@@ -3468,7 +3471,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);
 	}
@@ -3481,17 +3484,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))
@@ -3508,15 +3511,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.19.1.647.g708186aaf9
#15 lore raw

PATCH 15/19 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         | 151 +++++++++++++++++++++-----------------
 merge-recursive.h         |   6 +-
 sequencer.c               |   4 +-
 7 files changed, 94 insertions(+), 75 deletions(-)
builtin/am.c +1 -1
index d2af94500c..65e10a5eb3 100644
@@ -1597,7 +1597,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
index 38b28c20e2..8ecb4c43c7 100644
@@ -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
index 9b2f707c29..4864f7b22f 100644
@@ -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
index db22119c93..d2d636d979 100644
@@ -701,7 +701,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 +83 -68

471 lines not on this page · raw message

merge-recursive.h +5 -1
index e6a0828eca..c2b7bb65c6 100644
@@ -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
index 3620a42649..c5073e0b92 100644
@@ -540,7 +540,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)";
@@ -3185,7 +3185,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.19.1.647.g708186aaf9
#17 lore raw

PATCH 17/19 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
index 65e10a5eb3..37b52be7db 100644
@@ -1771,7 +1771,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);
 	}
@@ -1829,7 +1829,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;
 			}
@@ -1883,7 +1883,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
index 91c092cf76..4b3ec4ff82 100644
@@ -701,9 +701,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
index ad0a5b0202..22b382e85f 100644
@@ -3282,7 +3282,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
index 46e5e4000a..19389c6f30 100644
@@ -2372,22 +2372,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.19.1.647.g708186aaf9
#19 lore raw

PATCH 19/19 Flip NO_THE_REPOSITORY_COMPATIBILITY_MACROS

In reply to Nguyễn Thái Ngọc Duy

Similar to NO_THE_INDEX_COMPATIBILITY_MACROS, this switch is now off by default. It remains here just to make it easier to merge in-flight topics where the old functions are still used. Then you can just stick

    #define USE_THE_REPOSITORY_COMPATIBILITY_MACROS

at the beginning of those files.

---
 diff.h     | 2 +-
 rerere.h   | 2 +-
 revision.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
diff.h +1 -1
index ce5e8a8183..de7cb7018f 100644
@@ -341,7 +341,7 @@ int git_diff_basic_config(const char *var, const char *value, void *cb);
 int git_diff_heuristic_config(const char *var, const char *value, void *cb);
 void init_diff_ui_defaults(void);
 int git_diff_ui_config(const char *var, const char *value, void *cb);
-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS
 #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
 #endif
 void repo_diff_setup(struct repository *, struct diff_options *);
rerere.h +1 -1
index 5ad8864b3c..8ddd0b20da 100644
@@ -24,7 +24,7 @@ struct rerere_id {
 };
 
 int setup_rerere(struct string_list *, int);
-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS
 #define rerere(flags) repo_rerere(the_repository, flags)
 #endif
 int repo_rerere(struct repository *, int);
revision.h +1 -1
index bc30a3023e..5b6ab10143 100644
@@ -271,7 +271,7 @@ struct setup_revision_opt {
 	unsigned revarg_opt;
 };
 
-#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
+#ifdef USE_THE_REPOSITORY_COMPATIBILITY_MACROS
 #define init_revisions(revs, prefix) repo_init_revisions(the_repository, revs, prefix)
 #endif
 void repo_init_revisions(struct repository *r,
Signature · 1 line
2.19.1.647.g708186aaf9
#18 lore raw

PATCH 18/19 cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch

In reply to Nguyễn Thái Ngọc Duy

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).

---
 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/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                 | 3 ++-
 builtin/merge.c                      | 1 +
 builtin/mv.c                         | 1 +
 builtin/pack-objects.c               | 2 +-
 builtin/pull.c                       | 1 +
 builtin/read-tree.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                         | 1 +
 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 -
 52 files changed, 49 insertions(+), 24 deletions(-)
attr.c +0 -1
index 60d284796d..e56ffa9112 100644
@@ -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
index ad49806ebf..72e9765edf 100644
@@ -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
index 37b52be7db..4e36c186fc 100644
@@ -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
index a443af9ee9..d004343211 100644
@@ -1001,7 +1001,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
index 17faea8846..72be3e8065 100644
@@ -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
index 30a2f84274..dd83397786 100644
@@ -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
index ec9a959e08..599097304b 100644
@@ -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
index 88b86c8d9f..2f820910b7 100644
@@ -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
index 8ecb4c43c7..b1ed49d020 100644
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "config.h"
 #include "checkout.h"
builtin/clean.c +1 -0
index 8d9a7dc206..7e21380200 100644
@@ -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
index d7afaa9ed4..9ba55b2653 100644
@@ -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
index cff8ec3d65..d673ba197d 100644
@@ -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
index 48cfcb935d..86ae474fbf 100644
@@ -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
index fcccd1f10d..93ec642423 100644
@@ -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
index 42bc1eb41d..a90681bcba 100644
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
builtin/diff.c +1 -0
index ec78920ee2..74351a5757 100644
@@ -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
index 544b0e8639..eeb9e370b9 100644
@@ -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
index 06eb421720..916f14e634 100644
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "cache.h"
 #include "repository.h"
builtin/grep.c +1 -0
index 9d40b5c073..75543fe458 100644
@@ -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
index d6f06ea32f..e055c11103 100644
@@ -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
index ed28e81a22..04682c02ad 100644
@@ -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
index 7f9919a362..c9ea56a214 100644
@@ -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
index c99443b095..38ea6ad6ca 100644
@@ -1,3 +1,4 @@
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
 #include "builtin.h"
 #include "run-command.h"
 
builtin/merge-ours.c +1 -0
index c84c6e05e9..7c4a80ed3b 100644
@@ -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 +2 -1
index 8fc108d305..6fd6586069 100644
@@ -76,7 +76,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
index d2d636d979..eaf5608948 100644
@@ -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
index 80bb967a63..be15ba7044 100644
@@ -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
index b059b86aee..d6f9b749ab 100644
@@ -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
index 9b0fce07ca..61af382d98 100644
@@ -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
index fbbc98e516..6bbe614b02 100644
@@ -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/replace.c +1 -1
index a58b9c6d13..379e220949 100644
@@ -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
index 6d37a35e2e..1d8f3c6235 100644
@@ -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
index 38d7d8fd74..baa5514038 100644
@@ -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
index 17086d3d97..db85b33982 100644
@@ -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
index 80474c3ff5..972209452e 100644
@@ -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
index 07c10bcb7d..d8a879b19c 100644
@@ -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
index cdcbf8264e..3d46d22ee5 100644
@@ -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
index 0ab6784ffe..f0e470a508 100644
@@ -51,7 +51,7 @@ void prime_cache_tree(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
index 4b3ec4ff82..2df03a1ab1 100644
@@ -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
index e0848226d2..df8c6a0bf8 100644
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "object-store.h"
dir.c +0 -1
index 47c2fca8dc..5e713ddf5f 100644
@@ -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
index 5920f8019b..c1eb62acd6 100644
@@ -414,9 +414,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
index 1fcda73cb3..b0ae38563c 100644
@@ -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
index 6f005996fd..f1505cfd0a 100644
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "config.h"
 #include "dir.h"
read-cache.c +0 -2
index 19389c6f30..7255f453f6 100644
@@ -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 +1 -0
index 39b5a80d43..fca30c1086 100644
@@ -9,6 +9,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
index d9d3046689..4c727d2459 100644
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 
 #include "cache.h"
 #include "repository.h"
t/helper/test-dump-fsmonitor.c +2 -2
index 08e3684aff..2786f47088 100644
@@ -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
index 52870ebbb3..cf0f2c7228 100644
@@ -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
index e4890566da..6f223f3870 100644
@@ -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
index 215d3fdc7c..181a3778f3 100644
@@ -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
index 51bfac6aa0..dbb62d61aa 100644
@@ -1,4 +1,3 @@
-#define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
 #include "argv-array.h"
 #include "repository.h"
Signature · 1 line
2.19.1.647.g708186aaf9
#20 lore raw
In reply to Nguyễn Thái Ngọc Duy
Quoted 5 lines · Nguyễn Thái Ngọc Duy

Stefan I see you start removing more references of the_repository in another series (haven't really looked at it yet) so this is just heads up so we could coordinate if needed. Still WIP, not really ready for review yet.

I'll take a brief look anyway, otherwise you wouldn't have put in on a mailing list :-P

Yes, coordination would be good; stolee brought up a good point regarding testing these changes. Killing of the index in itself can be just tested by checking if behavior stays the same, but killing of the_repository is a slightly different beast, as it relates to submodules, which means any global state that is still around, need to go into the repository struct (we might have missed some there, whereas the index struct has been around for a long time).

Quoted 5 lines

This series removes use of the_index outside builtin/ and t/helper/. The only the_index reference left is in repository.c. The macro NO_THE_REPOSITORY_COMPATIBILITY_MACROS is now flipped to USE_THE_INDEX_COMPATIBILITY_MACROS. "the_index" is forbidden by default.

Wow, that is really cool. Looking forward for the patches. :-)

Quoted 4 lines

After this I think we can start pushing the_repository outside library code. Then perhaps clean them up in builtin code too and you can finally get rid of it. But I don't think that'll happen in a year's time.

That sounds realistic.

Stefan

author
#21 lore raw
Quoted 10 lines · Stefan Beller
Quoted 5 lines · Nguyễn Thái Ngọc Duy

Stefan I see you start removing more references of the_repository in another series (haven't really looked at it yet) so this is just heads up so we could coordinate if needed. Still WIP, not really ready for review yet.

I'll take a brief look anyway, otherwise you wouldn't have put in on a mailing list :-P

Thanks. Just fyi. Since there are still plenty conflicts when merging this with 'pu', I'll just wait until things settle a bit in 'master' before resending.

Signature · 1 line
Duy