Patchwork [1,of,9] log: duplicate _logrevs() dedicated for walkchangerevs()

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 15, 2018, 1:26 p.m.
Message ID <94d41163dd4c8690e8e7.1516022795@mimosa>
Download mbox | patch
Permalink /patch/26762/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 15, 2018, 1:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1512892794 -32400
#      Sun Dec 10 16:59:54 2017 +0900
# Node ID 94d41163dd4c8690e8e784567c73665a620a09b7
# Parent  a177c6aa055a86799e9dd9cecc3bbb3531759bcc
log: duplicate _logrevs() dedicated for walkchangerevs()

Prepares for refactoring getlogrevs() to fix the "log -frREV PATH" issue.

I initially thought I could get rid of walkchangerevs(), but it turned out
requiring non-trivial work because of a "prepare" callback and a scanning
window. This patch makes sure that walkchangerevs() will be unaffected by
subsequent changes.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2032,6 +2032,21 @@  def increasingwindows(windowsize=8, size
         if windowsize < sizelimit:
             windowsize *= 2
 
+def _walkrevs(repo, opts):
+    # Default --rev value depends on --follow but --follow behavior
+    # depends on revisions resolved from --rev...
+    follow = opts.get('follow') or opts.get('follow_first')
+    if opts.get('rev'):
+        revs = scmutil.revrange(repo, opts['rev'])
+    elif follow and repo.dirstate.p1() == nullid:
+        revs = smartset.baseset()
+    elif follow:
+        revs = repo.revs('reverse(:.)')
+    else:
+        revs = smartset.spanset(repo)
+        revs.reverse()
+    return revs
+
 class FileWalkError(Exception):
     pass
 
@@ -2186,7 +2201,7 @@  def walkchangerevs(repo, match, opts, pr
     function on each context in the window in forward order.'''
 
     follow = opts.get('follow') or opts.get('follow_first')
-    revs = _logrevs(repo, opts)
+    revs = _walkrevs(repo, opts)
     if not revs:
         return []
     wanted = set()