Skip to content

Commit

Permalink
unpack-trees: preserve index extensions
Browse files Browse the repository at this point in the history
Make git checkout (and other unpack_tree operations) preserve the
untracked cache. This is valuable for two reasons:

1. Often, an unpack_tree operation will not touch large parts of the
working tree, and thus most of the untracked cache will continue to be
valid.

2. Even if the untracked cache were entirely invalidated by such an
operation, the user has signaled their intention to have such a cache,
and we don't want to throw it away.

[jes: backed out the watchman-specific parts]

Signed-off-by: David Turner <[email protected]>
Signed-off-by: Ben Peart <[email protected]>
Signed-off-by: Johannes Schindelin <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
dturner-tw authored and gitster committed May 20, 2017
1 parent 4fa66c8 commit edf3b90
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ extern int read_index_unmerged(struct index_state *);
#define CLOSE_LOCK (1 << 1)
extern int write_locked_index(struct index_state *, struct lock_file *lock, unsigned flags);
extern int discard_index(struct index_state *);
extern void move_index_extensions(struct index_state *dst, struct index_state *src);
extern int unmerged_index(const struct index_state *);
extern int verify_path(const char *path);
extern int strcmp_offset(const char *s1, const char *s2, size_t *first_change);
Expand Down
6 changes: 6 additions & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2628,3 +2628,9 @@ void stat_validity_update(struct stat_validity *sv, int fd)
fill_stat_data(sv->sd, &st);
}
}

void move_index_extensions(struct index_state *dst, struct index_state *src)
{
dst->untracked = src->untracked;
src->untracked = NULL;
}
22 changes: 22 additions & 0 deletions t/t7063-status-untracked-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,26 @@ test_expect_success 'test ident field is working' '
test_i18ncmp ../expect ../err
'

test_expect_success 'untracked cache survives a checkout' '
git commit --allow-empty -m empty &&
test-dump-untracked-cache >../before &&
test_when_finished "git checkout master" &&
git checkout -b other_branch &&
test-dump-untracked-cache >../after &&
test_cmp ../before ../after &&
test_commit test &&
test-dump-untracked-cache >../before &&
git checkout master &&
test-dump-untracked-cache >../after &&
test_cmp ../before ../after
'

test_expect_success 'untracked cache survives a commit' '
test-dump-untracked-cache >../before &&
git add done/two &&
git commit -m commit &&
test-dump-untracked-cache >../after &&
test_cmp ../before ../after
'

test_done
1 change: 1 addition & 0 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
WRITE_TREE_SILENT |
WRITE_TREE_REPAIR);
}
move_index_extensions(&o->result, o->dst_index);
discard_index(o->dst_index);
*o->dst_index = o->result;
} else {
Expand Down

0 comments on commit edf3b90

Please sign in to comment.