Patchwork [1,of,4] log: map --removed to walkopts.force_changelog_traversal

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

Comments

Yuya Nishihara - Sept. 27, 2020, 10:03 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599915298 -32400
#      Sat Sep 12 21:54:58 2020 +0900
# Node ID a09c59cea54f63db9a1ef69971271843d7f6ecbb
# Parent  f9a3edf2dee4f11117699967c226b882a98957e0
log: map --removed to walkopts.force_changelog_traversal

This is the flag to forcibly enable the slowpath. I'm not sure if the
slowpath parameter should be merged with this flag, so let's keep it as
an immutable flag for now.

I'll add another flag to support "grep --all-files". These two will be the
flags which aren't directly mapped from the command-line options.
Pulkit Goyal - Oct. 2, 2020, 1:32 p.m.
On Sun, Sep 27, 2020 at 3:36 PM Yuya Nishihara <yuya@tcha.org> wrote:
>
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1599915298 -32400
> #      Sat Sep 12 21:54:58 2020 +0900
> # Node ID a09c59cea54f63db9a1ef69971271843d7f6ecbb
> # Parent  f9a3edf2dee4f11117699967c226b882a98957e0
> log: map --removed to walkopts.force_changelog_traversal
>
> This is the flag to forcibly enable the slowpath. I'm not sure if the
> slowpath parameter should be merged with this flag, so let's keep it as
> an immutable flag for now.
>
> I'll add another flag to support "grep --all-files". These two will be the
> flags which aren't directly mapped from the command-line options.

Queued the series, many thanks!

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -693,6 +693,10 @@  class walkopts(object):
     # 0: no follow, 1: follow first, 2: follow both parents
     follow = attr.ib(default=0)  # type: int
 
+    # do not attempt filelog-based traversal, which may be fast but cannot
+    # include revisions where files were removed
+    force_changelog_traversal = attr.ib(default=False)  # type: bool
+
     # limit number of changes displayed; None means unlimited
     limit = attr.ib(default=None)  # type: Optional[int]
 
@@ -715,6 +719,7 @@  def parseopts(ui, pats, opts):
         opts=opts,
         revspec=opts.get(b'rev', []),
         follow=follow,
+        force_changelog_traversal=bool(opts.get(b'removed')),
         limit=getlimit(opts),
     )
 
@@ -736,7 +741,7 @@  def _makematcher(repo, revs, wopts):
     wctx = repo[None]
     match, pats = scmutil.matchandpats(wctx, wopts.pats, wopts.opts)
     slowpath = match.anypats() or (
-        not match.always() and wopts.opts.get(b'removed')
+        not match.always() and wopts.force_changelog_traversal
     )
     if not slowpath:
         if wopts.follow and wopts.revspec:
@@ -923,6 +928,7 @@  def getrevs(repo, wopts):
     revs = _initialrevs(repo, wopts)
     if not revs:
         return smartset.baseset(), None
+    # TODO: might want to merge slowpath with wopts.force_changelog_traversal
     match, pats, slowpath = _makematcher(repo, revs, wopts)
     wopts = attr.evolve(wopts, pats=pats)
 
@@ -931,6 +937,7 @@  def getrevs(repo, wopts):
         if slowpath or match.always():
             revs = dagop.revancestors(repo, revs, followfirst=wopts.follow == 1)
         else:
+            assert not wopts.force_changelog_traversal
             revs, filematcher = _fileancestors(
                 repo, revs, match, followfirst=wopts.follow == 1
             )