Patchwork [4,of,5] cmdutil: make walkchangerevs() gracefully handle wdir parents

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 17, 2020, 12:42 p.m.
Message ID <88b989703070b5054041.1600346548@mimosa>
Download mbox | patch
Permalink /patch/47188/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 17, 2020, 12:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1599816821 -32400
#      Fri Sep 11 18:33:41 2020 +0900
# Node ID 88b989703070b50540415e9a4614612a0af2183a
# Parent  9a45d79801466d8cb592df7acdc17fc633069077
cmdutil: make walkchangerevs() gracefully handle wdir parents

This code will be completely rewritten, but test-grep.t would fail without
fixing it.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2386,12 +2386,20 @@  class _followfilter(object):
 
     def match(self, rev):
         def realparents(rev):
-            if self.onlyfirst:
-                return self.repo.changelog.parentrevs(rev)[0:1]
-            else:
-                return filter(
-                    lambda x: x != nullrev, self.repo.changelog.parentrevs(rev)
-                )
+            try:
+                if self.onlyfirst:
+                    return self.repo.changelog.parentrevs(rev)[0:1]
+                else:
+                    return filter(
+                        lambda x: x != nullrev,
+                        self.repo.changelog.parentrevs(rev),
+                    )
+            except error.WdirUnsupported:
+                prevs = [p.rev() for p in self.repo[rev].parents()]
+                if self.onlyfirst:
+                    return prevs[:1]
+                else:
+                    return prevs
 
         if self.startrev == nullrev:
             self.startrev = rev