You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/02/06 16:42:52 UTC

[33/50] git commit: [#4691] Code cleanup on Git commits implementation

[#4691] Code cleanup on Git commits implementation

Signed-off-by: Cory Johns <jo...@geek.net>


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/cj/4691
Commit: 7fd94b9d8df80e6ba762e8c1fe4d3688dededead
Parents: 4d8ce02
Author: Cory Johns <jo...@geek.net>
Authored: Tue Jan 29 21:48:16 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
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