Patchwork [1,of,4] patch: make diff in Git mode respect --text option (issue5510)

login
register
mail settings
Submitter Alexander Fomin
Date April 4, 2017, 10:21 p.m.
Message ID <9be2b4ec19e846d2a95f.1491344480@devvm2125.lla2.facebook.com>
Download mbox | patch
Permalink /patch/19960/
State Changes Requested
Headers show

Comments

Alexander Fomin - April 4, 2017, 10:21 p.m.
# HG changeset patch
# User Alexander Fomin <afomin@fb.com>
# Date 1490992236 25200
#      Fri Mar 31 13:30:36 2017 -0700
# Node ID 9be2b4ec19e846d2a95fe801ebe76f83fffd1ea9
# Parent  65969cd351b73228642d1e491e8c78b20d85405a
patch: make diff in Git mode respect --text option (issue5510)

This changeset makes patch respect -a/--text option in --git mode by aligning
its behaviour with Git itself.
Ryan McElroy - April 5, 2017, 2:37 p.m.
On 4/4/17 11:21 PM, Alexander Fomin wrote:
> # HG changeset patch
> # User Alexander Fomin <afomin@fb.com>
> # Date 1490992236 25200
> #      Fri Mar 31 13:30:36 2017 -0700
> # Node ID 9be2b4ec19e846d2a95fe801ebe76f83fffd1ea9
> # Parent  65969cd351b73228642d1e491e8c78b20d85405a
> patch: make diff in Git mode respect --text option (issue5510)
>
> This changeset makes patch respect -a/--text option in --git mode by aligning
> its behaviour with Git itself.
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -2552,7 +2552,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi
>           elif revs and not repo.ui.quiet:
>               header.append(diffline(path1, revs))
>   
> -        if binary and opts.git and not opts.nobinary:
> +        if binary and opts.git and not opts.nobinary and not opts.text:
>               text = mdiff.b85diff(content1, content2)
>               if text:
>                   header.append('index %s..%s' %
> diff --git a/tests/test-diff-binary-file.t b/tests/test-diff-binary-file.t
> --- a/tests/test-diff-binary-file.t
> +++ b/tests/test-diff-binary-file.t
> @@ -73,5 +73,38 @@
>     literal 5
>     Mc$_OqttjCF00uV!&;S4c
>     
> +  $ cd ..

This should have a comment (any unindented text is a comment) explaining 
what the test is doing. Something simple like "Test text mode with 
git-style diff"
> +
> +  $ hg init b
> +  $ cd b
> +  $ cat > writebin.py <<EOF
> +  > import sys
> +  > path = sys.argv[1]
> +  > open(path, 'wb').write('\x00\x01\x02\x03')
> +  > EOF

Why not use printf here?

> +  $ python writebin.py binfile.bin
> +  $ hg add binfile.bin
> +  $ hg ci -m 'add binfile.bin'
> +
> +  $ echo >> binfile.bin
> +  $ hg ci -m 'change binfile.bin'
> +
> +  $ hg diff --git -a -r 0 -r 1
> +  diff --git a/binfile.bin b/binfile.bin
> +  --- a/binfile.bin
> +  +++ b/binfile.bin
> +  @@ -1,1 +1,1 @@
> +  -\x00\x01\x02\x03 (esc)
> +  \ No newline at end of file
> +  +\x00\x01\x02\x03 (esc)
> +
> +  $ HGPLAIN=1 hg diff --git -a -r 0 -r 1
> +  diff --git a/binfile.bin b/binfile.bin
> +  --- a/binfile.bin
> +  +++ b/binfile.bin
> +  @@ -1,1 +1,1 @@
> +  -\x00\x01\x02\x03 (esc)
> +  \ No newline at end of file
> +  +\x00\x01\x02\x03 (esc)
>   
>     $ cd ..
>

Nice! The code changes look good, just the test I'd like a response on.
Alexander Fomin - April 5, 2017, 9:43 p.m.
On 05/04/2017, 07:37, "Ryan McElroy" <rm@fb.com> wrote:
> 

> On 4/4/17 11:21 PM, Alexander Fomin wrote:

> > # HG changeset patch

> > # User Alexander Fomin <afomin@fb.com>

> > # Date 1490992236 25200

> > #      Fri Mar 31 13:30:36 2017 -0700

> > # Node ID 9be2b4ec19e846d2a95fe801ebe76f83fffd1ea9

> > # Parent  65969cd351b73228642d1e491e8c78b20d85405a

> > patch: make diff in Git mode respect --text option (issue5510)

> >

> > This changeset makes patch respect -a/--text option in --git mode by aligning

> > its behaviour with Git itself.

> >

> > diff --git a/mercurial/patch.py b/mercurial/patch.py

> > --- a/mercurial/patch.py

> > +++ b/mercurial/patch.py

> > @@ -2552,7 +2552,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi

> >           elif revs and not repo.ui.quiet:

> >               header.append(diffline(path1, revs))

> >

> > -        if binary and opts.git and not opts.nobinary:

> > +        if binary and opts.git and not opts.nobinary and not opts.text:

> >               text = mdiff.b85diff(content1, content2)

> >               if text:

> >                   header.append('index %s..%s' %

> > diff --git a/tests/test-diff-binary-file.t b/tests/test-diff-binary-file.t

> > --- a/tests/test-diff-binary-file.t

> > +++ b/tests/test-diff-binary-file.t

> > @@ -73,5 +73,38 @@

> >     literal 5

> >     Mc$_OqttjCF00uV!&;S4c

> >

> > +  $ cd ..

> 

> This should have a comment (any unindented text is a comment) explaining

> what the test is doing. Something simple like "Test text mode with

> git-style diff"

Got it, thanks!
> > +

> > +  $ hg init b

> > +  $ cd b

> > +  $ cat > writebin.py <<EOF

> > +  > import sys

> > +  > path = sys.argv[1]

> > +  > open(path, 'wb').write('\x00\x01\x02\x03')

> > +  > EOF

> 

> Why not use printf here?

> 

That’s because hg linter (test-check-code.t) doesn’t like printf :-(
> > +  $ python writebin.py binfile.bin

> > +  $ hg add binfile.bin

> > +  $ hg ci -m 'add binfile.bin'

> > +

> > +  $ echo >> binfile.bin

> > +  $ hg ci -m 'change binfile.bin'

> > +

> > +  $ hg diff --git -a -r 0 -r 1

> > +  diff --git a/binfile.bin b/binfile.bin

> > +  --- a/binfile.bin

> > +  +++ b/binfile.bin

> > +  @@ -1,1 +1,1 @@

> > +  -\x00\x01\x02\x03 (esc)

> > +  \ No newline at end of file

> > +  +\x00\x01\x02\x03 (esc)

> > +

> > +  $ HGPLAIN=1 hg diff --git -a -r 0 -r 1

> > +  diff --git a/binfile.bin b/binfile.bin

> > +  --- a/binfile.bin

> > +  +++ b/binfile.bin

> > +  @@ -1,1 +1,1 @@

> > +  -\x00\x01\x02\x03 (esc)

> > +  \ No newline at end of file

> > +  +\x00\x01\x02\x03 (esc)

> >

> >     $ cd ..

> >

> 

> Nice! The code changes look good, just the test I'd like a response on.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2552,7 +2552,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
         elif revs and not repo.ui.quiet:
             header.append(diffline(path1, revs))
 
-        if binary and opts.git and not opts.nobinary:
+        if binary and opts.git and not opts.nobinary and not opts.text:
             text = mdiff.b85diff(content1, content2)
             if text:
                 header.append('index %s..%s' %
diff --git a/tests/test-diff-binary-file.t b/tests/test-diff-binary-file.t
--- a/tests/test-diff-binary-file.t
+++ b/tests/test-diff-binary-file.t
@@ -73,5 +73,38 @@ 
   literal 5
   Mc$_OqttjCF00uV!&;S4c
   
+  $ cd ..
+
+  $ hg init b
+  $ cd b
+  $ cat > writebin.py <<EOF
+  > import sys
+  > path = sys.argv[1]
+  > open(path, 'wb').write('\x00\x01\x02\x03')
+  > EOF
+  $ python writebin.py binfile.bin
+  $ hg add binfile.bin
+  $ hg ci -m 'add binfile.bin'
+
+  $ echo >> binfile.bin
+  $ hg ci -m 'change binfile.bin'
+
+  $ hg diff --git -a -r 0 -r 1
+  diff --git a/binfile.bin b/binfile.bin
+  --- a/binfile.bin
+  +++ b/binfile.bin
+  @@ -1,1 +1,1 @@
+  -\x00\x01\x02\x03 (esc)
+  \ No newline at end of file
+  +\x00\x01\x02\x03 (esc)
+
+  $ HGPLAIN=1 hg diff --git -a -r 0 -r 1
+  diff --git a/binfile.bin b/binfile.bin
+  --- a/binfile.bin
+  +++ b/binfile.bin
+  @@ -1,1 +1,1 @@
+  -\x00\x01\x02\x03 (esc)
+  \ No newline at end of file
+  +\x00\x01\x02\x03 (esc)
 
   $ cd ..