allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [6/10] git commit: [#5037] ticket:202 mercurial implementation
Date Mon, 03 Dec 2012 23:57:05 GMT
[#5037] ticket:202 mercurial 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/712ef42a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/712ef42a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/712ef42a

Branch: refs/heads/master
Commit: 712ef42abad4aa974896219f4ce1f2659893ee1a
Parents: 0151c0e
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Nov 6 15:25:31 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Dec 3 23:56:23 2012 +0000

----------------------------------------------------------------------
 ForgeHg/forgehg/model/hg.py                    |  110 +++++-------------
 ForgeHg/forgehg/tests/model/test_repository.py |   35 +++++-
 2 files changed, 62 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/712ef42a/ForgeHg/forgehg/model/hg.py
----------------------------------------------------------------------
diff --git a/ForgeHg/forgehg/model/hg.py b/ForgeHg/forgehg/model/hg.py
index 2a32206..5fffdbc 100644
--- a/ForgeHg/forgehg/model/hg.py
+++ b/ForgeHg/forgehg/model/hg.py
@@ -10,8 +10,7 @@ from ConfigParser import ConfigParser
 import tg
 from pylons import app_globals as g
 os.environ['HGRCPATH'] = '' # disable loading .hgrc
-from mercurial import ui, hg, cmdutil, error
-from mercurial.node import nullrev
+from mercurial import ui, hg, cmdutil
 
 from pymongo.errors import DuplicateKeyError
 
@@ -231,76 +230,6 @@ class HgImplementation(M.RepositoryImplementation):
         doc.m.save(safe=False)
         return doc
 
-    def get_commits(self, ui, repo, *pats, **opts):
-        matchfn = cmdutil.match(repo, pats, opts, default='relpath')
-        if opts.get('copies') and opts.get('rev'):
-            endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
-        else:
-            endrev = len(repo)
-        rcache = {}
-        ncache = {}
-
-        def getrenamed(fn, rev):
-            if fn not in rcache:
-                rcache[fn] = {}
-                ncache[fn] = {}
-                fl = repo.file(fn)
-                for i in fl:
-                    node = fl.node(i)
-                    lr = fl.linkrev(i)
-                    renamed = fl.renamed(node)
-                    rcache[fn][lr] = renamed
-                    if renamed:
-                        ncache[fn][node] = renamed
-                    if lr >= endrev:
-                        break
-            if rev in rcache[fn]:
-                return rcache[fn][rev]
-
-            try:
-                return repo[rev][fn].renamed()
-            except error.LookupError:
-                pass
-            return None
-
-        df = False
-
-        def prep(ctx, fns):
-            rev = ctx.rev()
-            parents = [
-                p for p in repo.changelog.parentrevs(rev) if p != nullrev
-            ]
-            if opts.get('no_merges') and len(parents) == 2:
-                return
-            if opts.get('only_merges') and len(parents) != 2:
-                return
-            if opts.get('only_branch') and ctx.branch() not in opts['only_branch']:
-                return
-            if df and not df(ctx.date()[0]):
-                return
-            if opts['user'] and not [k for k in opts['user'] if k in ctx.user()]:
-                return
-            if opts.get('keyword'):
-                for k in [kw.lower() for kw in opts['keyword']]:
-                    if (k in ctx.user().lower() or
-                        k in ctx.description().lower() or
-                        k in " ".join(ctx.files()).lower()):
-                        break
-                else:
-                    return
-
-            copies = []
-            if opts.get('copies') and rev:
-                for fn in ctx.files():
-                    rename = getrenamed(fn, rev)
-                    if rename:
-                        copies.append((fn, rename[0]))
-
-        revs = []
-        for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
-            revs.append(ctx.hex())
-        return revs
-
     def log(self, object_id, skip, count):
         obj = self._hg[object_id]
         candidates = [ obj ]
@@ -363,12 +292,35 @@ class HgImplementation(M.RepositoryImplementation):
         tree = self.refresh_tree_info(fake_tree, set())
         return tree._id
 
-    def get_commits_by_path(self, path):
-        return self.get_commits(
-            ui.ui(),
-            self._hg,
-            self._repo.fs_path + '/' + self._repo.name + '/'+path,
-            rev=None,
-            user=None)
+    def commits(self, path=None, rev=None, skip=None, limit=None):
+        if skip is None: skip = 0
+        if path is not None:
+            path = os.path.join(self._repo.full_fs_path, path)
+            m = cmdutil.match(self._hg, [path])
+        else:
+            m = cmdutil.match(self._hg)
+        revs = []
+        opts = {'rev': ['%s:0' % rev] if rev is not None else rev}
+        for ctx in cmdutil.walkchangerevs(self._hg, m, opts, lambda *a: None):
+            if limit and limit == len(revs):
+                return revs
+            if skip == 0:
+                revs.append(ctx.hex())
+            else:
+                skip -= 1
+        return revs
+
+    def commits_count(self, path=None, rev=None):
+        if path is not None:
+            path = os.path.join(self._repo.full_fs_path, path)
+            m = cmdutil.match(self._hg, [path])
+        else:
+            m = cmdutil.match(self._hg)
+        opts = {'rev': ['%s:0' % rev] if rev is not None else rev}
+        count = 0
+        for ctx in cmdutil.walkchangerevs(self._hg, m, opts, lambda *a: None):
+            count += 1
+        return count
+        return len(self._hg)
 
 Mapper.compile_all()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/712ef42a/ForgeHg/forgehg/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeHg/forgehg/tests/model/test_repository.py b/ForgeHg/forgehg/tests/model/test_repository.py
index 6656d89..da93f20 100644
--- a/ForgeHg/forgehg/tests/model/test_repository.py
+++ b/ForgeHg/forgehg/tests/model/test_repository.py
@@ -248,7 +248,34 @@ class TestHgCommit(unittest.TestCase):
         for d in diffs:
             print d
 
-    def test_get_commits_by_path(self):
-        assert len(self.repo.get_commits_by_path('')) == 6
-        assert len(self.repo.get_commits_by_path('README')) == 2
-        assert len(self.repo.get_commits_by_path('test')) == 0
+    def test_commits(self):
+        # path only
+        commits = self.repo.commits()
+        assert len(commits) == 6, 'Returned %s commits' % len(commits)
+        assert "5a0a993efa9bce7d1983344261393e841fcfd65d" in commits, commits
+        assert "773d2f8e3a94d0d5872988b16533d67e1a7f5462" in commits, commits
+        commits = self.repo.commits('README')
+        assert len(commits) == 2, 'Returned %s commits related to README' % len(commits)
+        assert "e5a0b44437be783c41084e7bf0740f9b58b96ecf" in commits, commits
+        assert "773d2f8e3a94d0d5872988b16533d67e1a7f5462" in commits, commits
+        assert self.repo.commits('does/not/exist') == []
+        # with path and start rev
+        commits = self.repo.commits('README', '773d2f8e3a94d0d5872988b16533d67e1a7f5462')
+        assert commits == ['773d2f8e3a94d0d5872988b16533d67e1a7f5462'], commits
+        # skip and limit
+        commits = self.repo.commits(None, rev=None, skip=1, limit=2)
+        assert commits == ['4a7f7ec0dcf5f005eb5d177b3d8c00bfc8159843', '1c7eb55bbd66ff45906b4a25d4b403899e0ffff1']
+        commits = self.repo.commits(None, 'e5a0b44437be783c41084e7bf0740f9b58b96ecf', skip=1)
+        assert commits == ['773d2f8e3a94d0d5872988b16533d67e1a7f5462'], commits
+        commits = self.repo.commits('README', '773d2f8e3a94d0d5872988b16533d67e1a7f5462',
skip=1)
+        assert commits == []
+
+    def test_commits_count(self):
+        commits = self.repo.commits_count()
+        assert commits == 6, commits
+        commits = self.repo.commits_count('a/b/c/hello.txt')
+        assert commits == 1, commits
+        commits = self.repo.commits_count(None, '23d1d8b68c8d6f3326bd42bcc30c40fffe77372c')
+        assert commits == 3, commits
+        commits = self.repo.commits_count('README', '773d2f8e3a94d0d5872988b16533d67e1a7f5462')
+        assert commits == 1, commits


Mime
View raw message