Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

fix index.changes_from_tree against a repository with no initial commit. #73

wants to merge 1 commit into


None yet
2 participants

kevinw commented Sep 6, 2012

index.changes_from_tree(object_store, None) should work. This change modifies BaseObjectStore.iter_tree_contents so that it works with tree_id=None.

kwatters Fix index.changes_from_tree against an empty tree.
index.changes_from_tree(object_store, None) should work. Modify that function
so the 'tree' argument can be None to signify an empty tree.

kevinw commented Sep 7, 2012

I force pushed a better commit, just checking for a tree with value None in dulwich.index.changes_from_tree. I also added a unit test verifying the new behavior.


jelmer commented Sep 8, 2012

Any reason you can't just pass in the id of an empty tree:

from dulwich.objects import Tree


kevinw commented Sep 10, 2012

Because asking index.changes_from_tree(objstore, Tree().id)) results in a traceback:

    changes = list(index.changes_from_tree(objstore, head_tree))
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/index.py", line 286, in changes_from_tree
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/index.py", line 363, in changes_from_tree
    for (name, mode, sha) in object_store.iter_tree_contents(tree):
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/object_store.py", line 157, in iter_tree_contents
    for entry, _ in walk_trees(self, tree_id, None):
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/diff_tree.py", line 148, in walk_trees
    tree1 = is_tree1 and store[entry1.sha] or None
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/object_store.py", line 112, in __getitem__
    type_num, uncomp = self.get_raw(sha)
  File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dulwich/object_store.py", line 322, in get_raw
    raise KeyError(hexsha)
KeyError: '4b825dc642cb6eb9a060e54bf8d69288fbee4904'

jelmer commented Sep 11, 2012

You could add the empty tree to the repository though, or special case that? I'm just pondering what the right level is to add this sort of special casing.

kevinw commented Sep 29, 2012

I'm not sure at which abstraction you mean, or what asking an object store for the empty tree would return...


jelmer commented Oct 8, 2012

On Sat, 2012-09-29 at 16:50 -0700, Kevin Watters wrote:

I'm not sure at which abstraction you mean, or what asking an object
store for the empty tree would return...

I mean that
repo.object_store.getitem('4b825dc642cb6eb9a060e54bf8d69288fbee4904') would return Tree() (with no contents), rather than special casing empty trees in all other functions.




jelmer commented May 25, 2013

Merged in its current form - we can always iterate over this. Thanks for the patch!

@jelmer jelmer closed this May 25, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment