Invalidate cache-tree entries for touched paths in git-apply.
This updates git-apply to maintain cache-tree information. With this and the previous write-tree patch, repeated "apply --index" followed by "write-tree" on a huge tree will hopefully become faster. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 23, 2006 at 16:52 UTC
03ac6e64651e4b5ca0c2164a23b5f345f2c03af4
1 file changed
+13
-3
apply.c
+13
-3
@@ -8,9 +8,14 @@
8
*/
9
#include <fnmatch.h>
10
#include "cache.h"
11
+#include "cache-tree.h"
12
#include "quote.h"
13
#include "blob.h"
14
15
+static unsigned char active_cache_sha1[20];
16
+static struct cache_tree *active_cache_tree;
17
+
18
+
19
// --check turns on checking that the working tree matches the
20
// files that are being modified, but doesn't apply the patch
21
// --stat does just a diffstat, and doesn't actually apply
@@ -1717,6 +1722,7 @@ static void remove_file(struct patch *patch)
1722
if (write_index) {
1723
if (remove_file_from_cache(patch->old_name) < 0)
1724
die("unable to remove %s from index", patch->old_name);
1725
+ cache_tree_invalidate_path(active_cache_tree, patch->old_name);
1726
}
1727
unlink(patch->old_name);
1728
}
@@ -1813,8 +1819,9 @@ static void create_file(struct patch *patch)
1819
1820
if (!mode)
1821
mode = S_IFREG | 0644;
1816
- create_one_file(path, mode, buf, size);
1822
+ create_one_file(path, mode, buf, size);
1823
add_index_file(path, mode, buf, size);
1824
+ cache_tree_invalidate_path(active_cache_tree, path);
1825
}
1826
1827
static void write_out_one_result(struct patch *patch)
@@ -1912,8 +1919,9 @@ static int apply_patch(int fd, const char *filename)
1919
if (write_index)
1920
newfd = hold_index_file_for_update(&cache_file, get_index_file());
1921
if (check_index) {
1915
- if (read_cache() < 0)
1922
+ if (read_cache_1(active_cache_sha1) < 0)
1923
die("unable to read index file");
1924
+ active_cache_tree = read_cache_tree(active_cache_sha1);
1925
}
1926
1927
if ((check || apply) && check_patch_list(list) < 0)
@@ -1923,9 +1931,11 @@ static int apply_patch(int fd, const char *filename)
1931
write_out_results(list, skipped_patch);
1932
1933
if (write_index) {
1926
- if (write_cache(newfd, active_cache, active_nr) ||
1934
+ if (write_cache_1(newfd, active_cache, active_nr,
1935
+ active_cache_sha1) ||
1936
commit_index_file(&cache_file))
1937
die("Unable to write new cachefile");
1938
+ write_cache_tree(active_cache_sha1, active_cache_tree);
1939
}
1940
1941
if (show_index_info)