Skip to content

Commit

Permalink
Merge branch 'nd/the-index-final'
Browse files Browse the repository at this point in the history
The assumption to work on the single "in-core index" instance has
been reduced from the library-ish part of the codebase.

* nd/the-index-final:
  cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch
  read-cache.c: remove the_* from index_has_changes()
  merge-recursive.c: remove implicit dependency on the_repository
  merge-recursive.c: remove implicit dependency on the_index
  sha1-name.c: remove implicit dependency on the_index
  read-cache.c: replace update_index_if_able with repo_&
  read-cache.c: kill read_index()
  checkout: avoid the_index when possible
  repository.c: replace hold_locked_index() with repo_hold_locked_index()
  notes-utils.c: remove the_repository references
  grep: use grep_opt->repo instead of explict repo argument
  • Loading branch information
gitster committed Feb 7, 2019
2 parents e52c6bb + f8adbec commit 7589e63
Show file tree
Hide file tree
Showing 74 changed files with 394 additions and 296 deletions.
5 changes: 3 additions & 2 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -4020,7 +4020,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 */
Expand Down Expand Up @@ -4713,7 +4713,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) {
Expand Down
1 change: 0 additions & 1 deletion attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
unsigned mode;
struct strbuf msg = STRBUF_INIT;

read_index(r->index);
repo_read_index(r);
time(&now);
commit = alloc_commit_node(r);
commit->object.parsed = 1;
Expand Down Expand Up @@ -270,7 +270,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
* want to run "diff-index --cached".
*/
discard_index(r->index);
read_index(r->index);
repo_read_index(r);

len = strlen(path);
if (!mode) {
Expand Down
1 change: 1 addition & 0 deletions builtin/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) 2006 Linus Torvalds
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
13 changes: 7 additions & 6 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -511,7 +512,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
}

finish:
finish_copy_notes_for_rewrite(c, msg);
finish_copy_notes_for_rewrite(the_repository, c, msg);
fclose(fp);
strbuf_release(&sb);
return ret;
Expand Down Expand Up @@ -1529,7 +1530,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);
Expand Down Expand Up @@ -1703,7 +1704,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);
}
Expand Down Expand Up @@ -1761,7 +1762,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;
}
Expand Down Expand Up @@ -1815,7 +1816,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."));
Expand Down Expand Up @@ -2271,7 +2272,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) {
Expand Down
3 changes: 2 additions & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
long bottom, top;
if (parse_range_arg(range_list.items[range_i].string,
nth_line_cb, &sb, lno, anchor,
&bottom, &top, sb.path, &the_index))
&bottom, &top, sb.path,
the_repository->index))
usage(blame_usage);
if ((!lno && (top || bottom)) || lno < bottom)
die(Q_("file %s has only %lu line",
Expand Down
7 changes: 5 additions & 2 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down Expand Up @@ -73,7 +74,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);

Expand Down Expand Up @@ -382,7 +384,8 @@ static void batch_one_object(const char *obj_name,
int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
enum get_oid_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:
Expand Down
1 change: 1 addition & 0 deletions builtin/check-attr.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/check-ignore.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "config.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2005 Linus Torvalds
*
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "lockfile.h"
Expand Down
5 changes: 3 additions & 2 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "config.h"
#include "checkout.h"
Expand Down Expand Up @@ -288,7 +289,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"));

Expand Down Expand Up @@ -701,7 +702,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);

Expand Down
1 change: 1 addition & 0 deletions builtin/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1368,7 +1369,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
if (status_format != STATUS_FORMAT_PORCELAIN &&
status_format != STATUS_FORMAT_PORCELAIN_V2)
progress_flag = REFRESH_PROGRESS;
read_index(&the_index);
repo_read_index(the_repository);
refresh_index(&the_index,
REFRESH_QUIET|REFRESH_UNMERGED|progress_flag,
&s.pathspec, NULL, NULL);
Expand Down Expand Up @@ -1397,7 +1398,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;
Expand Down Expand Up @@ -1675,7 +1676,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
if (amend && !no_post_rewrite) {
commit_post_rewrite(current_head, &oid);
commit_post_rewrite(the_repository, current_head, &oid);
}
if (!quiet) {
unsigned int flags = 0;
Expand Down
3 changes: 2 additions & 1 deletion builtin/describe.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "lockfile.h"
Expand Down Expand Up @@ -634,7 +635,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);
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Copyright (C) Linus Torvalds, 2005
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/diff-index.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down
3 changes: 2 additions & 1 deletion builtin/diff-tree.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "diff.h"
Expand Down Expand Up @@ -165,7 +166,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)) {
Expand Down
3 changes: 2 additions & 1 deletion builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -212,7 +213,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)
Expand Down
1 change: 1 addition & 0 deletions builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* Copyright (C) 2016 Johannes Schindelin
*/
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "config.h"
#include "builtin.h"
Expand Down
1 change: 1 addition & 0 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "builtin.h"
#include "cache.h"
#include "repository.h"
Expand Down
Loading

0 comments on commit 7589e63

Please sign in to comment.