log: factor out function to feed revisions to displayer
authorYuya Nishihara <yuya@tcha.org>
Sun, 21 Jan 2018 16:15:20 +0900
changeset 36198 7bc10d3f68b4
parent 36197 db26e6a0a677
child 36199 2d6e03a28c31
log: factor out function to feed revisions to displayer
mercurial/commands.py
mercurial/logcmdutil.py
--- a/mercurial/commands.py	Sun Jan 21 16:04:59 2018 +0900
+++ b/mercurial/commands.py	Sun Jan 21 16:15:20 2018 +0900
@@ -3434,22 +3434,10 @@
     displayer = logcmdutil.changesetdisplayer(ui, repo, opts, differ,
                                               buffered=True)
     if opts.get('graph'):
-        logcmdutil.graphlog(ui, repo, revs, displayer, getrenamed)
-        return
-
-    for rev in revs:
-        ctx = repo[rev]
-        copies = None
-        if getrenamed is not None and rev:
-            copies = []
-            for fn in ctx.files():
-                rename = getrenamed(fn, rev)
-                if rename:
-                    copies.append((fn, rename[0]))
-        displayer.show(ctx, copies=copies)
-        displayer.flush(ctx)
-
-    displayer.close()
+        displayfn = logcmdutil.displaygraphrevs
+    else:
+        displayfn = logcmdutil.displayrevs
+    displayfn(ui, repo, revs, displayer, getrenamed)
 
 @command('manifest',
     [('r', 'rev', '', _('revision to display'), _('REV')),
--- a/mercurial/logcmdutil.py	Sun Jan 21 16:04:59 2018 +0900
+++ b/mercurial/logcmdutil.py	Sun Jan 21 16:15:20 2018 +0900
@@ -899,10 +899,24 @@
             lines = []
     displayer.close()
 
-def graphlog(ui, repo, revs, displayer, getrenamed):
+def displaygraphrevs(ui, repo, revs, displayer, getrenamed):
     revdag = graphmod.dagwalker(repo, revs)
     displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed)
 
+def displayrevs(ui, repo, revs, displayer, getrenamed):
+    for rev in revs:
+        ctx = repo[rev]
+        copies = None
+        if getrenamed is not None and rev:
+            copies = []
+            for fn in ctx.files():
+                rename = getrenamed(fn, rev)
+                if rename:
+                    copies.append((fn, rename[0]))
+        displayer.show(ctx, copies=copies)
+        displayer.flush(ctx)
+    displayer.close()
+
 def checkunsupportedgraphflags(pats, opts):
     for op in ["newest_first"]:
         if op in opts and opts[op]: