changeset 4879:da8640113b5a

Merge with -stable
author Matt Mackall <mpm@selenic.com>
date Sat, 14 Jul 2007 13:34:40 -0500
parents 001e8a745834 (current diff) 372d93f03d3a (diff)
children 2a01e03ffacd
files mercurial/commands.py
diffstat 6 files changed, 213 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Jul 12 10:55:49 2007 -0400
+++ b/mercurial/commands.py	Sat Jul 14 13:34:40 2007 -0500
@@ -1107,7 +1107,11 @@
     reflags = 0
     if opts['ignore_case']:
         reflags |= re.I
-    regexp = re.compile(pattern, reflags)
+    try:
+        regexp = re.compile(pattern, reflags)
+    except Exception, inst:
+        ui.warn(_("grep: invalid match pattern: %s!\n") % inst)
+        return None
     sep, eol = ':', '\n'
     if opts['print0']:
         sep = eol = '\0'
--- a/mercurial/mdiff.py	Thu Jul 12 10:55:49 2007 -0400
+++ b/mercurial/mdiff.py	Sat Jul 14 13:34:40 2007 -0500
@@ -49,6 +49,16 @@
 
 defaultopts = diffopts()
 
+def wsclean(opts, text):
+    if opts.ignorews:
+        text = re.sub('[ \t]+', '', text)
+    elif opts.ignorewsamount:
+        text = re.sub('[ \t]+', ' ', text)
+        text = re.sub('[ \t]+\n', '\n', text)
+    if opts.ignoreblanklines:
+        text = re.sub('\n+', '', text)
+    return text
+
 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
     def datetag(date, addtab=True):
         if not opts.git and not opts.nodates:
@@ -151,13 +161,6 @@
 
     if opts.showfunc:
         funcre = re.compile('\w')
-    if opts.ignorewsamount:
-        wsamountre = re.compile('[ \t]+')
-        wsappendedre = re.compile(' \n')
-    if opts.ignoreblanklines:
-        wsblanklinesre = re.compile('\n')
-    if opts.ignorews:
-        wsre = re.compile('[ \t]')
 
     # bdiff.blocks gives us the matching sequences in the files.  The loop
     # below finds the spaces between those matching sequences and translates
@@ -189,24 +192,8 @@
         if not old and not new:
             continue
 
-        if opts.ignoreblanklines:
-            wsold = wsblanklinesre.sub('', "".join(old))
-            wsnew = wsblanklinesre.sub('', "".join(new))
-            if wsold == wsnew:
-                continue
-
-        if opts.ignorewsamount:
-            wsold = wsamountre.sub(' ', "".join(old))
-            wsold = wsappendedre.sub('\n', wsold)
-            wsnew = wsamountre.sub(' ', "".join(new))
-            wsnew = wsappendedre.sub('\n', wsnew)
-            if wsold == wsnew:
-                continue
-
-        if opts.ignorews:
-            wsold = wsre.sub('', "".join(old))
-            wsnew = wsre.sub('', "".join(new))
-            if wsold == wsnew:
+        if opts.ignorews or opts.ignorewsamount or opts.ignoreblanklines:
+            if wsclean(opts, "".join(old)) == wsclean(opts, "".join(new)):
                 continue
 
         astart = contextstart(a1)
--- a/tests/test-diff-ignore-whitespace	Thu Jul 12 10:55:49 2007 -0400
+++ b/tests/test-diff-ignore-whitespace	Sat Jul 14 13:34:40 2007 -0500
@@ -3,6 +3,7 @@
 # GNU diff is the reference for all of these results.
 
 hgdiff() {
+    echo hg diff $@
     hg diff --nodates "$@"
 }
 
@@ -72,6 +73,39 @@
     hgdiff -Bb
 }
 
+test_added_blank_line_with_other_whitespace() {
+    printf 'hello  world\n \t\ngoodbye world \n' >foo
+
+    echo '>>> three diffs showing added blank line w/other space <<<'
+    hgdiff
+    hgdiff -B
+    hgdiff -b
+    hgdiff -Bb
+}
+
+test_whitespace_changes() {
+    printf 'helloworld\ngoodbye\tworld \n' >foo
+
+    echo '>>> four diffs showing changed whitespace <<<'
+    hgdiff
+    hgdiff -B
+    hgdiff -b
+    hgdiff -Bb
+    hgdiff -w
+}
+
+test_whitespace_changes_and_blank_lines() {
+    printf 'helloworld\n\n\n\ngoodbye\tworld \n' >foo
+
+    echo '>>> five diffs showing changed whitespace <<<'
+    hgdiff
+    hgdiff -B
+    hgdiff -b
+    hgdiff -Bb
+    hgdiff -w
+    hgdiff -wB
+}
+
 hg init
 printf 'hello world\ngoodbye world\n' >foo
 hg ci -Amfoo -ufoo -d '0 0'
@@ -82,3 +116,6 @@
 test_added_horizontal_space_in_the_middle_of_a_word
 test_increased_horizontal_whitespace_amount
 test_added_blank_line_with_horizontal_whitespace
+test_added_blank_line_with_other_whitespace
+test_whitespace_changes
+test_whitespace_changes_and_blank_lines
--- a/tests/test-diff-ignore-whitespace.out	Thu Jul 12 10:55:49 2007 -0400
+++ b/tests/test-diff-ignore-whitespace.out	Sat Jul 14 13:34:40 2007 -0500
@@ -1,5 +1,6 @@
 adding foo
 >>> two diffs showing three added lines <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -9,6 +10,7 @@
 +
  goodbye world
 +
+hg diff -b
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -19,7 +21,10 @@
  goodbye world
 +
 >>> no diffs <<<
+hg diff -B
+hg diff -Bb
 >>> four diffs showing added space first on the first line <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -27,6 +32,7 @@
 -hello world
 +	 hello world
  goodbye world
+hg diff -b
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -34,6 +40,7 @@
 -hello world
 +	 hello world
  goodbye world
+hg diff -B
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -41,6 +48,7 @@
 -hello world
 +	 hello world
  goodbye world
+hg diff -Bb
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -49,6 +57,7 @@
 +	 hello world
  goodbye world
 >>> two diffs showing space appended to the first line <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -56,6 +65,7 @@
 -hello world
 +hello world	 
  goodbye world
+hg diff -B
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -64,7 +74,10 @@
 +hello world	 
  goodbye world
 >>> no diffs <<<
+hg diff -b
+hg diff -Bb
 >>> four diffs showing space inserted into "goodbye" <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -72,6 +85,7 @@
  hello world
 -goodbye world
 +good bye world
+hg diff -B
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -79,6 +93,7 @@
  hello world
 -goodbye world
 +good bye world
+hg diff -b
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -86,6 +101,7 @@
  hello world
 -goodbye world
 +good bye world
+hg diff -Bb
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -94,6 +110,7 @@
 -goodbye world
 +good bye world
 >>> two diffs showing changed whitespace amount in the last line <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -101,6 +118,7 @@
  hello world
 -goodbye world
 +goodbye		  	world
+hg diff -B
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -109,7 +127,10 @@
 -goodbye world
 +goodbye		  	world
 >>> no diffs <<<
+hg diff -b
+hg diff -Bb
 >>> four diffs showing added blank line w/horizontal space <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -117,6 +138,15 @@
  hello world
 + 	
  goodbye world
+hg diff -B
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,3 @@ hello world
+ hello world
++ 	
+ goodbye world
+hg diff -b
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
@@ -124,17 +154,136 @@
  hello world
 + 	
  goodbye world
+hg diff -Bb
+>>> three diffs showing added blank line w/other space <<<
+hg diff
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,3 @@ hello world
+-hello world
+-goodbye world
++hello  world
++ 	
++goodbye world 
+hg diff -B
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,3 @@ hello world
+-hello world
+-goodbye world
++hello  world
++ 	
++goodbye world 
+hg diff -b
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
 @@ -1,2 +1,3 @@ hello world
- hello world
+-hello world
+-goodbye world
++hello  world
 + 	
- goodbye world
++goodbye world 
+hg diff -Bb
+>>> four diffs showing changed whitespace <<<
+hg diff
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,2 @@ hello world
+-hello world
+-goodbye world
++helloworld
++goodbye	world 
+hg diff -B
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,2 @@ hello world
+-hello world
+-goodbye world
++helloworld
++goodbye	world 
+hg diff -b
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,2 @@ hello world
+-hello world
+-goodbye world
++helloworld
++goodbye	world 
+hg diff -Bb
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,2 @@ hello world
+-hello world
+-goodbye world
++helloworld
++goodbye	world 
+hg diff -w
+>>> five diffs showing changed whitespace <<<
+hg diff
 diff -r 540c40a65b78 foo
 --- a/foo
 +++ b/foo
-@@ -1,2 +1,3 @@ hello world
- hello world
-+ 	
- goodbye world
+@@ -1,2 +1,5 @@ hello world
+-hello world
+-goodbye world
++helloworld
++
++
++
++goodbye	world 
+hg diff -B
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,5 @@ hello world
+-hello world
+-goodbye world
++helloworld
++
++
++
++goodbye	world 
+hg diff -b
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,5 @@ hello world
+-hello world
+-goodbye world
++helloworld
++
++
++
++goodbye	world 
+hg diff -Bb
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,5 @@ hello world
+-hello world
+-goodbye world
++helloworld
++
++
++
++goodbye	world 
+hg diff -w
+diff -r 540c40a65b78 foo
+--- a/foo
++++ b/foo
+@@ -1,2 +1,5 @@ hello world
+-hello world
+-goodbye world
++helloworld
++
++
++
++goodbye	world 
+hg diff -wB
--- a/tests/test-grep	Thu Jul 12 10:55:49 2007 -0400
+++ b/tests/test-grep	Sat Jul 14 13:34:40 2007 -0500
@@ -17,6 +17,8 @@
 head -n 3 port > port1
 mv port1 port
 hg commit -m 4 -u spam -d '4 0'
+echo % pattern error
+hg grep '**test**'
 echo % simple
 hg grep port port
 echo % all
--- a/tests/test-grep.out	Thu Jul 12 10:55:49 2007 -0400
+++ b/tests/test-grep.out	Sat Jul 14 13:34:40 2007 -0500
@@ -1,3 +1,5 @@
+% pattern error
+grep: invalid match pattern: nothing to repeat!
 % simple
 port:4:export
 port:4:vaportight