Skip to content

Instantly share code, notes, and snippets.

@tail
Created August 4, 2011 00:47
Show Gist options
  • Save tail/1124259 to your computer and use it in GitHub Desktop.
Save tail/1124259 to your computer and use it in GitHub Desktop.
import os
from time import time
from pygit2 import *
def do_foo():
# Create a Repository, add an Index, and create Reference.
os.system('rm -rf /tmp/pygit2test')
repo = init_repository('/tmp/pygit2test', False)
fp = open('/tmp/pygit2test/foo', 'w')
fp.write('Hello, world!')
fp.close()
index = repo.index
index.add('foo')
index.write()
message = 'Testing segfault in pygit2.'
author = ('Test', 'test@example.com', int(time()), 0)
sha = repo.create_commit(None, author, author, message, index.create_tree(), [])
repo.create_reference('refs/heads/master', sha)
def main():
do_foo()
# Expect objects created in do_foo() to get cleaned up.
# Crashes here when using a debug version of CPython.
# Fatal Python error: pygit2.c:1654 object at 0x7f73cd9b82c0 has negative ref count -2604246222170760230
# Aborted
# pygit2.c:1654 is Py_XDECREF(self->repo) in Index_dealloc.
# Create another repository and attempt to use the tree object.
repo = Repository('/tmp/pygit2test/.git')
ref = repo.lookup_reference('refs/heads/master')
commit = repo[ref.sha]
print commit.tree.sha # This line is segfaulting (non-debug).
# 2 0x0000000101d42294 in Commit_get_tree (commit=0x10042918f) at pygit2.c:1049
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment