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 2012/12/04 00:57:05 UTC

[8/10] git commit: [#5037] ticket:202 commits filtering for git

[#5037] ticket:202 commits filtering for git


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

Branch: refs/heads/master
Commit: e7cd07157315b9dc39b8869fc4315da5ebd7acc0
Parents: 55924a8
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Nov 5 15:35:10 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Mon Dec 3 23:56:21 2012 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py          |   13 ++----
 Allura/allura/model/repository.py                |   17 +++++---
 ForgeGit/forgegit/model/git_repo.py              |   18 ++++++--
 ForgeGit/forgegit/tests/model/test_repository.py |   36 +++++++++++++----
 4 files changed, 57 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e7cd0715/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 0dc101d..350c8a8 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -428,15 +428,12 @@ class CommitBrowser(BaseController):
                    limit=validators.Int(if_empty=25)))
     def log(self, limit=25, page=0, path="", **kw):
         limit, page, start = g.handle_paging(limit, page, default=25)
-        if path[0:1] == "/":
+        if path[0] == "/":
             path = path[1:]
-        commits = c.app.repo.get_commits_by_path(path=path)
-        index = 0
-        if self._commit._id in commits:
-            index = commits.index(self._commit._id)
-        commits = commits[index:]
-        count = len(commits)
-        revisions = M.repo.Commit.query.find({'_id': {'$in': commits[start:start + limit]}}).sort('committed.date', -1)
+        params = dict(path=path, rev=self._commit._id, skip=start, limit=limit)
+        commits = c.app.repo.commits(**params)
+        count = c.app.repo.commits(**params)
+        revisions = M.repo.Commit.query.find({'_id': {'$in': commits}}).sort('committed.date', -1)
         c.log_widget = self.log_widget
         return dict(
             username=c.user._id and c.user.username,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e7cd0715/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 6246393..8aa91e8 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -104,9 +104,13 @@ class RepositoryImplementation(object):
         '''Return a blob size in bytes'''
         raise NotImplementedError, 'blob_size'
 
-    def get_commits_by_path(self, path):
-        '''Return a list of commits'''
-        raise NotImplementedError, 'get_commits_by_path'
+    def commits(self, path=None, rev=None, skip=None, limit=None):
+        '''Return a list of the commits related to path'''
+        raise NotImplementedError, 'commits'
+
+    def commits_count(self, path=None, rev=None):
+        '''Return count of the commits related to path'''
+        raise NotImplementedError, 'commits_count'
 
     @classmethod
     def shorthand_for_commit(cls, oid):
@@ -219,6 +223,10 @@ class Repository(Artifact, ActivityObject):
         return self._impl.url_for_commit(commit)
     def compute_tree_new(self, commit, path='/'):
         return self._impl.compute_tree_new(commit, path)
+    def commits(self, path=None, rev=None, skip=None, limit=None):
+        return self._impl.commits(path, rev, skip, limit)
+    def commits_count(self, path=None, rev=None):
+        return self._impl.commits_count(path, rev)
 
     def _log(self, rev, skip, limit):
         head = self.commit(rev)
@@ -228,9 +236,6 @@ class Repository(Artifact, ActivityObject):
             ci.set_context(self)
             yield ci
 
-    def get_commits_by_path(self, path):
-        return self._impl.get_commits_by_path(path)
-
     def init_as_clone(self, source_path, source_name, source_url):
         self.upstream_repo.name = source_name
         self.upstream_repo.url = source_url

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e7cd0715/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 08fe91d..cb1e685 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -234,11 +234,19 @@ class GitImplementation(M.RepositoryImplementation):
         doc.m.save(safe=False)
         return doc
 
-    def get_commits_by_path(self, path):
-        result = []
-        for c in self._git.iter_commits(paths=path):
-            result.append(c.hexsha)
-        return result
+    def commits(self, path=None, rev=None, skip=None, limit=None):
+        params = dict(paths=path)
+        if rev is not None:
+            params['rev'] = rev
+        if skip is not None:
+            params['skip'] = skip
+        if limit is not None:
+            params['max_count'] = limit
+        return [c.hexsha for c in self._git.iter_commits(**params)]
+
+    def commits_count(self, path=None, rev=None):
+        commit = self._git.commit(rev)
+        return commit.count(path)
 
     def log(self, object_id, skip, count):
         obj = self._git.commit(object_id)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/e7cd0715/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 8b930a7..c5e57f3 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -254,14 +254,34 @@ class TestGitCommit(unittest.TestCase):
         for d in diffs:
             print d
 
-    def test_get_commits_by_path(self):
-        assert ("9a7df788cf800241e3bb5a849c8870f2f8259d98"
-                in self.repo.get_commits_by_path(''))
-        assert ("1e146e67985dcd71c74de79613719bef7bddca4a"
-                in self.repo.get_commits_by_path('README'))
-        assert ("df30427c488aeab84b2352bdf88a3b19223f9d7a"
-                in self.repo.get_commits_by_path('README'))
-        assert [] == self.repo.get_commits_by_path('test')
+    def test_commits(self):
+        # path only
+        commits = self.repo.commits()
+        assert "9a7df788cf800241e3bb5a849c8870f2f8259d98" in commits, commits
+        commits = self.repo.commits('README')
+        assert "1e146e67985dcd71c74de79613719bef7bddca4a" in commits, commits
+        assert "df30427c488aeab84b2352bdf88a3b19223f9d7a" in commits, commits
+        assert self.repo.commits('does/not/exist') == []
+        # with path and start rev
+        commits = self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a')
+        assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a'], commits
+        # skip and limit
+        commits = self.repo.commits(None, rev=None, skip=1, limit=2)
+        assert commits == ['df30427c488aeab84b2352bdf88a3b19223f9d7a', '6a45885ae7347f1cac5103b0050cc1be6a1496c8']
+        commits = self.repo.commits(None, '6a45885ae7347f1cac5103b0050cc1be6a1496c8', skip=1)
+        assert commits == ['9a7df788cf800241e3bb5a849c8870f2f8259d98']
+        commits = self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a', skip=1)
+        assert commits == []
+
+    def test_commits_count(self):
+        commits = self.repo.commits_count()
+        assert commits == 4, commits
+        commits = self.repo.commits_count('README')
+        assert commits == 2, commits
+        commits = self.repo.commits_count(None, 'df30427c488aeab84b2352bdf88a3b19223f9d7a')
+        assert commits == 3, commits
+        commits = self.repo.commits_count('a/b/c/hello.txt', '6a45885ae7347f1cac5103b0050cc1be6a1496c8')
+        assert commits == 2, commits
 
 
 class TestGitHtmlView(unittest.TestCase):