allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/3] git commit: [#3060] Removed redundant commit log iteration and updated tests to new method
Date Sun, 07 Jul 2013 05:28:27 GMT
[#3060] Removed redundant commit log iteration and updated tests to new method

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: 1e27f3d88ef9ef696e1e8a72600905247320f507
Parents: 33e7fea
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Wed Jul 3 15:10:25 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Sun Jul 7 05:25:12 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repo.py                     | 20 ++---
 Allura/allura/model/repository.py               | 22 ------
 Allura/allura/tests/model/test_repo.py          |  9 ++-
 ForgeGit/forgegit/model/git_repo.py             | 14 ----
 .../forgegit/tests/model/test_repository.py     | 80 +++++++-------------
 ForgeSVN/forgesvn/model/svn.py                  | 39 ----------
 .../forgesvn/tests/model/test_repository.py     | 54 ++++---------
 7 files changed, 58 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/Allura/allura/model/repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repo.py b/Allura/allura/model/repo.py
index f683490..06a0853 100644
--- a/Allura/allura/model/repo.py
+++ b/Allura/allura/model/repo.py
@@ -783,13 +783,12 @@ class LastCommit(RepoObject):
 
     @classmethod
     def _last_commit_id(cls, commit, path):
-        commit_id = list(commit.repo.commits(path, commit._id, limit=1))
-        if commit_id:
-            commit_id = commit_id[0]
-        else:
+        try:
+            rev = commit.repo.log(commit._id, path, id_only=True).next()
+            return commit.repo.rev_to_commit_id(rev)
+        except StopIteration:
             log.error('Tree node not recognized by SCM: %s @ %s', path, commit._id)
-            commit_id = commit._id
-        return commit_id
+            return commit._id
 
     @classmethod
     def _prev_commit_id(cls, commit, path):
@@ -798,10 +797,13 @@ class LastCommit(RepoObject):
         lcid_cache = getattr(c, 'lcid_cache', '')
         if lcid_cache != '' and path in lcid_cache:
             return lcid_cache[path]
-        commit_id = list(commit.repo.commits(path, commit._id, skip=1, limit=1))
-        if not commit_id:
+        try:
+            log_iter = commit.repo.log(commit._id, path, id_only=True)
+            log_iter.next()
+            rev = log_iter.next()
+            return commit.repo.rev_to_commit_id(rev)
+        except StopIteration:
             return None
-        return commit_id[0]
 
     @classmethod
     def get(cls, tree, create=True):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 2904a39..3d893cc 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -135,14 +135,6 @@ class RepositoryImplementation(object):
         '''Return a blob size in bytes'''
         raise NotImplementedError, 'blob_size'
 
-    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'
-
     def tarball(self, revision, path=None):
         '''Create a tarball for the revision'''
         raise NotImplementedError, 'tarball'
@@ -346,10 +338,6 @@ class Repository(Artifact, ActivityObject):
         return self._impl.url_for_commit(commit, url_type)
     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 last_commit_ids(self, commit, paths):
         return self._impl.last_commit_ids(commit, paths)
     def is_empty(self):
@@ -433,16 +421,6 @@ class Repository(Artifact, ActivityObject):
             exclude = [exclude]
         return self._impl.log(revs, path, exclude=exclude, id_only=id_only, **kw)
 
-    def commitlog(self, revs):
-        """
-        Return a generator that returns Commit model instances reachable by
-        the commits specified by revs.
-        """
-        for ci_id in self.log(revs, id_only=True):
-            commit = self.commit(ci_id)
-            commit.set_context(self)
-            yield commit
-
     def latest(self, branch=None):
         if self._impl is None:
             return None

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 3880629..5d9e95e 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -98,7 +98,8 @@ class TestLastCommit(unittest.TestCase):
         setup_global_objects()
         self.repo = mock.Mock('repo', _commits=OrderedDict(), _last_commit=None)
         self.repo.shorthand_for_commit = lambda _id: _id[:6]
-        self.repo.commits = self._commits
+        self.repo.rev_to_commit_id = lambda rev: rev
+        self.repo.log = self._log
         lcids = M.repository.RepositoryImplementation.last_commit_ids.__func__
         self.repo.last_commit_ids = lambda *a, **k: lcids(self.repo, *a, **k)
         c.lcid_cache = {}
@@ -155,8 +156,10 @@ class TestLastCommit(unittest.TestCase):
         self.repo._commits[commit._id] = commit
         return commit
 
-    def _commits(self, path, commit_id, skip=0, limit=-1):
-        return [c._id for c in reversed(self.repo._commits.values()) if path in c.changed_paths][skip:limit]
+    def _log(self, revs, path, id_only=True):
+        for commit_id, commit in reversed(self.repo._commits.items()):
+            if path in commit.changed_paths:
+                yield commit_id
 
     def test_single_commit(self):
         commit1 = self._add_commit('Commit 1', [

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 0da371d..9906c0b 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -266,20 +266,6 @@ class GitImplementation(M.RepositoryImplementation):
         doc.m.save(safe=False)
         return doc
 
-    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, revs=None, path=None, exclude=None, id_only=True, **kw):
         """
         Returns a generator that returns information about commits reachable

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/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 dba95ae..85777e2 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -471,59 +471,35 @@ class TestGitCommit(unittest.TestCase):
         for d in diffs:
             print d
 
-    def test_commits(self):
+    def test_log(self):
         # path only
-        commits = list(self.repo.commits())
-        assert len(commits) == 4, 'Returned %s commits' % len(commits)
-        assert "9a7df788cf800241e3bb5a849c8870f2f8259d98" in commits, commits
-        commits = list(self.repo.commits('README'))
-        assert len(commits) == 2, 'Returned %s README commits' % len(commits)
-        assert "1e146e67985dcd71c74de79613719bef7bddca4a" in commits, commits
-        assert "df30427c488aeab84b2352bdf88a3b19223f9d7a" in commits, commits
-        assert list(self.repo.commits('does/not/exist')) == []
-        # with path and start rev
-        commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'))
-        assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a'])
-        # skip and limit
-        commits = list(self.repo.commits(None, rev=None, skip=1, limit=2))
-        assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a', '6a45885ae7347f1cac5103b0050cc1be6a1496c8'])
-        commits = list(self.repo.commits(None, '6a45885ae7347f1cac5103b0050cc1be6a1496c8',
skip=1))
-        assert_equal(commits, ['9a7df788cf800241e3bb5a849c8870f2f8259d98'])
-        commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a',
skip=1))
-        assert commits == []
-        # path to dir
-        commits = list(self.repo.commits('a/b/c/'))
-        assert commits == ['6a45885ae7347f1cac5103b0050cc1be6a1496c8', '9a7df788cf800241e3bb5a849c8870f2f8259d98']
-        commits = list(self.repo.commits('a/b/c/', skip=1))
-        assert commits == ['9a7df788cf800241e3bb5a849c8870f2f8259d98']
-        commits = list(self.repo.commits('a/b/c/', limit=1))
-        assert commits == ['6a45885ae7347f1cac5103b0050cc1be6a1496c8']
-        commits = list(self.repo.commits('not/exist/'))
-        assert commits == []
-        # with missing add record
-        commit = M.repo.Commit.query.get(_id='df30427c488aeab84b2352bdf88a3b19223f9d7a')
-        commit.changed_paths = []
-        commits = list(self.repo.commits('README', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'))
-        assert_equal(commits, ['df30427c488aeab84b2352bdf88a3b19223f9d7a'])
-        # with missing add record & no parent
-        commit = M.repo.Commit.query.get(_id='9a7df788cf800241e3bb5a849c8870f2f8259d98')
-        commit.changed_paths = ['a']
-        commits = list(self.repo.commits('a/b/c/hello.txt', '9a7df788cf800241e3bb5a849c8870f2f8259d98'))
-        assert_equal(commits, ['9a7df788cf800241e3bb5a849c8870f2f8259d98'])
-
-    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
-        commits = self.repo.commits_count('a/b/c/')
-        assert commits == 2, commits
-        commits = self.repo.commits_count('not/exist/')
-        assert commits == 0, commits
+        commits = list(self.repo.log(id_only=True))
+        assert_equal(commits, [
+                "1e146e67985dcd71c74de79613719bef7bddca4a",
+                "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+                "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
+                "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+            ])
+        commits = list(self.repo.log(self.repo.head, 'README', id_only=True))
+        assert_equal(commits, [
+                "1e146e67985dcd71c74de79613719bef7bddca4a",
+                "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+            ])
+        commits = list(self.repo.log("df30427c488aeab84b2352bdf88a3b19223f9d7a", 'README',
id_only=True))
+        assert_equal(commits, [
+                "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+            ])
+        commits = list(self.repo.log(self.repo.head, '/a/b/c/', id_only=True))
+        assert_equal(commits, [
+                "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
+                "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+            ])
+        commits = list(self.repo.log("9a7df788cf800241e3bb5a849c8870f2f8259d98", '/a/b/c/',
id_only=True))
+        assert_equal(commits, [
+                "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+            ])
+        commits = list(self.repo.log(self.repo.head, '/does/not/exist/', id_only=True))
+        assert_equal(commits, [])
 
 
 class TestGitHtmlView(unittest.TestCase):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index e348850..1ff9564 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -620,45 +620,6 @@ class SVNImplementation(M.RepositoryImplementation):
     def _oid(self, revno):
         return '%s:%s' % (self._repo._id, revno)
 
-    def commits(self, path=None, rev=None, skip=None, limit=None):
-        if path is not None:
-            path = '%s/%s' % (self._url, path)
-        else:
-            path = self._url
-        opts = {}
-        if rev is not None:
-            opts['revision_start'] = pysvn.Revision(pysvn.opt_revision_kind.number, self._revno(rev))
-            opts['revision_end'] = pysvn.Revision(pysvn.opt_revision_kind.number, 0)
-        if skip is None: skip = 0
-        if limit:
-            # we need to expand limit to include skipped revs (pysvn doesn't support skip)
-            opts['limit'] = skip + limit
-        try:
-            revs = self._svn.log(path, **opts)
-        except pysvn.ClientError as e:
-            log.exception('ClientError processing commits for SVN: path %s, rev %s, skip=%s,
limit=%s, treating as empty',
-                    path, rev, skip, limit)
-            return []
-        if skip:
-            # pysvn has already limited result for us, we just need to skip
-            revs = revs[skip:]
-        return [self._oid(r.revision.number) for r in revs]
-
-    def commits_count(self, path=None, rev=None):
-        if path is not None:
-            path = '%s/%s' % (self._url, path)
-        else:
-            path = self._url
-        opts = {}
-        if rev is not None:
-            opts['revision_start'] = pysvn.Revision(pysvn.opt_revision_kind.number, self._revno(rev))
-            opts['revision_end'] = pysvn.Revision(pysvn.opt_revision_kind.number, 0)
-        try:
-            return len(self._svn.log(path, **opts))
-        except pysvn.ClientError as e:
-            log.exception('ClientError processing commits for SVN: path %s, rev %s, treating
as empty', path, rev)
-            return 0
-
     def last_commit_ids(self, commit, paths):
         '''
         Return a mapping {path: commit_id} of the _id of the last

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e27f3d8/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index 3f5182a..e47158f 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -559,46 +559,19 @@ class TestSVNRev(unittest.TestCase):
     def _oid(self, rev_id):
         return '%s:%s' % (self.repo._id, rev_id)
 
-    def test_commits(self):
+    def test_log(self):
         # path only
-        commits = self.repo.commits()
-        assert len(commits) == 5, 'Returned %s commits' % len(commits)
-        assert self._oid(5) in commits, commits
-        assert self._oid(1) in commits, commits
-        commits = self.repo.commits('README')
-        assert commits == [self._oid(3), self._oid(1)]
-        assert self.repo.commits('does/not/exist') == []
-        # with path and start rev
-        commits = self.repo.commits('README', self._oid(1))
-        assert commits == [self._oid(1)], commits
-        # skip and limit
-        commits = self.repo.commits(None, rev=None, skip=1, limit=2)
-        assert commits == [self._oid(4), self._oid(3)]
-        commits = self.repo.commits(None, self._oid(2), skip=1)
-        assert commits == [self._oid(1)], commits
-        commits = self.repo.commits('README', self._oid(1), skip=1)
-        assert commits == []
-        # path to dir
-        commits = self.repo.commits('a/b/c/')
-        assert commits == [self._oid(4), self._oid(2)]
-        commits = self.repo.commits('a/b/c/', skip=1)
-        assert commits == [self._oid(2)]
-        commits = self.repo.commits('a/b/c/', limit=1)
-        assert commits == [self._oid(4)]
-        commits = self.repo.commits('not/exist/')
-        assert commits == []
-
-    def test_commits_count(self):
-        commits = self.repo.commits_count()
-        assert commits == 5, commits
-        commits = self.repo.commits_count('a/b/c/')
-        assert commits == 2, commits
-        commits = self.repo.commits_count(None, self._oid(3))
-        assert commits == 3, commits
-        commits = self.repo.commits_count('README', self._oid(1))
-        assert commits == 1, commits
-        commits = self.repo.commits_count('not/exist/')
-        assert commits == 0, commits
+        commits = list(self.repo.log(self.repo.head, id_only=True))
+        assert_equal(commits, [5, 4, 3, 2, 1])
+        commits = list(self.repo.log(self.repo.head, 'README', id_only=True))
+        assert_equal(commits, [3, 1])
+        commits = list(self.repo.log(1, 'README', id_only=True))
+        assert_equal(commits, [1])
+        commits = list(self.repo.log(self.repo.head, 'a/b/c/', id_only=True))
+        assert_equal(commits, [4, 2])
+        commits = list(self.repo.log(3, 'a/b/c/', id_only=True))
+        assert_equal(commits, [2])
+        assert_equal(list(self.repo.log(self.repo.head, 'does/not/exist', id_only=True)),
[])
 
     def test_notification_email(self):
         setup_global_objects()
@@ -613,8 +586,7 @@ class TestSVNRev(unittest.TestCase):
             status = 'creating')
         self.repo.refresh()
         ThreadLocalORMSession.flush_all()
-        commits = self.repo.commits()
-        send_notifications(self.repo, [commits[4], ])
+        send_notifications(self.repo, [self.repo.rev_to_commit_id(1)])
         ThreadLocalORMSession.flush_all()
         n = M.Notification.query.find(
             dict(subject='[test:src] [r1] - rick446: Create readme')).first()


Mime
View raw message