incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [47/50] git commit: [#6686] Refactored prefix_paths_union and added tests
Date Tue, 22 Oct 2013 21:50:57 GMT
[#6686] Refactored prefix_paths_union and added tests

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/cj/6422
Commit: d91c8ff8fdb84bf5330406bff901e743ab1a12d2
Parents: 2139f13
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Oct 21 21:02:43 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Oct 21 21:02:43 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py     | 16 ++++++++++++++++
 Allura/allura/tests/unit/test_repo.py | 19 ++++++++++++++++++-
 ForgeGit/forgegit/model/git_repo.py   | 16 +---------------
 3 files changed, 35 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d91c8ff8/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 04c4063..fa36e73 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -745,6 +745,22 @@ def topological_sort(graph):
     assert not graph, 'Cycle detected'
 
 
+def prefix_paths_union(a, b):
+    """
+    Given two sets of paths, a and b, find the items from a that
+    are either in b or are parent directories of items in b.
+    """
+    union = a & b
+    prefixes = a - b
+    candidates = b - a
+    for prefix in prefixes:
+        for candidate in candidates:
+            if candidate.startswith(prefix + '/'):
+                union.add(prefix)
+                break
+    return union
+
+
 def zipdir(source, zipfile, exclude=None):
     """Create zip archive using zip binary."""
     zipbin = tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d91c8ff8/Allura/allura/tests/unit/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_repo.py b/Allura/allura/tests/unit/test_repo.py
index 0cdd65a..ad956b5 100644
--- a/Allura/allura/tests/unit/test_repo.py
+++ b/Allura/allura/tests/unit/test_repo.py
@@ -24,7 +24,7 @@ from pylons import tmpl_context as c
 
 from allura import model as M
 from allura.controllers.repository import topo_sort
-from allura.model.repository import zipdir
+from allura.model.repository import zipdir, prefix_paths_union
 from alluratest.controller import setup_unit_test
 
 class TestCommitRunBuilder(unittest.TestCase):
@@ -325,3 +325,20 @@ class TestZipDir(unittest.TestCase):
                 "returned non-zero exit code 1" in emsg)
         self.assertTrue("STDOUT: 1" in emsg)
         self.assertTrue("STDERR: 2" in emsg)
+
+
+class TestPrefixPathsUnion(unittest.TestCase):
+    def test_disjoint(self):
+        a = set(['a1', 'a2', 'a3'])
+        b = set(['b1', 'b1/foo', 'b2'])
+        self.assertItemsEqual(prefix_paths_union(a, b), [])
+
+    def test_exact(self):
+        a = set(['a1', 'a2', 'a3'])
+        b = set(['b1', 'a2', 'a3'])
+        self.assertItemsEqual(prefix_paths_union(a, b), ['a2', 'a3'])
+
+    def test_prefix(self):
+        a = set(['a1', 'a2', 'a3'])
+        b = set(['b1', 'a2/foo', 'b3/foo'])
+        self.assertItemsEqual(prefix_paths_union(a, b), ['a2'])

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d91c8ff8/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 1f2ae37..a06300f 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -42,7 +42,7 @@ from ming.utils import LazyProperty
 
 from allura.lib import helpers as h
 from allura.lib import utils
-from allura.model.repository import topological_sort
+from allura.model.repository import topological_sort, prefix_paths_union
 from allura import model as M
 
 log = logging.getLogger(__name__)
@@ -502,20 +502,6 @@ class GitImplementation(M.RepositoryImplementation):
         """
         Find the ID of the last commit to touch each path.
         """
-        def prefix_paths_union(a, b):
-            """
-            Given two sets of paths, a and b, find the items from a that
-            are either in b or are parent directories of items in b.
-            """
-            union = a & b
-            prefixes = a - b
-            candidates = b - a
-            for prefix in prefixes:
-                for candidate in candidates:
-                    if candidate.startswith(prefix + '/'):
-                        union.add(prefix)
-                        break
-            return union
         result = {}
         paths = set(paths)
         orig_commit_id = commit_id = commit._id


Mime
View raw message