Skip to content

Commit fa0624f

Browse files
committed
Merge branch 'dt/unpack-save-untracked-cache-extension'
When "git checkout", "git merge", etc. manipulates the in-core index, various pieces of information in the index extensions are discarded from the original state, as it is usually not the case that they are kept up-to-date and in-sync with the operation on the main index. The untracked cache extension is copied across these operations now, which would speed up "git status" (as long as the cache is properly invalidated). * dt/unpack-save-untracked-cache-extension: unpack-trees: preserve index extensions
2 parents 35d802d + edf3b90 commit fa0624f

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ extern int read_index_unmerged(struct index_state *);
597597
#define CLOSE_LOCK (1 << 1)
598598
extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
599599
extern int discard_index(struct index_state *);
600+
extern void move_index_extensions(struct index_state *dst, struct index_state *src);
600601
extern int unmerged_index(const struct index_state *);
601602
extern int verify_path(const char *path);
602603
extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);

read-cache.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,3 +2625,9 @@ void stat_validity_update(struct stat_validity *sv, int fd)
26252625
fill_stat_data(sv->sd, &st);
26262626
}
26272627
}
2628+
2629+
void move_index_extensions(struct index_state *dst, struct index_state *src)
2630+
{
2631+
dst->untracked = src->untracked;
2632+
src->untracked = NULL;
2633+
}

t/t7063-status-untracked-cache.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,4 +661,26 @@ test_expect_success 'test ident field is working' '
661661
test_i18ncmp ../expect ../err
662662
'
663663

664+
test_expect_success 'untracked cache survives a checkout' '
665+
git commit --allow-empty -m empty &&
666+
test-dump-untracked-cache >../before &&
667+
test_when_finished "git checkout master" &&
668+
git checkout -b other_branch &&
669+
test-dump-untracked-cache >../after &&
670+
test_cmp ../before ../after &&
671+
test_commit test &&
672+
test-dump-untracked-cache >../before &&
673+
git checkout master &&
674+
test-dump-untracked-cache >../after &&
675+
test_cmp ../before ../after
676+
'
677+
678+
test_expect_success 'untracked cache survives a commit' '
679+
test-dump-untracked-cache >../before &&
680+
git add done/two &&
681+
git commit -m commit &&
682+
test-dump-untracked-cache >../after &&
683+
test_cmp ../before ../after
684+
'
685+
664686
test_done

unpack-trees.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
13961396
WRITE_TREE_SILENT |
13971397
WRITE_TREE_REPAIR);
13981398
}
1399+
move_index_extensions(&o->result, o->dst_index);
13991400
discard_index(o->dst_index);
14001401
*o->dst_index = o->result;
14011402
} else {

0 commit comments

Comments
 (0)