log: move --graph and topo sort options to walkopts
authorYuya Nishihara <yuya@tcha.org>
Sat, 12 Sep 2020 22:42:58 +0900
changeset 45630 224c786f4fce
parent 45629 8fe09005ed88
child 45631 7f033a587414
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.
mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py	Sat Sep 12 22:03:53 2020 +0900
+++ b/mercurial/logcmdutil.py	Sat Sep 12 22:42:58 2020 +0900
@@ -710,6 +710,9 @@
     # 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 @@
     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 @@
         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 @@
             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