Patchwork [3,of,4] log: move --graph and topo sort options to walkopts

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 27, 2020, 10:03 a.m.
Message ID <24792763fc1cb5be40f4.1601201026@mimosa>
Download mbox | patch
Permalink /patch/47297/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 27, 2020, 10:03 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599918178 -32400
#      Sat Sep 12 22:42:58 2020 +0900
# Node ID 24792763fc1cb5be40f40aa50d3f69b4b98b701e
# Parent  2a04837d026753ed9b0852ae675d268289b7648e
log: move --graph and topo sort options to walkopts

This is the last opts.get() found in getrevs(). It might be better to define
an enum, but for now, it is just a string.

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -710,6 +710,9 @@  class walkopts(object):
     # include revisions where files were removed
     force_changelog_traversal = attr.ib(default=False)  # type: bool
 
+    # sort revisions prior to traversal: 'desc', 'topo', or None
+    sort_revisions = attr.ib(default=None)  # type: Optional[bytes]
+
     # limit number of changes displayed; None means unlimited
     limit = attr.ib(default=None)  # type: Optional[int]
 
@@ -727,6 +730,14 @@  def parseopts(ui, pats, opts):
     else:
         follow = 0
 
+    if opts.get(b'graph'):
+        if ui.configbool(b'experimental', b'log.topo'):
+            sort_revisions = b'topo'
+        else:
+            sort_revisions = b'desc'
+    else:
+        sort_revisions = None
+
     return walkopts(
         pats=pats,
         opts=opts,
@@ -744,6 +755,7 @@  def parseopts(ui, pats, opts):
         exclude_pats=opts.get(b'exclude', []),
         follow=follow,
         force_changelog_traversal=bool(opts.get(b'removed')),
+        sort_revisions=sort_revisions,
         limit=getlimit(opts),
     )
 
@@ -975,8 +987,9 @@  def getrevs(repo, wopts):
             return match
 
     expr = _makerevset(repo, wopts, slowpath)
-    if wopts.opts.get(b'graph'):
-        if repo.ui.configbool(b'experimental', b'log.topo'):
+    if wopts.sort_revisions:
+        assert wopts.sort_revisions in {b'topo', b'desc'}
+        if wopts.sort_revisions == b'topo':
             if not revs.istopo():
                 revs = dagop.toposort(revs, repo.changelog.parentrevs)
                 # TODO: try to iterate the set lazily