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>
Shawn O. Pearce committed
Aug 28, 2006 at 21:43 UTC
b54d6422b1a277ee905819e01020f5690196a999
1 file changed
+11
-5
fast-import.c
+11
-5
@@ -956,7 +956,8 @@ static void store_tree(struct tree_entry *root)
956
}
957
958
if (is_null_sha1(root->versions[0].sha1)
959
- || !find_object(root->versions[0].sha1)) {
959
+ || !find_object(root->versions[0].sha1)
960
+ || !S_ISDIR(root->versions[0].mode)) {
961
lo.data = NULL;
962
lo.depth = 0;
963
} else {
@@ -1023,6 +1024,7 @@ static int tree_content_set(
1024
if (!S_ISDIR(e->versions[1].mode)) {
1025
e->tree = new_tree_content(8);
1026
e->versions[1].mode = S_IFDIR;
1027
+ hashclr(e->versions[1].sha1);
1028
}
1029
if (!e->tree)
1030
load_tree(e);
@@ -1044,6 +1046,7 @@ static int tree_content_set(
1046
if (slash1) {
1047
e->tree = new_tree_content(8);
1048
e->versions[1].mode = S_IFDIR;
1049
+ hashclr(e->versions[1].sha1);
1050
tree_content_set(e, slash1 + 1, sha1, mode);
1051
} else {
1052
e->tree = NULL;
@@ -1075,10 +1078,13 @@ static int tree_content_remove(struct tree_entry *root, const char *p)
1078
if (!e->tree)
1079
load_tree(e);
1080
if (tree_content_remove(e, slash1 + 1)) {
1078
- if (!e->tree->entry_count)
1079
- goto del_entry;
1080
- hashclr(root->versions[1].sha1);
1081
- return 1;
1081
+ for (n = 0; n < e->tree->entry_count; n++) {
1082
+ if (e->tree->entries[n]->versions[1].mode) {
1083
+ hashclr(root->versions[1].sha1);
1084
+ return 1;
1085
+ }
1086
+ }
1087
+ goto del_entry;
1088
}
1089
return 0;
1090
}