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 76235109D2 for ; Tue, 4 Jun 2013 22:17:06 +0000 (UTC) Received: (qmail 10110 invoked by uid 500); 4 Jun 2013 22:17:06 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 10054 invoked by uid 500); 4 Jun 2013 22:17:06 -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 9975 invoked by uid 99); 4 Jun 2013 22:17:06 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Jun 2013 22:17:06 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F3B3A3150FB; Tue, 4 Jun 2013 22:17:05 +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: Tue, 04 Jun 2013 22:17:13 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [09/26] git commit: [#6218] Get branches and tags directly from SCM [#6218] Get branches and tags directly from SCM 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/6a3753d7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6a3753d7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6a3753d7 Branch: refs/heads/cj/6325 Commit: 6a3753d773045b66b319941ec6a264dbd20575d0 Parents: f9d1c45 Author: Cory Johns Authored: Thu May 23 23:35:00 2013 +0000 Committer: Tim Van Steenburgh Committed: Tue Jun 4 18:46:06 2013 +0000 ---------------------------------------------------------------------- Allura/allura/lib/repository.py | 27 +++++++++------ Allura/allura/model/repository.py | 10 +++++ ForgeGit/forgegit/model/git_repo.py | 6 +++ .../forgegit/tests/data/testgit.git/refs/tags/foo | 1 + ForgeGit/forgegit/tests/model/test_repository.py | 20 +++++++++++ ForgeSVN/forgesvn/model/svn.py | 6 +++ 6 files changed, 59 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/Allura/allura/lib/repository.py ---------------------------------------------------------------------- diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py index 3a432ec..afd5557 100644 --- a/Allura/allura/lib/repository.py +++ b/Allura/allura/lib/repository.py @@ -130,29 +130,34 @@ class RepositoryApp(Application): self.repo.upstream_repo.name + 'merge-requests/', small=pending_upstream_merges)) ref_url = self.repo.url_for_commit(self.default_branch_name, url_type='ref') - if self.repo.branches: + branches = self.repo.get_branches() + if branches: links.append(SitemapEntry('Branches')) + for branch in branches: + if branch.name == self.default_branch_name: + branches.remove(branch) + branches.insert(0, branch) + break max_branches = 10 - for b in self.repo.branches[:max_branches]: + for branch in branches[:max_branches]: links.append(SitemapEntry( - b.name, - quote(self.repo.url_for_commit(b.name) + 'tree/'), - small=b.count)) - if len(self.repo.branches) > max_branches: + branch.name, + quote(self.repo.url_for_commit(branch.name) + 'tree/'))) + if len(branches) > max_branches: links.append( SitemapEntry( 'More Branches', ref_url + 'branches/', )) - if self.repo.repo_tags: + tags = self.repo.get_tags() + if tags: links.append(SitemapEntry('Tags')) max_tags = 10 - for b in self.repo.repo_tags[:max_tags]: + for b in tags[:max_tags]: links.append(SitemapEntry( b.name, - quote(self.repo.url_for_commit(b.name) + 'tree/'), - small=b.count)) - if len(self.repo.repo_tags) > max_tags: + quote(self.repo.url_for_commit(b.name) + 'tree/'))) + if len(tags) > max_tags: links.append( SitemapEntry( 'More Tags', http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/Allura/allura/model/repository.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py index 1b6cfc4..1960d59 100644 --- a/Allura/allura/model/repository.py +++ b/Allura/allura/model/repository.py @@ -214,6 +214,12 @@ class RepositoryImplementation(object): os.chmod(magic_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) self._setup_hooks(source_path) + def get_branches(self): + return self.repo.branches + + def get_tags(self): + return self.repo.tags + class Repository(Artifact, ActivityObject): BATCH_SIZE=100 class __mongometa__: @@ -326,6 +332,10 @@ class Repository(Artifact, ActivityObject): return self._impl.last_commit_ids(commit, paths) def is_empty(self): return self._impl.is_empty() + def get_branches(self): + return self._impl.get_branches() + def get_tags(self): + return self._impl.get_tags() def _log(self, rev, skip, limit): head = self.commit(rev) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/ForgeGit/forgegit/model/git_repo.py ---------------------------------------------------------------------- diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py index c656dfd..5683296 100644 --- a/ForgeGit/forgegit/model/git_repo.py +++ b/ForgeGit/forgegit/model/git_repo.py @@ -361,6 +361,12 @@ class GitImplementation(M.RepositoryImplementation): def is_empty(self): return not self._git or len(self._git.heads) == 0 + def get_branches(self): + return [Object(name=b.name,object_id=b.commit.hexsha) for b in self._git.heads] + + def get_tags(self): + return [Object(name=t.name, object_id=t.commit.hexsha) for t in self._git.tags] + class _OpenedGitBlob(object): CHUNK_SIZE=4096 http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/ForgeGit/forgegit/tests/data/testgit.git/refs/tags/foo ---------------------------------------------------------------------- diff --git a/ForgeGit/forgegit/tests/data/testgit.git/refs/tags/foo b/ForgeGit/forgegit/tests/data/testgit.git/refs/tags/foo new file mode 100644 index 0000000..7e970a5 --- /dev/null +++ b/ForgeGit/forgegit/tests/data/testgit.git/refs/tags/foo @@ -0,0 +1 @@ +1e146e67985dcd71c74de79613719bef7bddca4a http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/ForgeGit/forgegit/tests/model/test_repository.py ---------------------------------------------------------------------- diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py index 46be17f..e0026b7 100644 --- a/ForgeGit/forgegit/tests/model/test_repository.py +++ b/ForgeGit/forgegit/tests/model/test_repository.py @@ -339,6 +339,26 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase): ThreadLocalORMSession.flush_all() assert repo2.is_empty() +class TestGitImplementation(unittest.TestCase): + def test_get_branches(self): + repo_dir = pkg_resources.resource_filename( + 'forgegit', 'tests/data/testgit.git') + repo = mock.Mock(full_fs_path=repo_dir) + impl = GM.git_repo.GitImplementation(repo) + self.assertEqual(impl.get_branches(), [ + Object(name='master', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'), + Object(name='zz', object_id='5c47243c8e424136fd5cdd18cd94d34c66d1955c') + ]) + + def test_get_tags(self): + repo_dir = pkg_resources.resource_filename( + 'forgegit', 'tests/data/testgit.git') + repo = mock.Mock(full_fs_path=repo_dir) + impl = GM.git_repo.GitImplementation(repo) + self.assertEqual(impl.get_tags(), [ + Object(name='foo', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'), + ]) + class TestGitCommit(unittest.TestCase): http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a3753d7/ForgeSVN/forgesvn/model/svn.py ---------------------------------------------------------------------- diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py index 811380a..f017f0b 100644 --- a/ForgeSVN/forgesvn/model/svn.py +++ b/ForgeSVN/forgesvn/model/svn.py @@ -698,5 +698,11 @@ class SVNImplementation(M.RepositoryImplementation): else: raise + def get_branches(self): + return [] + + def get_tags(self): + return [] + Mapper.compile_all()