@matheusbsbs / matheus-bagliano / commits / 8a8c55ea70
Fork 0

Additional fast-import tree delta corruption cleanups.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Aug 28, 2006 at 22:06 UTC 8a8c55ea709d26ca397d6588e85579339885f507
1 file changed +11 -11
fast-import.c
+11 -11
@@ -478,6 +478,8 @@ static struct branch* new_branch(const char *name)
478 b = pool_calloc(1, sizeof(struct branch));
479 b->name = pool_strdup(name);
480 b->table_next_branch = branch_table[hc];
481 + b->branch_tree.versions[0].mode = S_IFDIR;
482 + b->branch_tree.versions[1].mode = S_IFDIR;
483 branch_table[hc] = b;
484 branch_count++;
485 return b;
@@ -955,9 +957,9 @@ static void store_tree(struct tree_entry *root)
957 store_tree(t->entries[i]);
958 }
959
958 - if (is_null_sha1(root->versions[0].sha1)
959 - || !find_object(root->versions[0].sha1)
960 - || !S_ISDIR(root->versions[0].mode)) {
960 + if (!S_ISDIR(root->versions[0].mode)
961 + || is_null_sha1(root->versions[0].sha1)
962 + || !find_object(root->versions[0].sha1)) {
963 lo.data = NULL;
964 lo.depth = 0;
965 } else {
@@ -967,13 +969,12 @@ static void store_tree(struct tree_entry *root)
969 lo.no_free = 1;
970 hashcpy(lo.sha1, root->versions[0].sha1);
971 }
970 - mktree(t, 1, &new_len, &new_tree);
972
973 + mktree(t, 1, &new_len, &new_tree);
974 store_object(OBJ_TREE, new_tree.buffer, new_len,
975 &lo, root->versions[1].sha1, 0);
976
977 t->delta_depth = lo.depth;
976 - hashcpy(root->versions[0].sha1, root->versions[1].sha1);
978 for (i = 0, j = 0, del = 0; i < t->entry_count; i++) {
979 struct tree_entry *e = t->entries[i];
980 if (e->versions[1].mode) {
@@ -1024,7 +1025,6 @@ static int tree_content_set(
1025 if (!S_ISDIR(e->versions[1].mode)) {
1026 e->tree = new_tree_content(8);
1027 e->versions[1].mode = S_IFDIR;
1027 - hashclr(e->versions[1].sha1);
1028 }
1029 if (!e->tree)
1030 load_tree(e);
@@ -1046,7 +1046,6 @@ 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);
1049 tree_content_set(e, slash1 + 1, sha1, mode);
1050 } else {
1051 e->tree = NULL;
@@ -1564,6 +1563,8 @@ static void cmd_new_commit()
1563
1564 /* build the tree and the commit */
1565 store_tree(&b->branch_tree);
1566 + hashcpy(b->branch_tree.versions[0].sha1,
1567 + b->branch_tree.versions[1].sha1);
1568 size_dbuf(&new_data, 97 + msglen
1569 + (author
1570 ? strlen(author) + strlen(committer)
@@ -1823,9 +1824,9 @@ int main(int argc, const char **argv)
1824 fclose(branch_log);
1825
1826 fprintf(stderr, "%s statistics:\n", argv[0]);
1826 - fprintf(stderr, "---------------------------------------------------\n");
1827 + fprintf(stderr, "---------------------------------------------------------------------\n");
1828 fprintf(stderr, "Alloc'd objects: %10lu (%10lu overflow )\n", alloc_count, alloc_count - est_obj_cnt);
1828 - fprintf(stderr, "Total objects: %10lu (%10lu duplicates)\n", object_count, duplicate_count);
1829 + fprintf(stderr, "Total objects: %10lu (%10lu duplicates )\n", object_count, duplicate_count);
1830 fprintf(stderr, " blobs : %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);
1831 fprintf(stderr, " trees : %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);
1832 fprintf(stderr, " commits: %10lu (%10lu duplicates %10lu deltas)\n", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);
@@ -1837,12 +1838,11 @@ int main(int argc, const char **argv)
1838 fprintf(stderr, " pools: %10lu KiB\n", total_allocd/1024);
1839 fprintf(stderr, " objects: %10lu KiB\n", (alloc_count*sizeof(struct object_entry))/1024);
1840 fprintf(stderr, "Pack remaps: %10lu\n", remap_count);
1840 - fprintf(stderr, "---------------------------------------------------\n");
1841 -
1841 stat(pack_name, &sb);
1842 fprintf(stderr, "Pack size: %10lu KiB\n", (unsigned long)(sb.st_size/1024));
1843 stat(idx_name, &sb);
1844 fprintf(stderr, "Index size: %10lu KiB\n", (unsigned long)(sb.st_size/1024));
1845 + fprintf(stderr, "---------------------------------------------------------------------\n");
1846
1847 fprintf(stderr, "\n");
1848