write-tree --ignore-cache-tree
This allows you to discard the cache-tree information before writing the tree out of the index (i.e. it always recomputes the tree object names for all the subtrees). This is only useful as a debug option, so I did not bother documenting it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
May 20, 2009 at 11:04 UTC
d11b8d342529a8fe2164ceb563ad9213902d3533
3 files changed
+22
-7
builtin-write-tree.c
+9
-3
@@ -13,7 +13,7 @@ static const char write_tree_usage[] =
13
14
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
15
{
16
- int missing_ok = 0, ret;
16
+ int flags = 0, ret;
17
const char *prefix = NULL;
18
unsigned char sha1[20];
19
const char *me = "git-write-tree";
@@ -22,9 +22,15 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
22
while (1 < argc) {
23
const char *arg = argv[1];
24
if (!strcmp(arg, "--missing-ok"))
25
- missing_ok = 1;
25
+ flags |= WRITE_TREE_MISSING_OK;
26
else if (!prefixcmp(arg, "--prefix="))
27
prefix = arg + 9;
28
+ else if (!prefixcmp(arg, "--ignore-cache-tree"))
29
+ /*
30
+ * This is only useful for debugging, so I
31
+ * do not bother documenting it.
32
+ */
33
+ flags |= WRITE_TREE_IGNORE_CACHE_TREE;
34
else
35
usage(write_tree_usage);
36
argc--; argv++;
@@ -33,7 +39,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
39
if (argc > 2)
40
die("too many options");
41
36
- ret = write_cache_as_tree(sha1, missing_ok, prefix);
42
+ ret = write_cache_as_tree(sha1, flags, prefix);
43
switch (ret) {
44
case 0:
45
printf("%s\n", sha1_to_hex(sha1));
cache-tree.c
+7
-3
@@ -538,28 +538,32 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
538
return it;
539
}
540
541
-int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
541
+int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
542
{
543
int entries, was_valid, newfd;
544
+ struct lock_file *lock_file;
545
546
/*
547
* We can't free this memory, it becomes part of a linked list
548
* parsed atexit()
549
*/
549
- struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
550
+ lock_file = xcalloc(1, sizeof(struct lock_file));
551
552
newfd = hold_locked_index(lock_file, 1);
553
554
entries = read_cache();
555
if (entries < 0)
556
return WRITE_TREE_UNREADABLE_INDEX;
557
+ if (flags & WRITE_TREE_IGNORE_CACHE_TREE)
558
+ cache_tree_free(&(active_cache_tree));
559
560
if (!active_cache_tree)
561
active_cache_tree = cache_tree();
562
563
was_valid = cache_tree_fully_valid(active_cache_tree);
561
-
564
if (!was_valid) {
565
+ int missing_ok = flags & WRITE_TREE_MISSING_OK;
566
+
567
if (cache_tree_update(active_cache_tree,
568
active_cache, active_nr,
569
missing_ok, 0) < 0)
cache-tree.h
+6
-1
@@ -30,11 +30,16 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
30
int cache_tree_fully_valid(struct cache_tree *);
31
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int);
32
33
+/* bitmasks to write_cache_as_tree flags */
34
+#define WRITE_TREE_MISSING_OK 1
35
+#define WRITE_TREE_IGNORE_CACHE_TREE 2
36
+
37
+/* error return codes */
38
#define WRITE_TREE_UNREADABLE_INDEX (-1)
39
#define WRITE_TREE_UNMERGED_INDEX (-2)
40
#define WRITE_TREE_PREFIX_ERROR (-3)
41
37
-int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
42
+int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix);
43
void prime_cache_tree(struct cache_tree **, struct tree *);
44
45
#endif