Recreate git.Repository() on each call

It appears that pygit2 has similar to mercurial’s issue with statuses
(they are not updated) and needs to be regenerated on each call as well.
Implies to index statuses only though, that is why I used to think
pygit2 does not have this problem.
This commit is contained in:
ZyX 2013-01-04 22:18:36 +04:00 committed by Kim Silkebækken
parent 3addf44a6d
commit 5b43960e0e
1 changed files with 7 additions and 5 deletions

View File

@ -2,11 +2,13 @@ try:
import pygit2 as git
class Repository(object):
__slots__ = ('repo', 'directory')
__slots__ = ('directory')
def __init__(self, directory):
self.directory = directory
self.repo = git.Repository(directory)
def _repo(self):
return git.Repository(self.directory)
def status(self, path=None):
'''Return status of repository or file.
@ -23,7 +25,7 @@ try:
(except for merge statuses as they are not supported by libgit2).
'''
if path:
status = self.repo.status_file(path)
status = self._repo().status_file(path)
if status == git.GIT_STATUS_CURRENT:
return None
@ -54,7 +56,7 @@ try:
wt_column = ' '
index_column = ' '
untracked_column = ' '
for status in self.repo.status():
for status in self._repo().status():
if status & (git.GIT_STATUS_WT_DELETED
| git.GIT_STATUS_WT_MODIFIED):
wt_column = 'D'
@ -68,7 +70,7 @@ try:
def branch(self):
try:
ref = self.repo.lookup_reference('HEAD')
ref = self._repo().lookup_reference('HEAD')
except KeyError:
return None