Skip to content

Repository.diff fails when treeish is "empty" #432

Closed

Description

@Inkane

Repository.diff contains https://github.com/libgit2/pygit2/blob/master/pygit2/repository.py#L390
This causes a subsequent failure when a is pygit2.Commit and len(a.tree) is 0, because a treeish_to_tree(a) evaluates to False in this case. Consequently, a will be the Commit object afterwards.
An example for such a commit is eb02887bc34130647a52f8152c13531d97f5a058 from https://github.com/twbs/bootstrap.git . https://stackoverflow.com/questions/9765453/gits-semi-secret-empty-tree might shed some light on the empty tree.

Activity

  1. added a commit that references this issue on Oct 6, 2014
  2. carlosmn commented on Oct 6, 2014

    @carlosmn
    Member

    So git is assuming that every other implementation is going to support the fake empty tree and it doesn't bother writing the actual tree it wants to use to disc? That is quite worrying.

  3. added a commit that references this issue on Oct 6, 2014
    156a82e
  4. carlosmn commented on Oct 6, 2014

    @carlosmn
    Member

    This behaviour has nothing to do with git-core's special handling of the empty tree in some situations, or really with the Git system at all, it's purely an unfortunate decision in Python to consider that an object with a sequence interface is falsy just because the length of that aspect is zero.

  5. added 3 commits that reference this issue on Oct 6, 2014
    2031136
    947e409
    d0aaa64
  6. jdavid commented on Oct 7, 2014

    @jdavid
    Member

    I disagree with the solution. It is the code in Repository.diff which is wrong and should be spelled
    differently. It should be explicit.

    Regarding the if len == 0 then falsy debate, I have not yet stop to think about it, so I don't
    have an opinion yet, anyway, that's to be discussed in PR #433

  7. jdavid commented on Oct 7, 2014

    @jdavid
    Member

    There is by the way at least one more bug, when the input is a reference.

  8. carlosmn commented on Oct 7, 2014

    @carlosmn
    Member

    There are more issues with this method, yes. I have a refactored version which should clear away the issue as well.

  9. carlosmn commented on Oct 7, 2014

    @carlosmn
    Member

    PR #434 would also fix this, as well as working for references.

  10. jdavid commented on Oct 7, 2014

    @jdavid
    Member

    @carlosmn ouch, just pushed my version, feel free to improve it

    @Inkane please check if it works for you

  11. Inkane commented on Oct 7, 2014

    @Inkane
    Author

    @jdavid : Your change does indeed fix my issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions