You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/06/25 16:43:30 UTC
[07/13] allura git commit: [#7873] Performance improvements when
accessing tags and branches in git
[#7873] Performance improvements when accessing tags and branches in git
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/646d665c
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/646d665c
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/646d665c
Branch: refs/heads/hs/7873
Commit: 646d665c48a83f1fc7c40d850c58f18d818a3a93
Parents: b714827
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Tue May 5 13:47:19 2015 +0000
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Jun 25 14:10:34 2015 +0000
----------------------------------------------------------------------
ForgeGit/forgegit/git_main.py | 2 +-
ForgeGit/forgegit/model/git_repo.py | 32 +++++++++++++++++++++++++++++---
2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/646d665c/ForgeGit/forgegit/git_main.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index 62fc0f7..bb19ec3 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -66,7 +66,7 @@ class ForgeGitApp(RepositoryApp):
def repo(self):
return GM.Repository.query.get(app_config_id=self.config._id)
- @property
+ @LazyProperty
def default_branch_name(self):
return self.repo.get_default_branch('master')
http://git-wip-us.apache.org/repos/asf/allura/blob/646d665c/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 416db33..d6e791c 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -533,6 +533,32 @@ class GitImplementation(M.RepositoryImplementation):
return False
@LazyProperty
+ def _is_valid(self):
+ """ Verifies the validity of the reference objects in the git database
+
+ Returns True if no issues are found. This allows us to bypass the individual testing of each ref
+ unless absolutely necessary.
+
+ :rtype: bool
+ """
+ try:
+ self._git.git.fsck(full=True)
+ return True
+ except git.GitCommandError as gce:
+ log.debug(u"Found inconsistency in {}: {}".format(self._repo.name, gce.stderr))
+ return False
+
+ def _get_refs(self, ref_list):
+ """ Returns a list of valid reference objects from the git database
+
+ :return: List of git ref objects.
+ :rtype: list
+ """
+ if self._is_valid:
+ return [Object(name=ref.name, object_id=ref.commit.hexsha) for ref in ref_list]
+ return [Object(name=ref.name, object_id=ref.commit.hexsha) for ref in ref_list if ref.is_valid()]
+
+ @LazyProperty
def head(self):
if not self._git or not self._git.heads:
return None
@@ -549,15 +575,15 @@ class GitImplementation(M.RepositoryImplementation):
@LazyProperty
def heads(self):
- return [Object(name=b.name, object_id=b.commit.hexsha) for b in self._git.heads if b.is_valid()]
+ return self._get_refs(self._git.heads)
@LazyProperty
def branches(self):
- return [Object(name=b.name, object_id=b.commit.hexsha) for b in self._git.branches if b.is_valid()]
+ return self._get_refs(self._git.branches)
@LazyProperty
def tags(self):
- return [Object(name=t.name, object_id=t.commit.hexsha) for t in self._git.tags if t.is_valid()]
+ return self._get_refs(self._git.tags)
def set_default_branch(self, name):
if not name: