Skip to content

Commit 3f13877

Browse files
bmwillgitster
authored andcommitted
repo_read_index: don't discard the index
Have 'repo_read_index()' behave more like the other read_index family of functions and don't discard the index if it has already been populated and instead rely on the quick return of read_index_from which has: /* istate->initialized covers both .git/index and .git/sharedindex.xxx */ if (istate->initialized) return istate->cache_nr; Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3da2b7 commit 3f13877

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

repository.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ int repo_read_index(struct repository *repo)
235235
{
236236
if (!repo->index)
237237
repo->index = xcalloc(1, sizeof(*repo->index));
238-
else
239-
discard_index(repo->index);
240238

241239
return read_index_from(repo->index, repo->index_file);
242240
}

repository.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ extern int repo_submodule_init(struct repository *submodule,
9292
const char *path);
9393
extern void repo_clear(struct repository *repo);
9494

95+
/*
96+
* Populates the repository's index from its index_file, an index struct will
97+
* be allocated if needed.
98+
*
99+
* Return the number of index entries in the populated index or a value less
100+
* than zero if an error occured. If the repository's index has already been
101+
* populated then the number of entries will simply be returned.
102+
*/
95103
extern int repo_read_index(struct repository *repo);
96104

97105
#endif /* REPOSITORY_H */

0 commit comments

Comments
 (0)