aboutsummaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2006-08-28 21:43:04 -0400
committerShawn O. Pearce <spearce@spearce.org>2007-01-14 02:15:11 -0500
commitb54d6422b1a277ee905819e01020f5690196a999 (patch)
tree934f101d727b4c6a7471e4589862ba5e80120a8f /fast-import.c
parent23bc886c966b4362555b61f33c6eef71552e4d0e (diff)
downloadgit-b54d6422b1a277ee905819e01020f5690196a999.tar.gz
git-b54d6422b1a277ee905819e01020f5690196a999.tar.xz
Correct tree corruption problems in fast-import.
The new tree delta implementation caused blob SHA1s to be used instead of a tree SHA1 when a tree was written out. This really only appeared to happen when converting an existing file to a tree, but may have been possible in some other situations. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/fast-import.c b/fast-import.c
index f94f307ee..34ff946fa 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -956,7 +956,8 @@ static void store_tree(struct tree_entry *root)
}
if (is_null_sha1(root->versions[0].sha1)
- || !find_object(root->versions[0].sha1)) {
+ || !find_object(root->versions[0].sha1)
+ || !S_ISDIR(root->versions[0].mode)) {
lo.data = NULL;
lo.depth = 0;
} else {
@@ -1023,6 +1024,7 @@ static int tree_content_set(
if (!S_ISDIR(e->versions[1].mode)) {
e->tree = new_tree_content(8);
e->versions[1].mode = S_IFDIR;
+ hashclr(e->versions[1].sha1);
}
if (!e->tree)
load_tree(e);
@@ -1044,6 +1046,7 @@ static int tree_content_set(
if (slash1) {
e->tree = new_tree_content(8);
e->versions[1].mode = S_IFDIR;
+ hashclr(e->versions[1].sha1);
tree_content_set(e, slash1 + 1, sha1, mode);
} else {
e->tree = NULL;
@@ -1075,10 +1078,13 @@ static int tree_content_remove(struct tree_entry *root, const char *p)
if (!e->tree)
load_tree(e);
if (tree_content_remove(e, slash1 + 1)) {
- if (!e->tree->entry_count)
- goto del_entry;
- hashclr(root->versions[1].sha1);
- return 1;
+ for (n = 0; n < e->tree->entry_count; n++) {
+ if (e->tree->entries[n]->versions[1].mode) {
+ hashclr(root->versions[1].sha1);
+ return 1;
+ }
+ }
+ goto del_entry;
}
return 0;
}