ostree commit: Fix combining trees with multiple --tree=ref arguments

You'd expect

    ostree commit --tree=ref=A --tree=ref=B

to produce a commit with the union of the trees given.  Instead you'd get
a commit with the contents of just the latter commit.  This was due to an
optimisation where we'd skip filling out the `files` and `subdirs`
members of the mtree, just filling in the metadata instead.  This backfires
becuase this same code relies on checking the `files` and `subdirs` members
itself to work out whether the mtree is empty.

This commit removes the optimisation, fixing the bug.  Maybe there's a way
to keep the optimisation and still fix the bug but it's not obvious to
me.

Closes: #581
Approved by: cgwalters
This commit is contained in:
William Manley authored and Atomic Bot committed 2016-11-17 14:45:55 +00:00
1 parent 24bf257ee9
commit 0ee9e221be
2 files changed
+15 -11

No files matched your search

-10
View File
@@ -2550,16 +2550,6 @@ write_directory_to_mtree_internal (OstreeRepo *self,
ostree_mutable_tree_set_metadata_checksum (mtree, ostree_repo_file_tree_get_metadata_checksum (repo_dir));
/* If the mtree was empty beforehand, the checksums on the mtree can simply
* become the checksums on the tree in the repo. Super simple. */
if (g_hash_table_size (ostree_mutable_tree_get_files (mtree)) == 0 &&
g_hash_table_size (ostree_mutable_tree_get_subdirs (mtree)) == 0)
{
ostree_mutable_tree_set_contents_checksum (mtree, ostree_repo_file_tree_get_contents_checksum (repo_dir));
ret = TRUE;
goto out;
}
filter_result = OSTREE_REPO_COMMIT_FILTER_ALLOW;
}
else