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

Commit

Permalink
GitPlugin: optimiziation: make use of git's 1.5.6+ tree-ls -l featu…
Browse files Browse the repository at this point in the history
…re for grabbing blob size instead of

individual `cat-file -s` calls; bump up minimum required git version to 1.5.6
  • Loading branch information
hvr committed Mar 23, 2009
1 parent 386f4ae commit 3666f7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
39 changes: 17 additions & 22 deletions tracext/git/PyGIT.py
Expand Up @@ -146,7 +146,7 @@ def __rev_key(rev):


@staticmethod @staticmethod
def git_version(git_bin="git"): def git_version(git_bin="git"):
GIT_VERSION_MIN_REQUIRED = (1,5,2) GIT_VERSION_MIN_REQUIRED = (1,5,6)
try: try:
g = GitCore(git_bin=git_bin) g = GitCore(git_bin=git_bin)
output = g.version() output = g.version()
Expand Down Expand Up @@ -203,9 +203,7 @@ def __init__(self, git_dir, log, git_bin='git'):
self.__commit_msg_cache = SizedDict(200) self.__commit_msg_cache = SizedDict(200)
self.__commit_msg_lock = Lock() self.__commit_msg_lock = Lock()


# cache the last 2000 file sizes
self.__fs_obj_size_cache = SizedDict(2000)
self.__fs_obj_size_lock = Lock()


def __del__(self): def __del__(self):
self.logger.debug("PyGIT.Storage instance %d destructed" % id(self)) self.logger.debug("PyGIT.Storage instance %d destructed" % id(self))
Expand Down Expand Up @@ -483,18 +481,21 @@ def ls_tree(self, rev, path=""):
if path.startswith('/'): if path.startswith('/'):
path = path[1:] path = path[1:]


if path: tree = self.repo.ls_tree("-z", "-l", rev, "--", path).read().split('\0')
tree = self.repo.ls_tree("-z", rev, "--", path)
else:
tree = self.repo.ls_tree("-z", rev)


def split_ls_tree_line(l): def split_ls_tree_line(l):
"split according to '<mode> <type> <sha>\t<fname>'" "split according to '<mode> <type> <sha> <size>\t<fname>'"
meta,fname = l.split('\t') meta,fname = l.split('\t')
_mode,_type,_sha = meta.split(' ') _mode,_type,_sha,_size = meta.split()
return _mode,_type,_sha,fname
if _size == '-':
_size = None
else:
_size = int(_size)


return [split_ls_tree_line(e) for e in tree.read().split('\0') if e] return _mode,_type,_sha,_size,fname

return [ split_ls_tree_line(e) for e in tree if e ]


def read_commit(self, commit_id): def read_commit(self, commit_id):
if not commit_id: if not commit_id:
Expand Down Expand Up @@ -539,13 +540,9 @@ def get_file(self, sha):


def get_obj_size(self, sha): def get_obj_size(self, sha):
sha = str(sha) sha = str(sha)

try: try:
with self.__fs_obj_size_lock: obj_size = int(self.repo.cat_file("-s", sha).read().strip())
if self.__fs_obj_size_cache.has_key(sha):
obj_size = self.__fs_obj_size_cache[sha]
else:
obj_size = int(self.repo.cat_file("-s", sha).read().strip())
self.__fs_obj_size_cache[sha] = obj_size
except ValueError: except ValueError:
raise GitErrorSha("object '%s' not found" % sha) raise GitErrorSha("object '%s' not found" % sha)


Expand Down Expand Up @@ -770,8 +767,6 @@ def check4loops(head):
for sha in g.children_recursive(head): for sha in g.children_recursive(head):
if sha in seen: if sha in seen:
print "dupe detected :-/", sha, len(seen) print "dupe detected :-/", sha, len(seen)
#print seen
#break
seen.add(sha) seen.add(sha)
return seen return seen


Expand Down Expand Up @@ -802,10 +797,10 @@ def shortrev_test():


# perform typical trac operations: # perform typical trac operations:


if 0: if 1:
print "--------------" print "--------------"
rev = g.head() rev = g.head()
for mode,type,sha,name in g.ls_tree(rev): for mode,type,sha,_size,name in g.ls_tree(rev):
[last_rev] = g.history(rev, name, limit=1) [last_rev] = g.history(rev, name, limit=1)
s = g.get_obj_size(sha) if type == "blob" else 0 s = g.get_obj_size(sha) if type == "blob" else 0
msg = g.read_commit(last_rev) msg = g.read_commit(last_rev)
Expand Down
4 changes: 2 additions & 2 deletions tracext/git/git_fs.py
Expand Up @@ -290,7 +290,7 @@ def __init__(self, git, path, rev, log, ls_tree_info=None):
if not ls_tree_info: if not ls_tree_info:
raise NoSuchNode(path, rev) raise NoSuchNode(path, rev)


(self.fs_perm, k, self.fs_sha, fn) = ls_tree_info (self.fs_perm, k, self.fs_sha, self.fs_size, fn) = ls_tree_info


# fix-up to the last commit-rev that touched this node # fix-up to the last commit-rev that touched this node
rev = self.git.last_change(rev, p) rev = self.git.last_change(rev, p)
Expand Down Expand Up @@ -338,7 +338,7 @@ def get_entries(self):
return return


for ent in self.git.ls_tree(self.rev, self.__git_path()): for ent in self.git.ls_tree(self.rev, self.__git_path()):
yield GitNode(self.git, ent[3], self.rev, self.log, ent) yield GitNode(self.git, ent[-1], self.rev, self.log, ent)


def get_content_type(self): def get_content_type(self):
if self.isdir: if self.isdir:
Expand Down

0 comments on commit 3666f7f

Please sign in to comment.