Patchwork [V2] revset: fix a crash in parents() when 'wdir()' is in the set

login
register
mail settings
Submitter Matt Harbison
Date June 30, 2015, 2:26 p.m.
Message ID <b84b980cf15bdda20c47.1435674395@MATT7H-PC.attotech.com>
Download mbox | patch
Permalink /patch/9830/
State Accepted
Headers show

Comments

Matt Harbison - June 30, 2015, 2:26 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1435588496 14400
#      Mon Jun 29 10:34:56 2015 -0400
# Node ID b84b980cf15bdda20c474f8f5ff6b3e367164f7e
# Parent  ff5172c830022b64cc5bd1bae36b2276e9dc6e5d
revset: fix a crash in parents() when 'wdir()' is in the set

The crash was "TypeError: expected string or Unicode object, NoneType found"
down in revlog.parentrevs().  This fixes heads() too (which is where I found
it.)
Matt Mackall - June 30, 2015, 7:15 p.m.
On Tue, 2015-06-30 at 10:26 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1435588496 14400
> #      Mon Jun 29 10:34:56 2015 -0400
> # Node ID b84b980cf15bdda20c474f8f5ff6b3e367164f7e
> # Parent  ff5172c830022b64cc5bd1bae36b2276e9dc6e5d
> revset: fix a crash in parents() when 'wdir()' is in the set

This one's queued for default, thanks.

FYI, we've now got breakage in test-subrepo-deep-nested-change.t in this
area. The calculation of changessince in archive explodes due to trying
to use repo.revs("%d") on a workingctx. I've got a patch to add a %c
revset.formatspec that knows how to take a context object and turn it
into a rev or 'wdir()', but this isn't quite sufficient because ::wdir()
doesn't work and wdir()^ has the same bug as parents().
Matt Harbison - July 1, 2015, 2:34 a.m.
On Tue, 30 Jun 2015 15:15:35 -0400, Matt Mackall <mpm@selenic.com> wrote:

> On Tue, 2015-06-30 at 10:26 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1435588496 14400
>> #      Mon Jun 29 10:34:56 2015 -0400
>> # Node ID b84b980cf15bdda20c474f8f5ff6b3e367164f7e
>> # Parent  ff5172c830022b64cc5bd1bae36b2276e9dc6e5d
>> revset: fix a crash in parents() when 'wdir()' is in the set
>
> This one's queued for default, thanks.
>
> FYI, we've now got breakage in test-subrepo-deep-nested-change.t in this
> area. The calculation of changessince in archive explodes due to trying
> to use repo.revs("%d") on a workingctx. I've got a patch to add a %c
> revset.formatspec that knows how to take a context object and turn it
> into a rev or 'wdir()', but this isn't quite sufficient because ::wdir()
> doesn't work and wdir()^ has the same bug as parents().

My plan is to finish the keyword Yuya and I have been debating, and then  
switch the archive code to that is possible to avoid a copy/paste.

I've also got a series that fixes wdir()^, among other things.  I fixed a  
crash in ::wdir(), but need more investigation because wdir() doesn't show  
in the series.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1468,7 +1468,10 @@  def parents(repo, subset, x):
         ps = set()
         cl = repo.changelog
         for r in getset(repo, fullreposet(repo), x):
-            ps.update(cl.parentrevs(r))
+            if r is None:
+                ps.update(p.rev() for p in repo[r].parents())
+            else:
+                ps.update(cl.parentrevs(r))
     ps -= set([node.nullrev])
     return subset & ps
 
diff --git a/tests/test-add.t b/tests/test-add.t
--- a/tests/test-add.t
+++ b/tests/test-add.t
@@ -75,6 +75,13 @@  should fail
 
   $ hg ci -m 0 --traceback
 
+  $ hg log -r "heads(. or wdir() & file('**'))"
+  changeset:   0:* (glob)
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     0
+  
 should fail
 
   $ hg add a
@@ -99,6 +106,15 @@  should fail
   M a
   ? a.orig
 
+wdir doesn't cause a crash, and can be dynamically selected if dirty
+
+  $ hg log -r "heads(. or wdir() & file('**'))"
+  changeset:   2:*+ (glob)
+  parent:      2:* (glob)
+  parent:      1:* (glob)
+  user:        test
+  date:        * (glob)
+  
 should fail
 
   $ hg add a