[PATCH 3 of 4] log: move main code from commands to hg

Martin Geisler mg at aragost.com
Thu Sep 23 10:03:21 CDT 2010


# HG changeset patch
# User Martin Geisler <mg at aragost.com>
# Date 1285254056 -7200
# Node ID 2ec1394c1cd819d2ebac281814c7426d5c7e5ac2
# Parent  f25293364dda43c039550527f3130bd900c2c995
log: move main code from commands to hg

This is for better reuse in subrepositories.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -10,7 +10,7 @@
 from i18n import _, gettext
 import os, re, sys, difflib, time, tempfile
 import hg, util, revlog, extensions, copies, error
-import patch, help, mdiff, url, encoding, templatekw, discovery
+import patch, help, mdiff, url, encoding, discovery
 import archival, changegroup, cmdutil, sshserver, hbisect, hgweb, hgweb.server
 import merge as mergemod
 import minirst, revset
@@ -2456,69 +2456,7 @@
     """
 
     matchfn = cmdutil.match(repo, pats, opts)
-    limit = cmdutil.loglimit(opts)
-    count = 0
-
-    endrev = None
-    if opts.get('copies') and opts.get('rev'):
-        endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
-
-    df = False
-    if opts["date"]:
-        df = util.matchdate(opts["date"])
-
-    branches = opts.get('branch', []) + opts.get('only_branch', [])
-    opts['branch'] = [repo.lookupbranch(b) for b in branches]
-
-    displayer = cmdutil.show_changeset(ui, repo, opts, True)
-    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('branch') and ctx.branch() not in opts['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 = None
-        if opts.get('copies') and rev:
-            copies = []
-            getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
-            for fn in ctx.files():
-                rename = getrenamed(fn, rev)
-                if rename:
-                    copies.append((fn, rename[0]))
-
-        revmatchfn = None
-        if opts.get('patch') or opts.get('stat'):
-            if opts.get('follow') or opts.get('follow_first'):
-                # note: this might be wrong when following through merges
-                revmatchfn = cmdutil.match(repo, fns, default='path')
-            else:
-                revmatchfn = matchfn
-
-        displayer.show(ctx, copies=copies, matchfn=revmatchfn)
-
-    for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
-        if count == limit:
-            break
-        if displayer.flush(ctx.rev()):
-            count += 1
-    displayer.close()
+    hg.log(ui, repo, matchfn, opts)
 
 def manifest(ui, repo, node=None, rev=None):
     """output the current or given revision of the project manifest
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -11,7 +11,7 @@
 from node import hex, nullid, nullrev, short
 import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo
 import lock, util, extensions, error, encoding, node
-import cmdutil, discovery, url, changegroup
+import cmdutil, discovery, url, changegroup, templatekw
 import merge as mergemod
 import verify as verifymod
 import errno, os, shutil
@@ -114,6 +114,71 @@
         return path[5:]
     return path
 
+def log(ui, repo, matchfn, opts):
+    limit = cmdutil.loglimit(opts)
+    count = 0
+
+    endrev = None
+    if opts.get('copies') and opts.get('rev'):
+        endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
+
+    df = False
+    if opts["date"]:
+        df = util.matchdate(opts["date"])
+
+    branches = opts.get('branch', []) + opts.get('only_branch', [])
+    opts['branch'] = [repo.lookupbranch(b) for b in branches]
+
+    displayer = cmdutil.show_changeset(ui, repo, opts, True)
+    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('branch') and ctx.branch() not in opts['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 = None
+        if opts.get('copies') and rev:
+            copies = []
+            getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
+            for fn in ctx.files():
+                rename = getrenamed(fn, rev)
+                if rename:
+                    copies.append((fn, rename[0]))
+
+        revmatchfn = None
+        if opts.get('patch') or opts.get('stat'):
+            if opts.get('follow') or opts.get('follow_first'):
+                # note: this might be wrong when following through merges
+                revmatchfn = cmdutil.match(repo, fns, default='path')
+            else:
+                revmatchfn = matchfn
+
+        displayer.show(ctx, copies=copies, matchfn=revmatchfn)
+
+    for ctx in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
+        if count == limit:
+            break
+        if displayer.flush(ctx.rev()):
+            count += 1
+    displayer.close()
+
 def share(ui, source, dest=None, update=True):
     '''create a shared repository'''
 


More information about the Mercurial-devel mailing list