Simplify cache API
Earlier, add_file_to_index() invalidated the path in the cache-tree but remove_file_from_cache() did not, and the user of the latter needed to invalidate the entry himself. This led to a few bugs due to missed invalidate calls already. This patch makes the management of cache-tree less error prone by making more invalidate calls from lower level cache API functions. The rules are: - If you are going to write the index, you should either maintain cache_tree correctly. - If you cannot, alternatively you can remove the entire cache_tree by calling cache_tree_free() before you call write_cache(). - When you modify the index, cache_tree_invalidate_path() should be called with the path you are modifying, to discard the entry from the cache-tree structure. - The following cache API functions exported from read-cache.c (and the macro whose names have "cache" instead of "index") automatically call cache_tree_invalidate_path() for you: - remove_file_from_index(); - add_file_to_index(); - add_index_entry(); You can modify the index bypassing the above API functions (e.g. find an existing cache entry from the index and modify it in place). You need to call cache_tree_invalidate_path() yourself in such a case. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -195,11 +195,6 @@ static int process_path(const char *path)
|
||||
int len;
|
||||
struct stat st;
|
||||
|
||||
/* We probably want to do this in remove_file_from_cache() and
|
||||
* add_cache_entry() instead...
|
||||
*/
|
||||
cache_tree_invalidate_path(active_cache_tree, path);
|
||||
|
||||
/*
|
||||
* First things first: get the stat information, to decide
|
||||
* what to do about the pathname!
|
||||
@ -239,7 +234,6 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
|
||||
return error("%s: cannot add to the index - missing --add option?",
|
||||
path);
|
||||
report("add '%s'", path);
|
||||
cache_tree_invalidate_path(active_cache_tree, path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -284,7 +278,6 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
|
||||
die("Unable to mark file %s", path);
|
||||
goto free_return;
|
||||
}
|
||||
cache_tree_invalidate_path(active_cache_tree, path);
|
||||
|
||||
if (force_remove) {
|
||||
if (remove_file_from_cache(p))
|
||||
@ -367,7 +360,6 @@ static void read_index_info(int line_termination)
|
||||
free(path_name);
|
||||
continue;
|
||||
}
|
||||
cache_tree_invalidate_path(active_cache_tree, path_name);
|
||||
|
||||
if (!mode) {
|
||||
/* mode == 0 means there is no such path -- remove */
|
||||
@ -474,7 +466,6 @@ static int unresolve_one(const char *path)
|
||||
goto free_return;
|
||||
}
|
||||
|
||||
cache_tree_invalidate_path(active_cache_tree, path);
|
||||
remove_file_from_cache(path);
|
||||
if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
|
||||
error("%s: cannot add our version to the index.", path);
|
||||
|
Reference in New Issue
Block a user