Skip to content

Commit dc0f6f9

Browse files
committed
Merge branch 'nd/no-the-index'
The more library-ish parts of the codebase learned to work on the in-core index-state instance that is passed in by their callers, instead of always working on the singleton "the_index" instance. * nd/no-the-index: (24 commits) blame.c: remove implicit dependency on the_index apply.c: remove implicit dependency on the_index apply.c: make init_apply_state() take a struct repository apply.c: pass struct apply_state to more functions resolve-undo.c: use the right index instead of the_index archive-*.c: use the right repository archive.c: avoid access to the_index grep: use the right index instead of the_index attr: remove index from git_attr_set_direction() entry.c: use the right index instead of the_index submodule.c: use the right index instead of the_index pathspec.c: use the right index instead of the_index unpack-trees: avoid the_index in verify_absent() unpack-trees: convert clear_ce_flags* to avoid the_index unpack-trees: don't shadow global var the_index unpack-trees: add a note about path invalidation unpack-trees: remove 'extern' on function declaration ls-files: correct index argument to get_convert_attr_ascii() preload-index.c: use the right index instead of the_index dir.c: remove an implicit dependency on the_index in pathspec code ...
2 parents ace1f99 + ecbbc0a commit dc0f6f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+337
-245
lines changed

apply.c

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ static int parse_ignorewhitespace_option(struct apply_state *state,
7676
}
7777

7878
int init_apply_state(struct apply_state *state,
79+
struct repository *repo,
7980
const char *prefix)
8081
{
8182
memset(state, 0, sizeof(*state));
8283
state->prefix = prefix;
84+
state->repo = repo;
8385
state->apply = 1;
8486
state->line_termination = '\n';
8587
state->p_value = 1;
@@ -3374,14 +3376,17 @@ static struct patch *previous_patch(struct apply_state *state,
33743376
return previous;
33753377
}
33763378

3377-
static int verify_index_match(const struct cache_entry *ce, struct stat *st)
3379+
static int verify_index_match(struct apply_state *state,
3380+
const struct cache_entry *ce,
3381+
struct stat *st)
33783382
{
33793383
if (S_ISGITLINK(ce->ce_mode)) {
33803384
if (!S_ISDIR(st->st_mode))
33813385
return -1;
33823386
return 0;
33833387
}
3384-
return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
3388+
return ie_match_stat(state->repo->index, ce, st,
3389+
CE_MATCH_IGNORE_VALID | CE_MATCH_IGNORE_SKIP_WORKTREE);
33853390
}
33863391

33873392
#define SUBMODULE_PATCH_WITHOUT_INDEX 1
@@ -3514,17 +3519,17 @@ static int load_current(struct apply_state *state,
35143519
if (!patch->is_new)
35153520
BUG("patch to %s is not a creation", patch->old_name);
35163521

3517-
pos = cache_name_pos(name, strlen(name));
3522+
pos = index_name_pos(state->repo->index, name, strlen(name));
35183523
if (pos < 0)
35193524
return error(_("%s: does not exist in index"), name);
3520-
ce = active_cache[pos];
3525+
ce = state->repo->index->cache[pos];
35213526
if (lstat(name, &st)) {
35223527
if (errno != ENOENT)
35233528
return error_errno("%s", name);
3524-
if (checkout_target(&the_index, ce, &st))
3529+
if (checkout_target(state->repo->index, ce, &st))
35253530
return -1;
35263531
}
3527-
if (verify_index_match(ce, &st))
3532+
if (verify_index_match(state, ce, &st))
35283533
return error(_("%s: does not match index"), name);
35293534

35303535
status = load_patch_target(state, &buf, ce, &st, patch, name, mode);
@@ -3683,18 +3688,19 @@ static int check_preimage(struct apply_state *state,
36833688
}
36843689

36853690
if (state->check_index && !previous) {
3686-
int pos = cache_name_pos(old_name, strlen(old_name));
3691+
int pos = index_name_pos(state->repo->index, old_name,
3692+
strlen(old_name));
36873693
if (pos < 0) {
36883694
if (patch->is_new < 0)
36893695
goto is_new;
36903696
return error(_("%s: does not exist in index"), old_name);
36913697
}
3692-
*ce = active_cache[pos];
3698+
*ce = state->repo->index->cache[pos];
36933699
if (stat_ret < 0) {
3694-
if (checkout_target(&the_index, *ce, st))
3700+
if (checkout_target(state->repo->index, *ce, st))
36953701
return -1;
36963702
}
3697-
if (!state->cached && verify_index_match(*ce, st))
3703+
if (!state->cached && verify_index_match(state, *ce, st))
36983704
return error(_("%s: does not match index"), old_name);
36993705
if (state->cached)
37003706
st_mode = (*ce)->ce_mode;
@@ -3738,7 +3744,7 @@ static int check_to_create(struct apply_state *state,
37383744
struct stat nst;
37393745

37403746
if (state->check_index &&
3741-
cache_name_pos(new_name, strlen(new_name)) >= 0 &&
3747+
index_name_pos(state->repo->index, new_name, strlen(new_name)) >= 0 &&
37423748
!ok_if_exists)
37433749
return EXISTS_IN_INDEX;
37443750
if (state->cached)
@@ -3827,7 +3833,8 @@ static int path_is_beyond_symlink_1(struct apply_state *state, struct strbuf *na
38273833
if (state->check_index) {
38283834
struct cache_entry *ce;
38293835

3830-
ce = cache_file_exists(name->buf, name->len, ignore_case);
3836+
ce = index_file_exists(state->repo->index, name->buf,
3837+
name->len, ignore_case);
38313838
if (ce && S_ISLNK(ce->ce_mode))
38323839
return 1;
38333840
} else {
@@ -4002,9 +4009,10 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)
40024009
static int read_apply_cache(struct apply_state *state)
40034010
{
40044011
if (state->index_file)
4005-
return read_cache_from(state->index_file);
4012+
return read_index_from(state->repo->index, state->index_file,
4013+
get_git_dir());
40064014
else
4007-
return read_cache();
4015+
return read_index(state->repo->index);
40084016
}
40094017

40104018
/* This function tries to read the object name from the current index */
@@ -4015,10 +4023,10 @@ static int get_current_oid(struct apply_state *state, const char *path,
40154023

40164024
if (read_apply_cache(state) < 0)
40174025
return -1;
4018-
pos = cache_name_pos(path, strlen(path));
4026+
pos = index_name_pos(state->repo->index, path, strlen(path));
40194027
if (pos < 0)
40204028
return -1;
4021-
oidcpy(oid, &active_cache[pos]->oid);
4029+
oidcpy(oid, &state->repo->index->cache[pos]->oid);
40224030
return 0;
40234031
}
40244032

@@ -4246,7 +4254,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
42464254
static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
42474255
{
42484256
if (state->update_index && !state->ita_only) {
4249-
if (remove_file_from_cache(patch->old_name) < 0)
4257+
if (remove_file_from_index(state->repo->index, patch->old_name) < 0)
42504258
return error(_("unable to remove %s from index"), patch->old_name);
42514259
}
42524260
if (!state->cached) {
@@ -4267,7 +4275,7 @@ static int add_index_file(struct apply_state *state,
42674275
struct cache_entry *ce;
42684276
int namelen = strlen(path);
42694277

4270-
ce = make_empty_cache_entry(&the_index, namelen);
4278+
ce = make_empty_cache_entry(state->repo->index, namelen);
42714279
memcpy(ce->name, path, namelen);
42724280
ce->ce_mode = create_ce_mode(mode);
42734281
ce->ce_flags = create_ce_flags(0);
@@ -4299,7 +4307,7 @@ static int add_index_file(struct apply_state *state,
42994307
"for newly created file %s"), path);
43004308
}
43014309
}
4302-
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
4310+
if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
43034311
discard_cache_entry(ce);
43044312
return error(_("unable to add cache entry for %s"), path);
43054313
}
@@ -4313,7 +4321,9 @@ static int add_index_file(struct apply_state *state,
43134321
* 0 if everything went well
43144322
* 1 if a recoverable error happened
43154323
*/
4316-
static int try_create_file(const char *path, unsigned int mode, const char *buf, unsigned long size)
4324+
static int try_create_file(struct apply_state *state, const char *path,
4325+
unsigned int mode, const char *buf,
4326+
unsigned long size)
43174327
{
43184328
int fd, res;
43194329
struct strbuf nbuf = STRBUF_INIT;
@@ -4335,7 +4345,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
43354345
if (fd < 0)
43364346
return 1;
43374347

4338-
if (convert_to_working_tree(path, buf, size, &nbuf)) {
4348+
if (convert_to_working_tree(state->repo->index, path, buf, size, &nbuf)) {
43394349
size = nbuf.len;
43404350
buf = nbuf.buf;
43414351
}
@@ -4371,7 +4381,7 @@ static int create_one_file(struct apply_state *state,
43714381
if (state->cached)
43724382
return 0;
43734383

4374-
res = try_create_file(path, mode, buf, size);
4384+
res = try_create_file(state, path, mode, buf, size);
43754385
if (res < 0)
43764386
return -1;
43774387
if (!res)
@@ -4380,7 +4390,7 @@ static int create_one_file(struct apply_state *state,
43804390
if (errno == ENOENT) {
43814391
if (safe_create_leading_directories(path))
43824392
return 0;
4383-
res = try_create_file(path, mode, buf, size);
4393+
res = try_create_file(state, path, mode, buf, size);
43844394
if (res < 0)
43854395
return -1;
43864396
if (!res)
@@ -4402,7 +4412,7 @@ static int create_one_file(struct apply_state *state,
44024412
for (;;) {
44034413
char newpath[PATH_MAX];
44044414
mksnpath(newpath, sizeof(newpath), "%s~%u", path, nr);
4405-
res = try_create_file(newpath, mode, buf, size);
4415+
res = try_create_file(state, newpath, mode, buf, size);
44064416
if (res < 0)
44074417
return -1;
44084418
if (!res) {
@@ -4432,17 +4442,17 @@ static int add_conflicted_stages_file(struct apply_state *state,
44324442
namelen = strlen(patch->new_name);
44334443
mode = patch->new_mode ? patch->new_mode : (S_IFREG | 0644);
44344444

4435-
remove_file_from_cache(patch->new_name);
4445+
remove_file_from_index(state->repo->index, patch->new_name);
44364446
for (stage = 1; stage < 4; stage++) {
44374447
if (is_null_oid(&patch->threeway_stage[stage - 1]))
44384448
continue;
4439-
ce = make_empty_cache_entry(&the_index, namelen);
4449+
ce = make_empty_cache_entry(state->repo->index, namelen);
44404450
memcpy(ce->name, patch->new_name, namelen);
44414451
ce->ce_mode = create_ce_mode(mode);
44424452
ce->ce_flags = create_ce_flags(stage);
44434453
ce->ce_namelen = namelen;
44444454
oidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);
4445-
if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {
4455+
if (add_index_entry(state->repo->index, ce, ADD_CACHE_OK_TO_ADD) < 0) {
44464456
discard_cache_entry(ce);
44474457
return error(_("unable to add cache entry for %s"),
44484458
patch->new_name);
@@ -4891,7 +4901,7 @@ int apply_all_patches(struct apply_state *state,
48914901
}
48924902

48934903
if (state->update_index) {
4894-
res = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);
4904+
res = write_locked_index(state->repo->index, &state->lock_file, COMMIT_LOCK);
48954905
if (res) {
48964906
error(_("Unable to write new index file"));
48974907
res = -128;

apply.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef APPLY_H
22
#define APPLY_H
33

4+
struct repository;
5+
46
enum apply_ws_error_action {
57
nowarn_ws_error,
68
warn_on_ws_error,
@@ -62,6 +64,7 @@ struct apply_state {
6264
int unsafe_paths;
6365

6466
/* Other non boolean parameters */
67+
struct repository *repo;
6568
const char *index_file;
6669
enum apply_verbosity apply_verbosity;
6770
const char *fake_ancestor;
@@ -116,6 +119,7 @@ int apply_parse_options(int argc, const char **argv,
116119
int *force_apply, int *options,
117120
const char * const *apply_usage);
118121
int init_apply_state(struct apply_state *state,
122+
struct repository *repo,
119123
const char *prefix);
120124
void clear_apply_state(struct apply_state *state);
121125
int check_apply_state(struct apply_state *state, int force_apply);

archive-tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static int write_tar_entry(struct archiver_args *args,
277277
memcpy(header.name, path, pathlen);
278278

279279
if (S_ISREG(mode) && !args->convert &&
280-
oid_object_info(the_repository, oid, &size) == OBJ_BLOB &&
280+
oid_object_info(args->repo, oid, &size) == OBJ_BLOB &&
281281
size > big_file_threshold)
282282
buffer = NULL;
283283
else if (S_ISLNK(mode) || S_ISREG(mode)) {

archive-zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static int write_zip_entry(struct archiver_args *args,
326326
compressed_size = 0;
327327
buffer = NULL;
328328
} else if (S_ISREG(mode) || S_ISLNK(mode)) {
329-
enum object_type type = oid_object_info(the_repository, oid,
329+
enum object_type type = oid_object_info(args->repo, oid,
330330
&size);
331331

332332
method = 0;

0 commit comments

Comments
 (0)