Use cache-tree in update-index.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 24, 2006 at 00:23 UTC
a6e5642f39db2113785c4f22add7e16d559b8d55
1 file changed
+21
-2
update-index.c
+21
-2
@@ -6,6 +6,11 @@
6
#include "cache.h"
7
#include "strbuf.h"
8
#include "quote.h"
9
+#include "tree.h"
10
+#include "cache-tree.h"
11
+
12
+static unsigned char active_cache_sha1[20];
13
+static struct cache_tree *active_cache_tree;
14
15
/*
16
* Default to not allowing changes to the list of files. The
@@ -70,6 +75,7 @@ static int mark_valid(const char *path)
75
active_cache[pos]->ce_flags &= ~htons(CE_VALID);
76
break;
77
}
78
+ cache_tree_invalidate_path(active_cache_tree, path);
79
active_cache_changed = 1;
80
return 0;
81
}
@@ -83,6 +89,12 @@ static int add_file_to_cache(const char *path)
89
struct stat st;
90
91
status = lstat(path, &st);
92
+
93
+ /* We probably want to do this in remove_file_from_cache() and
94
+ * add_cache_entry() instead...
95
+ */
96
+ cache_tree_invalidate_path(active_cache_tree, path);
97
+
98
if (status < 0 || S_ISDIR(st.st_mode)) {
99
/* When we used to have "path" and now we want to add
100
* "path/file", we need a way to remove "path" before
@@ -325,6 +337,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
337
return error("%s: cannot add to the index - missing --add option?",
338
path);
339
report("add '%s'", path);
340
+ cache_tree_invalidate_path(active_cache_tree, path);
341
return 0;
342
}
343
@@ -349,6 +362,7 @@ static int chmod_path(int flip, const char *path)
362
default:
363
return -1;
364
}
365
+ cache_tree_invalidate_path(active_cache_tree, path);
366
active_cache_changed = 1;
367
return 0;
368
}
@@ -367,6 +381,7 @@ static void update_one(const char *path, const char *prefix, int prefix_length)
381
die("Unable to mark file %s", path);
382
return;
383
}
384
+ cache_tree_invalidate_path(active_cache_tree, path);
385
386
if (force_remove) {
387
if (remove_file_from_cache(p))
@@ -442,6 +457,7 @@ static void read_index_info(int line_termination)
457
free(path_name);
458
continue;
459
}
460
+ cache_tree_invalidate_path(active_cache_tree, path_name);
461
462
if (!mode) {
463
/* mode == 0 means there is no such path -- remove */
@@ -485,9 +501,10 @@ int main(int argc, const char **argv)
501
if (newfd < 0)
502
die("unable to create new cachefile");
503
488
- entries = read_cache();
504
+ entries = read_cache_1(active_cache_sha1);
505
if (entries < 0)
506
die("cache corrupted");
507
+ active_cache_tree = read_cache_tree(active_cache_sha1);
508
509
for (i = 1 ; i < argc; i++) {
510
const char *path = argv[i];
@@ -613,9 +630,11 @@ int main(int argc, const char **argv)
630
}
631
}
632
if (active_cache_changed) {
616
- if (write_cache(newfd, active_cache, active_nr) ||
633
+ if (write_cache_1(newfd, active_cache, active_nr,
634
+ active_cache_sha1) ||
635
commit_index_file(&cache_file))
636
die("Unable to write new cachefile");
637
+ write_cache_tree(active_cache_sha1, active_cache_tree);
638
}
639
640
return has_errors ? 1 : 0;