Patchwork [V2] fix: change the default fix pattern (issue6077)

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date Feb. 13, 2019, 10:54 p.m.
Message ID <d8ba3b6466b220a5e04d.1550098458@chloe>
Download mbox | patch
Permalink /patch/38736/
State New
Headers show

Comments

Jordi Gutiérrez Hermoso - Feb. 13, 2019, 10:54 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1550096863 18000
#      Wed Feb 13 17:27:43 2019 -0500
# Node ID d8ba3b6466b220a5e04d07a5eccd3c1d45a2f501
# Parent  5d383d9636d0b81b416398913b32b8c715e98db5
fix: change the default fix pattern (issue6077)

The matchutils functions don't know what to do with an empty pattern.
When a fixer doesn't have a pattern at all, a default of None will
make match functions unhappy and stack trace.

Change this default instead to a pattern that matches everything.
Yuya Nishihara - Feb. 14, 2019, 2:45 p.m.
On Wed, 13 Feb 2019 17:54:18 -0500, Jordi Gutiérrez Hermoso wrote:
> # HG changeset patch
> # User Jordi Gutiérrez Hermoso <jordigh@octave.org>
> # Date 1550096863 18000
> #      Wed Feb 13 17:27:43 2019 -0500
> # Node ID d8ba3b6466b220a5e04d07a5eccd3c1d45a2f501
> # Parent  5d383d9636d0b81b416398913b32b8c715e98db5
> fix: change the default fix pattern (issue6077)
> 
> The matchutils functions don't know what to do with an empty pattern.
> When a fixer doesn't have a pattern at all, a default of None will
> make match functions unhappy and stack trace.
> 
> Change this default instead to a pattern that matches everything.
> 
> diff --git a/hgext/fix.py b/hgext/fix.py
> --- a/hgext/fix.py
> +++ b/hgext/fix.py
> @@ -38,7 +38,8 @@ substituted into the command::
>  
>  The :pattern suboption determines which files will be passed through each
>  configured tool. See :hg:`help patterns` for possible values. If there are file
> -arguments to :hg:`fix`, the intersection of these patterns is used.
> +arguments to :hg:`fix`, the intersection of these patterns is used. If no patterns
> +are specified, the default is to apply the tool to all files.
>  
>  There is also a configurable limit for the maximum size of file that will be
>  processed by :hg:`fix`::
> @@ -122,7 +123,7 @@ FIXER_ATTRS = {
>      'command': None,
>      'linerange': None,
>      'fileset': None,
> -    'pattern': None,
> +    'pattern': '.',

Perhaps it would mean 'relpath:.' (any files under the current directory, not
under the repository root.)

I think it's better to either pass in an empty list to scmutil.match() or use
scmutil.matchall() if _pattern is None.

Patch

diff --git a/hgext/fix.py b/hgext/fix.py
--- a/hgext/fix.py
+++ b/hgext/fix.py
@@ -38,7 +38,8 @@  substituted into the command::
 
 The :pattern suboption determines which files will be passed through each
 configured tool. See :hg:`help patterns` for possible values. If there are file
-arguments to :hg:`fix`, the intersection of these patterns is used.
+arguments to :hg:`fix`, the intersection of these patterns is used. If no patterns
+are specified, the default is to apply the tool to all files.
 
 There is also a configurable limit for the maximum size of file that will be
 processed by :hg:`fix`::
@@ -122,7 +123,7 @@  FIXER_ATTRS = {
     'command': None,
     'linerange': None,
     'fileset': None,
-    'pattern': None,
+    'pattern': '.',
     'priority': 0,
 }
 
diff --git a/tests/test-fix.t b/tests/test-fix.t
--- a/tests/test-fix.t
+++ b/tests/test-fix.t
@@ -288,17 +288,28 @@  we ignore a file that doesn't match any 
 
   $ cd ..
 
+A config file missing a :pattern suboption to match issue6077
+
+  $ REMOVE_WS=$TESTTMP/remove-trailing-whitespace.hgrc
+  $ cat >> $REMOVE_WS <<EOF
+  > [extensions]
+  > fix =
+  > [fix]
+  > trailing-whitespace:command = sed
+  > trailing-whitespace:linerange = -e '{first},{last}s/\s\+$//'
+  > EOF
+
 Fixing the working directory should still work if there are no revisions.
 
   $ hg init norevisions
   $ cd norevisions
 
-  $ printf "something\n" > something.whole
+  $ printf "something   \n" > something.whole
   $ hg add
   adding something.whole
-  $ hg fix --working-dir
+  $ HGRCPATH=$REMOVE_WS hg fix --working-dir
   $ cat something.whole
-  SOMETHING
+  something
 
   $ cd ..