Mercurial > hg > hg-git
changeset 543:5a688ad69449
Verify tree and parent objects are in Git repo
When exporting Git commits, verify that the tree and parents objects
exist in the repository before allowing the commit to be exported. If a
tree or parent commit is missing, then the repository is not valid and
the export should not be allowed.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 21 Sep 2012 20:26:26 -0700 |
parents | c9faba7d01f4 |
children | ebf4ea20ade5 |
files | hggit/git_handler.py |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -384,6 +384,10 @@ hgsha = hex(parent.node()) git_sha = self.map_git_get(hgsha) if git_sha: + if git_sha not in self.git.object_store: + raise hgutil.Abort(_('Parent SHA-1 not present in Git' + 'repo: %s' % git_sha)) + commit.parents.append(git_sha) commit.message = self.get_git_message(ctx) @@ -392,6 +396,10 @@ commit.encoding = extra['encoding'] tree_sha = commit_tree(self.git.object_store, self.iterblobs(ctx)) + if tree_sha not in self.git.object_store: + raise hgutil.Abort(_('Tree SHA-1 not present in Git repo: %s' % + tree_sha)) + commit.tree = tree_sha self.git.object_store.add_object(commit)