summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d00e364)
raw | patch | inline | side by side (parent: d00e364)
author | Junio C Hamano <gitster@pobox.com> | |
Wed, 20 May 2009 18:04:35 +0000 (11:04 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 20 May 2009 18:07:07 +0000 (11:07 -0700) |
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>
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>
builtin-write-tree.c | patch | blob | history | |
cache-tree.c | patch | blob | history | |
cache-tree.h | patch | blob | history |
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 9d640508dd8eb62201b286490b7f83486470d611..3a24ce8157be7c4209d831027693653b8d65ca13 100644 (file)
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{
- int missing_ok = 0, ret;
+ int flags = 0, ret;
const char *prefix = NULL;
unsigned char sha1[20];
const char *me = "git-write-tree";
while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--missing-ok"))
- missing_ok = 1;
+ flags |= WRITE_TREE_MISSING_OK;
else if (!prefixcmp(arg, "--prefix="))
prefix = arg + 9;
+ else if (!prefixcmp(arg, "--ignore-cache-tree"))
+ /*
+ * This is only useful for debugging, so I
+ * do not bother documenting it.
+ */
+ flags |= WRITE_TREE_IGNORE_CACHE_TREE;
else
usage(write_tree_usage);
argc--; argv++;
if (argc > 2)
die("too many options");
- ret = write_cache_as_tree(sha1, missing_ok, prefix);
+ ret = write_cache_as_tree(sha1, flags, prefix);
switch (ret) {
case 0:
printf("%s\n", sha1_to_hex(sha1));
diff --git a/cache-tree.c b/cache-tree.c
index 37bf35e636f0966662416f0693dbea5c1cc73311..6dd8411945c77568373e8a354b925926952f147c 100644 (file)
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -538,28 +538,32 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat
return it;
}
-int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
+int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix)
{
int entries, was_valid, newfd;
+ struct lock_file *lock_file;
/*
* We can't free this memory, it becomes part of a linked list
* parsed atexit()
*/
- struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file));
+ lock_file = xcalloc(1, sizeof(struct lock_file));
newfd = hold_locked_index(lock_file, 1);
entries = read_cache();
if (entries < 0)
return WRITE_TREE_UNREADABLE_INDEX;
+ if (flags & WRITE_TREE_IGNORE_CACHE_TREE)
+ cache_tree_free(&(active_cache_tree));
if (!active_cache_tree)
active_cache_tree = cache_tree();
was_valid = cache_tree_fully_valid(active_cache_tree);
-
if (!was_valid) {
+ int missing_ok = flags & WRITE_TREE_MISSING_OK;
+
if (cache_tree_update(active_cache_tree,
active_cache, active_nr,
missing_ok, 0) < 0)
diff --git a/cache-tree.h b/cache-tree.h
index e95883523633a51f833683e96af1738da2868238..eadcad8adc943233637367e5489c0e5d2fda6e2d 100644 (file)
--- a/cache-tree.h
+++ b/cache-tree.h
int cache_tree_fully_valid(struct cache_tree *);
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int);
+/* bitmasks to write_cache_as_tree flags */
+#define WRITE_TREE_MISSING_OK 1
+#define WRITE_TREE_IGNORE_CACHE_TREE 2
+
+/* error return codes */
#define WRITE_TREE_UNREADABLE_INDEX (-1)
#define WRITE_TREE_UNMERGED_INDEX (-2)
#define WRITE_TREE_PREFIX_ERROR (-3)
-int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix);
void prime_cache_tree(struct cache_tree **, struct tree *);
#endif