[PATCH 1 of 3] revset: allow repo.revs('%d', wdirrev)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1 of 3] revset: allow repo.revs('%d', wdirrev)

Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara <[hidden email]>
# Date 1584764867 -32400
#      Sat Mar 21 13:27:47 2020 +0900
# Node ID d0aa302e184789f1af3048814d23d0a4cedcca15
# Parent  c1c2f6e0cd9f819389c18245d791c906023d9545
revset: allow repo.revs('%d', wdirrev)

Otherwise we can't write repo.revs('null:%d', subset.max()) to build
a smartset covering the range {null .. tip} + {wdir} if subset includes
wdir.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2108,7 +2108,8 @@ def _rev(repo, subset, x):
     except (TypeError, ValueError):
         # i18n: "rev" is a keyword
         raise error.ParseError(_(b"rev expects a number"))
-    repo.changelog.node(l)  # check that the rev exists
+    if l not in _virtualrevs:
+        repo.changelog.node(l)  # check that the rev exists
     return subset & baseset([l])
 
 
diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t
--- a/tests/test-template-functions.t
+++ b/tests/test-template-functions.t
@@ -1263,6 +1263,13 @@ default. join() should agree with the de
   5:13207e5a10d9fd28ec424934298e176197f2c67f,
   4:bbe44766e73d5f11ed2177f1838de10c53ef3e74
 
+%d parameter handling:
+
+  $ hg log -T '{revset("%d", rev)}\n' -r'wdir()'
+  2147483647
+  $ hg log -T '{revset("%d", rev)}\n' -r'null'
+  -1
+
 Invalid arguments passed to revset()
 
   $ hg log -T '{revset("%whatever", 0)}\n'
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 2 of 3] revset: fix crash by repo.revs('%d', tip + 1)

Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara <[hidden email]>
# Date 1584765579 -32400
#      Sat Mar 21 13:39:39 2020 +0900
# Node ID 1c189a6e5aa76bf71d5078597fd01c1f959244a2
# Parent  d0aa302e184789f1af3048814d23d0a4cedcca15
revset: fix crash by repo.revs('%d', tip + 1)

IndexError shouldn't be raised from a revset predicate. The error message
is copied from scmutil.revsymbol().

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2109,7 +2109,10 @@ def _rev(repo, subset, x):
         # i18n: "rev" is a keyword
         raise error.ParseError(_(b"rev expects a number"))
     if l not in _virtualrevs:
-        repo.changelog.node(l)  # check that the rev exists
+        try:
+            repo.changelog.node(l)  # check that the rev exists
+        except IndexError:
+            raise error.RepoLookupError(_(b"unknown revision '%d'") % l)
     return subset & baseset([l])
 
 
diff --git a/tests/test-template-functions.t b/tests/test-template-functions.t
--- a/tests/test-template-functions.t
+++ b/tests/test-template-functions.t
@@ -1269,6 +1269,12 @@ default. join() should agree with the de
   2147483647
   $ hg log -T '{revset("%d", rev)}\n' -r'null'
   -1
+  $ hg log -T '{revset("%d", rev + 1)}\n' -r'tip'
+  abort: unknown revision '3'!
+  [255]
+  $ hg log -T '{revset("%d", rev - 1)}\n' -r'null'
+  abort: unknown revision '-2'!
+  [255]
 
 Invalid arguments passed to revset()
 
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

[PATCH 3 of 3] revset: leverage internal _rev() function to implement rev()

Yuya Nishihara
In reply to this post by Yuya Nishihara
# HG changeset patch
# User Yuya Nishihara <[hidden email]>
# Date 1584765728 -32400
#      Sat Mar 21 13:42:08 2020 +0900
# Node ID 98b60b759e2623db637a2ff68eadd5b7e6a8dc12
# Parent  1c189a6e5aa76bf71d5078597fd01c1f959244a2
revset: leverage internal _rev() function to implement rev()

Now 'rev(n)' is identical to 'present(_rev(n))'.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2082,19 +2082,11 @@ def removes(repo, subset, x):
 
 @predicate(b'rev(number)', safe=True)
 def rev(repo, subset, x):
-    """Revision with the given numeric identifier.
-    """
-    # i18n: "rev" is a keyword
-    l = getargs(x, 1, 1, _(b"rev requires one argument"))
+    """Revision with the given numeric identifier."""
     try:
-        # i18n: "rev" is a keyword
-        l = int(getstring(l[0], _(b"rev requires a number")))
-    except (TypeError, ValueError):
-        # i18n: "rev" is a keyword
-        raise error.ParseError(_(b"rev expects a number"))
-    if l not in repo.changelog and l not in _virtualrevs:
+        return _rev(repo, subset, x)
+    except error.RepoLookupError:
         return baseset()
-    return subset & baseset([l])
 
 
 @predicate(b'_rev(number)', safe=True)
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3 of 3] revset: leverage internal _rev() function to implement rev()

Pierre-Yves David-2
That series looks good to me.

On 3/21/20 6:26 AM, Yuya Nishihara wrote:

> # HG changeset patch
> # User Yuya Nishihara <[hidden email]>
> # Date 1584765728 -32400
> #      Sat Mar 21 13:42:08 2020 +0900
> # Node ID 98b60b759e2623db637a2ff68eadd5b7e6a8dc12
> # Parent  1c189a6e5aa76bf71d5078597fd01c1f959244a2
> revset: leverage internal _rev() function to implement rev()
>
> Now 'rev(n)' is identical to 'present(_rev(n))'.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2082,19 +2082,11 @@ def removes(repo, subset, x):
>  
>   @predicate(b'rev(number)', safe=True)
>   def rev(repo, subset, x):
> -    """Revision with the given numeric identifier.
> -    """
> -    # i18n: "rev" is a keyword
> -    l = getargs(x, 1, 1, _(b"rev requires one argument"))
> +    """Revision with the given numeric identifier."""
>       try:
> -        # i18n: "rev" is a keyword
> -        l = int(getstring(l[0], _(b"rev requires a number")))
> -    except (TypeError, ValueError):
> -        # i18n: "rev" is a keyword
> -        raise error.ParseError(_(b"rev expects a number"))
> -    if l not in repo.changelog and l not in _virtualrevs:
> +        return _rev(repo, subset, x)
> +    except error.RepoLookupError:
>           return baseset()
> -    return subset & baseset([l])
>  
>  
>   @predicate(b'_rev(number)', safe=True)
> _______________________________________________
> Mercurial-devel mailing list
> [hidden email]
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

--
Pierre-Yves David
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 3 of 3] revset: leverage internal _rev() function to implement rev()

Augie Fackler-2
queued per marmoute review, thanks

> On Mar 21, 2020, at 06:51, Pierre-Yves David <[hidden email]> wrote:
>
> That series looks good to me.
>
> On 3/21/20 6:26 AM, Yuya Nishihara wrote:
>> # HG changeset patch
>> # User Yuya Nishihara <[hidden email]>
>> # Date 1584765728 -32400
>> #      Sat Mar 21 13:42:08 2020 +0900
>> # Node ID 98b60b759e2623db637a2ff68eadd5b7e6a8dc12
>> # Parent  1c189a6e5aa76bf71d5078597fd01c1f959244a2
>> revset: leverage internal _rev() function to implement rev()
>> Now 'rev(n)' is identical to 'present(_rev(n))'.
>> diff --git a/mercurial/revset.py b/mercurial/revset.py
>> --- a/mercurial/revset.py
>> +++ b/mercurial/revset.py
>> @@ -2082,19 +2082,11 @@ def removes(repo, subset, x):
>>    @predicate(b'rev(number)', safe=True)
>>  def rev(repo, subset, x):
>> -    """Revision with the given numeric identifier.
>> -    """
>> -    # i18n: "rev" is a keyword
>> -    l = getargs(x, 1, 1, _(b"rev requires one argument"))
>> +    """Revision with the given numeric identifier."""
>>      try:
>> -        # i18n: "rev" is a keyword
>> -        l = int(getstring(l[0], _(b"rev requires a number")))
>> -    except (TypeError, ValueError):
>> -        # i18n: "rev" is a keyword
>> -        raise error.ParseError(_(b"rev expects a number"))
>> -    if l not in repo.changelog and l not in _virtualrevs:
>> +        return _rev(repo, subset, x)
>> +    except error.RepoLookupError:
>>          return baseset()
>> -    return subset & baseset([l])
>>      @predicate(b'_rev(number)', safe=True)
>> _______________________________________________
>> Mercurial-devel mailing list
>> [hidden email]
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
> --
> Pierre-Yves David
> _______________________________________________
> Mercurial-devel mailing list
> [hidden email]
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel