allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject allura git commit: [#7873] Optimize validation for git branches and tags
Date Wed, 10 Jun 2015 14:48:33 GMT
Repository: allura
Updated Branches:
  refs/heads/hs/7873 6027e4e6f -> 2702dfc23


[#7873] Optimize validation for git branches and tags


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2702dfc2
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2702dfc2
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2702dfc2

Branch: refs/heads/hs/7873
Commit: 2702dfc23b9dd80ee31f5949c20d9a4cbd4ab5fa
Parents: 6027e4e
Author: Heith Seewald <hseewald@slashdotmedia.com>
Authored: Wed Jun 10 10:47:57 2015 -0400
Committer: Heith Seewald <hseewald@slashdotmedia.com>
Committed: Wed Jun 10 10:47:57 2015 -0400

----------------------------------------------------------------------
 ForgeGit/forgegit/model/git_repo.py | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2702dfc2/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 5470e72..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]
+        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]
+        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]
+        return self._get_refs(self._git.tags)
 
     def set_default_branch(self, name):
         if not name:


Mime
View raw message