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 E53D3E5DF for ; Tue, 5 Feb 2013 20:23:34 +0000 (UTC) Received: (qmail 91378 invoked by uid 500); 5 Feb 2013 20:23:34 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 91362 invoked by uid 500); 5 Feb 2013 20:23:34 -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 91352 invoked by uid 99); 5 Feb 2013 20:23:34 -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, 05 Feb 2013 20:23:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9449F82A7A1; Tue, 5 Feb 2013 20:23:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tvansteenburgh@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [42/42] git commit: [#4691] Code cleanup on Git commits implementation Message-Id: <20130205202334.9449F82A7A1@tyr.zones.apache.org> Date: Tue, 5 Feb 2013 20:23:34 +0000 (UTC) Updated Branches: refs/heads/master ab5af7e43 -> 0fb11fe39 [#4691] Code cleanup on Git commits implementation 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/7fd94b9d Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/7fd94b9d Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/7fd94b9d Branch: refs/heads/master Commit: 7fd94b9d8df80e6ba762e8c1fe4d3688dededead Parents: 4d8ce02 Author: Cory Johns Authored: Tue Jan 29 21:48:16 2013 +0000 Committer: Tim Van Steenburgh Committed: Tue Feb 5 20:22:52 2013 +0000 ---------------------------------------------------------------------- Allura/allura/model/repo.py | 8 +++-- ForgeGit/forgegit/model/git_repo.py | 23 +++++++--------- ForgeGit/forgegit/tests/model/test_repository.py | 6 ++-- 3 files changed, 18 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fd94b9d/Allura/allura/model/repo.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py index e5c6210..b90b0c7 100644 --- a/Allura/allura/model/repo.py +++ b/Allura/allura/model/repo.py @@ -209,13 +209,15 @@ class Commit(RepoObject): except IndexError as e: return None - def climb_commit_tree(self): + def climb_commit_tree(self, predicate=None): ''' Returns a generator that walks up the commit tree along - the first-parent ancestory, starting with this commit.''' + the first-parent ancestory, starting with this commit, + optionally filtering by a predicate.''' ancestor = self while ancestor: - yield ancestor + if predicate is None or predicate(ancestor): + yield ancestor ancestor = ancestor.get_parent() def url(self): http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fd94b9d/ForgeGit/forgegit/model/git_repo.py ---------------------------------------------------------------------- diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py index 6360dfd..1e8e3d7 100644 --- a/ForgeGit/forgegit/model/git_repo.py +++ b/ForgeGit/forgegit/model/git_repo.py @@ -1,8 +1,10 @@ import os +import sys import shutil import string import logging import random +import itertools from collections import namedtuple from datetime import datetime from glob import glob @@ -239,21 +241,16 @@ class GitImplementation(M.RepositoryImplementation): def commits(self, path=None, rev=None, skip=None, limit=None): if rev is None: rev = 'HEAD' - if skip is None: - skip = 0 + start = skip or 0 + stop = start + limit if limit is not None else None + predicate = None if path is not None: path = path.strip('/') - max = skip + limit if limit is not None else None - commit = self.commit(rev) - i = 0 - while commit: - if path is None or path in commit.changed_paths: - if i >= skip: - yield commit._id - i += 1 - if max is not None and i >= max: - break - commit = commit.get_parent() + predicate = lambda c: path in c.changed_paths + + iter_tree = self.commit(rev).climb_commit_tree(predicate) + for commit in itertools.islice(iter_tree, start, stop): + yield commit._id def commits_count(self, path=None, rev=None): commit = self._git.commit(rev) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7fd94b9d/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 d18b017..75ff504 100644 --- a/ForgeGit/forgegit/tests/model/test_repository.py +++ b/ForgeGit/forgegit/tests/model/test_repository.py @@ -266,12 +266,12 @@ class TestGitCommit(unittest.TestCase): assert list(self.repo.commits('does/not/exist')) == [] # with path and start rev commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a')) - assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a'], commits + assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a']) # skip and limit commits = list(self.repo.commits(None, rev=None, skip=1, limit=2)) - assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a', '6a45885ae7347f1cac5103b0050cc1be6a1496c8'] + assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a', '6a45885ae7347f1cac5103b0050cc1be6a1496c8']) commits = list(self.repo.commits(None, '6a45885ae7347f1cac5103b0050cc1be6a1496c8', skip=1)) - assert commits == ['9a7df788cf800241e3bb5a849c8870f2f8259d98'] + assert_equal(commits, ['9a7df788cf800241e3bb5a849c8870f2f8259d98']) commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a', skip=1)) assert commits == [] # path to dir