libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.62k stars 387 forks source link

_pygit2.GitError: failed to parse commit e442edaa7d02afcf97f1f2976ab413dab8283b1d - cannot parse commit ti me #947

Open ddevault opened 5 years ago

ddevault commented 5 years ago

Commit e442edaa7d02afcf97f1f2976ab413dab8283b1d can be found in this repository:

https://git.sr.ht/~kvik/unionfs

git upstream shows this commit as being authored at the epoch.

jdavid commented 4 years ago

hey! Just cloned the repo but that commit is not there:

$ git clone https://git.sr.ht/~kvik/unionfs
Cloning into 'unionfs'...
remote: Enumerating objects: 143, done.
remote: Counting objects: 100% (143/143), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 143 (delta 83), reused 120 (delta 70)
Receiving objects: 100% (143/143), 23.18 KiB | 88.00 KiB/s, done.
Resolving deltas: 100% (83/83), done.
$ cd unionfs/
$ git log e442edaa7d02afcf97f1f2976ab413dab8283b1d
fatal: bad object e442edaa7d02afcf97f1f2976ab413dab8283b1d
ddevault commented 4 years ago

I should've made a git archive, eh.

jdavid commented 4 years ago

But it can be reproduced:

from pygit2 import Repository
repo = Repository('issue947/test')
repo.get(repo.head.target)
Traceback (most recent call last):
  File "issue947.py", line 3, in <module>
    repo.get(repo.head.target)
  File "/home/jdavid/sandboxes/pygit2/pygit2/repository.py", line 125, in get
    value = self.git_object_lookup_prefix(key)
ValueError: 5e6e4debbbba291b73cb985f2a904326cb0d5961: failed to parse signature - invalid Unix timestamp

Now it actually depends how the commit is done, because this works:

$ git init test && cd test
$ touch test.txt && git add test.txt
$ git commit --date="1970-01-01T00:00:00Z" -m "epoch"
$ git log
commit b2ee1d17cb84b07bcea15b6db3e7225ac771c1ae (HEAD -> master)
Author: J. David Ibáñez <jdavid.ibp@gmail.com>
Date:   Thu Jan 1 00:00:00 1970 +0000

    epoch

$ git log --pretty=raw
commit edf4d4067e631fa49cdc4f9bd054a7adeeed37ca
tree 5efb9bc29c482e023e40e0a2b3b7e49cec842034
author J. David Ibáñez <jdavid.ibp@gmail.com> 0 +0000
committer J. David Ibáñez <jdavid.ibp@gmail.com> 1583584590 +0100

    epoch

But this doesn't (the only difference is there's no Z in the date)

$ git init test && cd test
$ touch test.txt && git add test.txt
$ git commit --date="1970-01-01T00:00:00" -m "epoch"
$ git log
commit 5e6e4debbbba291b73cb985f2a904326cb0d5961 (HEAD -> master)
Author: J. David Ibáñez <jdavid.ibp@gmail.com>
Date:   Thu Jan 1 00:00:00 1970 +0000

    epoch

$ git log --pretty=raw
commit 5e6e4debbbba291b73cb985f2a904326cb0d5961
tree 5efb9bc29c482e023e40e0a2b3b7e49cec842034
author J. David Ibáñez <jdavid.ibp@gmail.com> 18446744073709548016 +0100
committer J. David Ibáñez <jdavid.ibp@gmail.com> 1583584805 +0100

    epoch

In any case this is a libgit2 issue. Since Git can produce these commits it may be considered a bug. Ping @ethomson