Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D86BC1093A for ; Mon, 21 Oct 2013 22:35:40 +0000 (UTC) Received: (qmail 68279 invoked by uid 500); 21 Oct 2013 22:34:25 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 68201 invoked by uid 500); 21 Oct 2013 22:34:21 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 68156 invoked by uid 99); 21 Oct 2013 22:34:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 22:34:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 439D54F8BE; Mon, 21 Oct 2013 22:34:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org Date: Mon, 21 Oct 2013 22:34:21 -0000 Message-Id: <251df6d57f9c4faf9cdca0c0596631a4@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/9] git commit: [#6686] Refactored prefix_paths_union and added tests [#6686] Refactored prefix_paths_union and added tests Signed-off-by: Cory Johns 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/6777 Commit: d91c8ff8fdb84bf5330406bff901e743ab1a12d2 Parents: 2139f13 Author: Cory Johns Authored: Mon Oct 21 21:02:43 2013 +0000 Committer: Cory Johns 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