Skip to content
This repository has been archived by the owner on May 22, 2019. It is now read-only.

Commit

Permalink
GitPlugin:
Browse files Browse the repository at this point in the history
performance improvements

addresses #746
  • Loading branch information
hvr committed Sep 29, 2006
1 parent 4f6afb1 commit ce830e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 8 additions & 2 deletions gitplugin/PyGIT.py
Expand Up @@ -14,12 +14,15 @@

import os, re

class GIT:
class GitError(Exception):
pass

class Storage:
def __init__(self,repo):
self.repo = repo

def _git_call_f(self,cmd):
#print cmd
#print "GIT: "+cmd
(input, output, error) = os.popen3('GIT_DIR="%s" %s' % (self.repo,cmd))
return output

Expand Down Expand Up @@ -52,6 +55,9 @@ def read_commit(self, sha):
def get_file(self, sha):
return self._git_call_f("git-cat-file blob "+sha)

def get_obj_size(self, sha):
return int(self._git_call("git-cat-file -s "+sha).strip())

def parents(self, sha):
tmp=self._git_call("git-rev-list --max-count=1 --parents "+sha)
tmp=tmp.strip()
Expand Down
21 changes: 14 additions & 7 deletions gitplugin/git_fs.py
Expand Up @@ -31,7 +31,7 @@ def get_repository(self, type, dir, authname):
class GitRepository(Repository):
def __init__(self, path, log):
self.gitrepo = path
self.git = PyGIT.GIT(path)
self.git = PyGIT.Storage(path)
Repository.__init__(self, "git:"+path, None, log)

def get_youngest_rev(self):
Expand Down Expand Up @@ -110,14 +110,19 @@ def sync(self):


class GitNode(Node):
def __init__(self, git, path, rev):
def __init__(self, git, path, rev, tree_ls_info=None):
self.git = git
self.sha = rev;
self.perm = None;
self.sha = rev
self.perm = None
self.data_len = None

kind = Node.DIRECTORY
p = path.strip('/')
if p != "":
[(self.perm,k,self.sha,fn)]=git.tree_ls(rev, p)
if tree_ls_info:
(self.perm,k,self.sha,fn)=tree_ls_info
else:
[(self.perm,k,self.sha,fn)]=git.tree_ls(rev, p)
rev=self.git.last_change(rev, p)
if k=='tree':
pass
Expand Down Expand Up @@ -152,7 +157,7 @@ def get_entries(self):
p = self.path.strip('/')
if p != '': p = p + '/'
for e in self.git.tree_ls(self.rev, p):
yield GitNode(self.git, e[3], self.rev)
yield GitNode(self.git, e[3], self.rev, e)

def get_content_type(self):
if self.isdir:
Expand All @@ -161,7 +166,9 @@ def get_content_type(self):

def get_content_length(self):
if self.isfile:
return len(self.get_content().read())
if not self.data_len:
self.data_len = self.git.get_obj_size(self.sha)
return self.data_len
return None

def get_history(self, limit=None):
Expand Down

0 comments on commit ce830e3

Please sign in to comment.