Patchwork [4,of,4] log: do not accept string-matcher pattern as -u/-b/-B parameter

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 1, 2020, 12:50 p.m.
Message ID <8e8feec5114933aaa522.1606827034@lemosa>
Download mbox | patch
Permalink /patch/47757/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 1, 2020, 12:50 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1606821744 -32400
#      Tue Dec 01 20:22:24 2020 +0900
# Node ID 8e8feec5114933aaa5224ff33acfa1bc9a52625c
# Parent  773cf7f8899449979131792e82a49fc6bc0d25ec
log: do not accept string-matcher pattern as -u/-b/-B parameter

I'm pretty sure this is a bug introduced after we've switched the filtering
backend to revset matcher.
Augie Fackler - Dec. 4, 2020, 10:27 p.m.
queued thanks

> On Dec 1, 2020, at 07:50, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1606821744 -32400
> #      Tue Dec 01 20:22:24 2020 +0900
> # Node ID 8e8feec5114933aaa5224ff33acfa1bc9a52625c
> # Parent  773cf7f8899449979131792e82a49fc6bc0d25ec
> log: do not accept string-matcher pattern as -u/-b/-B parameter
> 
> I'm pretty sure this is a bug introduced after we've switched the filtering
> backend to revset matcher.
> 
> diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
> --- a/mercurial/logcmdutil.py
> +++ b/mercurial/logcmdutil.py
> @@ -898,13 +898,13 @@ def _makenofollowfilematcher(repo, pats,
> def _makerevset(repo, wopts, slowpath):
>     """Return a revset string built from log options and file patterns"""
>     opts = {
> -        b'branch': [repo.lookupbranch(b) for b in wopts.branches],
> +        b'branch': [b'literal:' + repo.lookupbranch(b) for b in wopts.branches],
>         b'date': wopts.date,
>         b'keyword': wopts.keywords,
>         b'no_merges': wopts.no_merges,
>         b'only_merges': wopts.only_merges,
>         b'prune': wopts.prune_ancestors,
> -        b'user': wopts.users,
> +        b'user': [b'literal:' + v for v in wopts.users],
>     }
> 
>     if wopts.filter_revisions_by_pats and slowpath:
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -2310,6 +2310,7 @@ def bookmarkrevs(repo, mark):
> def format_bookmark_revspec(mark):
>     """Build a revset expression to select revisions reachable by a given
>     bookmark"""
> +    mark = b'literal:' + mark
>     return revsetlang.formatspec(
>         b"ancestors(bookmark(%s)) - "
>         b"ancestors(head() and not bookmark(%s)) - "
> diff --git a/tests/test-glog-beautifygraph.t b/tests/test-glog-beautifygraph.t
> --- a/tests/test-glog-beautifygraph.t
> +++ b/tests/test-glog-beautifygraph.t
> @@ -1588,19 +1588,19 @@ glog always reorders nodes which explain
>     (list
>       (func
>         (symbol 'user')
> -        (string 'test'))
> +        (string 'literal:test'))
>       (func
>         (symbol 'user')
> -        (string 'not-a-user'))))
> +        (string 'literal:not-a-user'))))
>   <filteredset
>     <spanset- 0:37>,
>     <addset
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <user 'test'>>,
> +        <user 'literal:test'>>,
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <user 'not-a-user'>>>>
> +        <user 'literal:not-a-user'>>>>
>   $ testlog -b not-a-branch
>   abort: unknown revision 'not-a-branch'
>   abort: unknown revision 'not-a-branch'
> @@ -1611,28 +1611,28 @@ glog always reorders nodes which explain
>     (list
>       (func
>         (symbol 'branch')
> -        (string 'default'))
> +        (string 'literal:default'))
>       (or
>         (list
>           (func
>             (symbol 'branch')
> -            (string 'branch'))
> +            (string 'literal:branch'))
>           (func
>             (symbol 'branch')
> -            (string 'branch'))))))
> +            (string 'literal:branch'))))))
>   <filteredset
>     <spanset- 0:37>,
>     <addset
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <branch 'default'>>,
> +        <branch 'literal:default'>>,
>       <addset
>         <filteredset
>           <fullreposet+ 0:37>,
> -          <branch 'branch'>>,
> +          <branch 'literal:branch'>>,
>         <filteredset
>           <fullreposet+ 0:37>,
> -          <branch 'branch'>>>>>
> +          <branch 'literal:branch'>>>>>
>   $ testlog -k expand -k merge
>   []
>   (or
> diff --git a/tests/test-glog.t b/tests/test-glog.t
> --- a/tests/test-glog.t
> +++ b/tests/test-glog.t
> @@ -1438,19 +1438,19 @@ glog always reorders nodes which explain
>     (list
>       (func
>         (symbol 'user')
> -        (string 'test'))
> +        (string 'literal:test'))
>       (func
>         (symbol 'user')
> -        (string 'not-a-user'))))
> +        (string 'literal:not-a-user'))))
>   <filteredset
>     <spanset- 0:37>,
>     <addset
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <user 'test'>>,
> +        <user 'literal:test'>>,
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <user 'not-a-user'>>>>
> +        <user 'literal:not-a-user'>>>>
>   $ testlog -b not-a-branch
>   abort: unknown revision 'not-a-branch'
>   abort: unknown revision 'not-a-branch'
> @@ -1461,28 +1461,28 @@ glog always reorders nodes which explain
>     (list
>       (func
>         (symbol 'branch')
> -        (string 'default'))
> +        (string 'literal:default'))
>       (or
>         (list
>           (func
>             (symbol 'branch')
> -            (string 'branch'))
> +            (string 'literal:branch'))
>           (func
>             (symbol 'branch')
> -            (string 'branch'))))))
> +            (string 'literal:branch'))))))
>   <filteredset
>     <spanset- 0:37>,
>     <addset
>       <filteredset
>         <fullreposet+ 0:37>,
> -        <branch 'default'>>,
> +        <branch 'literal:default'>>,
>       <addset
>         <filteredset
>           <fullreposet+ 0:37>,
> -          <branch 'branch'>>,
> +          <branch 'literal:branch'>>,
>         <filteredset
>           <fullreposet+ 0:37>,
> -          <branch 'branch'>>>>>
> +          <branch 'literal:branch'>>>>>
>   $ testlog -k expand -k merge
>   []
>   (or
> diff --git a/tests/test-log-bookmark.t b/tests/test-log-bookmark.t
> --- a/tests/test-log-bookmark.t
> +++ b/tests/test-log-bookmark.t
> @@ -190,3 +190,9 @@ Unknown bookmark:
>   $ hg log -B unknown
>   abort: bookmark 'unknown' does not exist
>   [255]
> +
> +Shouldn't accept string-matcher syntax:
> +
> +  $ hg log -B 're:.*'
> +  abort: bookmark 're:.*' does not exist
> +  [255]
> diff --git a/tests/test-log.t b/tests/test-log.t
> --- a/tests/test-log.t
> +++ b/tests/test-log.t
> @@ -1378,6 +1378,14 @@ are specified (issue5100):
>   1 k1
>   0 k0
> 
> + log -b/-u/-k shouldn't accept string-matcher syntax:
> +
> +  $ hg log -b 're:.*'
> +  abort: unknown revision 're:.*'
> +  [255]
> +  $ hg log -k 're:.*'
> +  $ hg log -u 're:.*'
> +
>  log FILE in ascending order, against dagrange:
> 
>   $ hg log -r1:: -T '{rev} {files}\n' f1 f2
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -898,13 +898,13 @@  def _makenofollowfilematcher(repo, pats,
 def _makerevset(repo, wopts, slowpath):
     """Return a revset string built from log options and file patterns"""
     opts = {
-        b'branch': [repo.lookupbranch(b) for b in wopts.branches],
+        b'branch': [b'literal:' + repo.lookupbranch(b) for b in wopts.branches],
         b'date': wopts.date,
         b'keyword': wopts.keywords,
         b'no_merges': wopts.no_merges,
         b'only_merges': wopts.only_merges,
         b'prune': wopts.prune_ancestors,
-        b'user': wopts.users,
+        b'user': [b'literal:' + v for v in wopts.users],
     }
 
     if wopts.filter_revisions_by_pats and slowpath:
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -2310,6 +2310,7 @@  def bookmarkrevs(repo, mark):
 def format_bookmark_revspec(mark):
     """Build a revset expression to select revisions reachable by a given
     bookmark"""
+    mark = b'literal:' + mark
     return revsetlang.formatspec(
         b"ancestors(bookmark(%s)) - "
         b"ancestors(head() and not bookmark(%s)) - "
diff --git a/tests/test-glog-beautifygraph.t b/tests/test-glog-beautifygraph.t
--- a/tests/test-glog-beautifygraph.t
+++ b/tests/test-glog-beautifygraph.t
@@ -1588,19 +1588,19 @@  glog always reorders nodes which explain
     (list
       (func
         (symbol 'user')
-        (string 'test'))
+        (string 'literal:test'))
       (func
         (symbol 'user')
-        (string 'not-a-user'))))
+        (string 'literal:not-a-user'))))
   <filteredset
     <spanset- 0:37>,
     <addset
       <filteredset
         <fullreposet+ 0:37>,
-        <user 'test'>>,
+        <user 'literal:test'>>,
       <filteredset
         <fullreposet+ 0:37>,
-        <user 'not-a-user'>>>>
+        <user 'literal:not-a-user'>>>>
   $ testlog -b not-a-branch
   abort: unknown revision 'not-a-branch'
   abort: unknown revision 'not-a-branch'
@@ -1611,28 +1611,28 @@  glog always reorders nodes which explain
     (list
       (func
         (symbol 'branch')
-        (string 'default'))
+        (string 'literal:default'))
       (or
         (list
           (func
             (symbol 'branch')
-            (string 'branch'))
+            (string 'literal:branch'))
           (func
             (symbol 'branch')
-            (string 'branch'))))))
+            (string 'literal:branch'))))))
   <filteredset
     <spanset- 0:37>,
     <addset
       <filteredset
         <fullreposet+ 0:37>,
-        <branch 'default'>>,
+        <branch 'literal:default'>>,
       <addset
         <filteredset
           <fullreposet+ 0:37>,
-          <branch 'branch'>>,
+          <branch 'literal:branch'>>,
         <filteredset
           <fullreposet+ 0:37>,
-          <branch 'branch'>>>>>
+          <branch 'literal:branch'>>>>>
   $ testlog -k expand -k merge
   []
   (or
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -1438,19 +1438,19 @@  glog always reorders nodes which explain
     (list
       (func
         (symbol 'user')
-        (string 'test'))
+        (string 'literal:test'))
       (func
         (symbol 'user')
-        (string 'not-a-user'))))
+        (string 'literal:not-a-user'))))
   <filteredset
     <spanset- 0:37>,
     <addset
       <filteredset
         <fullreposet+ 0:37>,
-        <user 'test'>>,
+        <user 'literal:test'>>,
       <filteredset
         <fullreposet+ 0:37>,
-        <user 'not-a-user'>>>>
+        <user 'literal:not-a-user'>>>>
   $ testlog -b not-a-branch
   abort: unknown revision 'not-a-branch'
   abort: unknown revision 'not-a-branch'
@@ -1461,28 +1461,28 @@  glog always reorders nodes which explain
     (list
       (func
         (symbol 'branch')
-        (string 'default'))
+        (string 'literal:default'))
       (or
         (list
           (func
             (symbol 'branch')
-            (string 'branch'))
+            (string 'literal:branch'))
           (func
             (symbol 'branch')
-            (string 'branch'))))))
+            (string 'literal:branch'))))))
   <filteredset
     <spanset- 0:37>,
     <addset
       <filteredset
         <fullreposet+ 0:37>,
-        <branch 'default'>>,
+        <branch 'literal:default'>>,
       <addset
         <filteredset
           <fullreposet+ 0:37>,
-          <branch 'branch'>>,
+          <branch 'literal:branch'>>,
         <filteredset
           <fullreposet+ 0:37>,
-          <branch 'branch'>>>>>
+          <branch 'literal:branch'>>>>>
   $ testlog -k expand -k merge
   []
   (or
diff --git a/tests/test-log-bookmark.t b/tests/test-log-bookmark.t
--- a/tests/test-log-bookmark.t
+++ b/tests/test-log-bookmark.t
@@ -190,3 +190,9 @@  Unknown bookmark:
   $ hg log -B unknown
   abort: bookmark 'unknown' does not exist
   [255]
+
+Shouldn't accept string-matcher syntax:
+
+  $ hg log -B 're:.*'
+  abort: bookmark 're:.*' does not exist
+  [255]
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1378,6 +1378,14 @@  are specified (issue5100):
   1 k1
   0 k0
 
+ log -b/-u/-k shouldn't accept string-matcher syntax:
+
+  $ hg log -b 're:.*'
+  abort: unknown revision 're:.*'
+  [255]
+  $ hg log -k 're:.*'
+  $ hg log -u 're:.*'
+
  log FILE in ascending order, against dagrange:
 
   $ hg log -r1:: -T '{rev} {files}\n' f1 f2