incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [10/34] git commit: [#5037] ticket:202 svn implementation
Date Wed, 05 Dec 2012 17:27:48 GMT
[#5037] ticket:202 svn implementation


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

Branch: refs/heads/cj/4691
Commit: 4893d756c716b90b2c217dffeebf0c9f5a755621
Parents: b030b67
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Nov 7 12:36:30 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Dec 3 23:56:28 2012 +0000

----------------------------------------------------------------------
 ForgeSVN/forgesvn/model/svn.py                   |   44 +++++++++++++---
 ForgeSVN/forgesvn/tests/model/test_repository.py |   47 +++++++++++++++--
 2 files changed, 80 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4893d756/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index b8550d5..4b9c724 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -468,14 +468,44 @@ class SVNImplementation(M.RepositoryImplementation):
     def _oid(self, revno):
         return '%s:%s' % (self._repo._id, revno)
 
-    def  get_commits_by_path(self, path):
-        result = []
+    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:
+            log.info('ClientError processing commits for path %s, rev %s, skip=%s, limit=%s,
treating as empty',
+                    path, rev, skip, limit, exc_info=True)
+            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:
-            for l in self._svn.log(url_or_path=self._url + "/" + path):
-                result.append(self._oid('') + str(l.revision.number))
-            return result
-        except:
-            return result
+            return len(self._svn.log(path, **opts))
+        except pysvn.ClientError:
+            log.info('ClientError processing commits for path %s, rev %s, treating as empty',
path, rev, exc_info=True)
+            return 0
 
 
 Mapper.compile_all()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4893d756/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 fb65a70..2515210 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -287,10 +287,49 @@ class TestSVNRev(unittest.TestCase):
         for d in diffs:
             print d
 
-    def test_get_commits_by_path(self):
-        assert  len(self.repo.get_commits_by_path('')) == 5
-        assert  len(self.repo.get_commits_by_path('README')) == 2
-        assert  len(self.repo.get_commits_by_path('test')) == 0
+    def _oid(self, rev_id):
+        return '%s:%s' % (self.repo._id, rev_id)
+
+    def test_commits(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
 
 
 class _Test(unittest.TestCase):


Mime
View raw message