Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 078a58e

Browse files
pcloudsgitster
authored andcommitted
read-cache: mark updated entries for split index
The large part of this patch just follows CE_ENTRY_CHANGED marks. replace_index_entry() is updated to update split_index->base->cache[] as well so base->cache[] does not reference to a freed entry. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 045113a commit 078a58e

File tree

7 files changed

+30
-2
lines changed

7 files changed

+30
-2
lines changed

builtin/update-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static int mark_ce_flags(const char *path, int flag, int mark)
5555
active_cache[pos]->ce_flags |= flag;
5656
else
5757
active_cache[pos]->ce_flags &= ~flag;
58+
active_cache[pos]->ce_flags |= CE_UPDATE_IN_BASE;
5859
cache_tree_invalidate_path(&the_index, path);
5960
active_cache_changed |= CE_ENTRY_CHANGED;
6061
return 0;
@@ -268,6 +269,7 @@ static void chmod_path(int flip, const char *path)
268269
goto fail;
269270
}
270271
cache_tree_invalidate_path(&the_index, path);
272+
ce->ce_flags |= CE_UPDATE_IN_BASE;
271273
active_cache_changed |= CE_ENTRY_CHANGED;
272274
report("chmod %cx '%s'", flip, path);
273275
return;

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ struct cache_entry {
169169
/* used to temporarily mark paths matched by pathspecs */
170170
#define CE_MATCHED (1 << 26)
171171

172+
#define CE_UPDATE_IN_BASE (1 << 27)
173+
172174
/*
173175
* Extended on-disk flags
174176
*/

entry.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ static int write_entry(struct cache_entry *ce,
214214
if (!fstat_done)
215215
lstat(ce->name, &st);
216216
fill_stat_cache_info(ce, &st);
217+
ce->ce_flags |= CE_UPDATE_IN_BASE;
217218
state->istate->cache_changed |= CE_ENTRY_CHANGED;
218219
}
219220
return 0;

read-cache.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
3939

4040
/* changes that can be kept in $GIT_DIR/index (basically all extensions) */
4141
#define EXTMASK (RESOLVE_UNDO_CHANGED | CACHE_TREE_CHANGED | \
42-
CE_ENTRY_ADDED | CE_ENTRY_REMOVED)
42+
CE_ENTRY_ADDED | CE_ENTRY_REMOVED | CE_ENTRY_CHANGED)
4343

4444
struct index_state the_index;
4545
static const char *alternate_index_output;
@@ -54,9 +54,11 @@ static void replace_index_entry(struct index_state *istate, int nr, struct cache
5454
{
5555
struct cache_entry *old = istate->cache[nr];
5656

57+
replace_index_entry_in_base(istate, old, ce);
5758
remove_name_hash(istate, old);
5859
free(old);
5960
set_index_entry(istate, nr, ce);
61+
ce->ce_flags |= CE_UPDATE_IN_BASE;
6062
istate->cache_changed |= CE_ENTRY_CHANGED;
6163
}
6264

@@ -1192,6 +1194,7 @@ int refresh_index(struct index_state *istate, unsigned int flags,
11921194
* means the index is not valid anymore.
11931195
*/
11941196
ce->ce_flags &= ~CE_VALID;
1197+
ce->ce_flags |= CE_UPDATE_IN_BASE;
11951198
istate->cache_changed |= CE_ENTRY_CHANGED;
11961199
}
11971200
if (quiet)

split-index.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,18 @@ void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce
100100
else
101101
free(ce);
102102
}
103+
104+
void replace_index_entry_in_base(struct index_state *istate,
105+
struct cache_entry *old,
106+
struct cache_entry *new)
107+
{
108+
if (old->index &&
109+
istate->split_index &&
110+
istate->split_index->base &&
111+
old->index <= istate->split_index->base->cache_nr) {
112+
new->index = old->index;
113+
if (old != istate->split_index->base->cache[new->index - 1])
114+
free(istate->split_index->base->cache[new->index - 1]);
115+
istate->split_index->base->cache[new->index - 1] = new;
116+
}
117+
}

split-index.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ struct split_index {
1313

1414
struct split_index *init_split_index(struct index_state *istate);
1515
void save_or_free_index_entry(struct index_state *istate, struct cache_entry *ce);
16+
void replace_index_entry_in_base(struct index_state *istate,
17+
struct cache_entry *old,
18+
struct cache_entry *new);
1619
int read_link_extension(struct index_state *istate,
1720
const void *data, unsigned long sz);
1821
int write_link_extension(struct strbuf *sb,

unpack-trees.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ static int apply_sparse_checkout(struct index_state *istate,
257257
ce->ce_flags |= CE_SKIP_WORKTREE;
258258
else
259259
ce->ce_flags &= ~CE_SKIP_WORKTREE;
260-
if (was_skip_worktree != ce_skip_worktree(ce))
260+
if (was_skip_worktree != ce_skip_worktree(ce)) {
261+
ce->ce_flags |= CE_UPDATE_IN_BASE;
261262
istate->cache_changed |= CE_ENTRY_CHANGED;
263+
}
262264

263265
/*
264266
* if (!was_skip_worktree && !ce_skip_worktree()) {

0 commit comments

Comments
 (0)