Patchwork [2,of,3,V2] revlog: raise WdirUnsupported when wdirrev is passed

login
register
mail settings
Submitter Pulkit Goyal
Date May 21, 2017, 4:18 p.m.
Message ID <497d73787ea6e0b0ec8a.1495383524@workspace>
Download mbox | patch
Permalink /patch/20797/
State Accepted
Headers show

Comments

Pulkit Goyal - May 21, 2017, 4:18 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1495201326 -19800
#      Fri May 19 19:12:06 2017 +0530
# Node ID 497d73787ea6e0b0ec8aa2262812c82086dc8e8b
# Parent  2adbd2d46cd7588d75201108f6e02b92d1480022
revlog: raise WdirUnsupported when wdirrev is passed

revlog.parentrevs() is called while evaluating ^ operator in revsets. When wdir
is passed, it raises IndexError. This patch raises WdirUnsupported if wdir is
passed in the function. The error will be caugth in future patches.
Yuya Nishihara - May 22, 2017, 3:02 p.m.
On Sun, 21 May 2017 21:48:44 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1495201326 -19800
> #      Fri May 19 19:12:06 2017 +0530
> # Node ID 497d73787ea6e0b0ec8aa2262812c82086dc8e8b
> # Parent  2adbd2d46cd7588d75201108f6e02b92d1480022
> revlog: raise WdirUnsupported when wdirrev is passed
> 
> revlog.parentrevs() is called while evaluating ^ operator in revsets. When wdir
> is passed, it raises IndexError. This patch raises WdirUnsupported if wdir is
> passed in the function. The error will be caugth in future patches.
> 
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -26,6 +26,7 @@
>      hex,
>      nullid,
>      nullrev,
> +    wdirrev,
>  )
>  from .i18n import _
>  from . import (
> @@ -477,7 +478,12 @@
>          return self.index[rev][4]
>  
>      def parentrevs(self, rev):
> -        return self.index[rev][5:7]
> +        try:
> +            return self.index[rev][5:7]
> +        except IndexError:
> +            if rev == wdirrev:
> +                raise error.WdirUnsupported("wdir() is not supported")

The message isn't used and would need _() if we wanted to print it. So dropped
it for now. In future, WdirUnsupported will be caught at callcatch() and
translated to an error message. (I have some patches.)

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -26,6 +26,7 @@ 
     hex,
     nullid,
     nullrev,
+    wdirrev,
 )
 from .i18n import _
 from . import (
@@ -477,7 +478,12 @@ 
         return self.index[rev][4]
 
     def parentrevs(self, rev):
-        return self.index[rev][5:7]
+        try:
+            return self.index[rev][5:7]
+        except IndexError:
+            if rev == wdirrev:
+                raise error.WdirUnsupported("wdir() is not supported")
+            raise
 
     def node(self, rev):
         return self.index[rev][7]