[PATCH 1 of 1] patch: generate .rej wihtout eol adaptation

Matt Mackall mpm at selenic.com
Sat Dec 4 17:07:55 CST 2010


On Fri, 2010-12-03 at 11:44 +0900, Shun-ichi Goto wrote:
> # HG changeset patch
> # User Shun-ichi GOTO <shunichi.goto at gmail.com>
> # Date 1291344030 -32400
> # Node ID ad4e934ef9dbe2a82d9477f5aed39ec0df6fc7d2
> # Parent  cec6140b0f3c8c00515dbf3589068d1e2d233fdf
> patch: generate .rej wihtout eol adaptation

Martin or Patrick, do you have an opinion about this?

> When patch.eol=auto and patch has CRLF content, incorrect .rej file
> having CRCRLF is generated because patchfile.write_rej() uses
> patchfile.writelines() which makes eol adaptation.
> 
> This changeset add optional boolean argument 'strict' to writelines()
> to choose eol adaptation.
> 
> Add test for this issue. To reproduce this issue:
>  1. make taget file having CRLF line ending
>  2. make patch file having CRLF content line ending
>  3. prepare patch which would conflict
>  4. applying patch with option 'patch.eol=auto'
>  5. check .rej file has CRCRLF <= incorrect!
> 
> diff -r cec6140b0f3c -r ad4e934ef9db mercurial/patch.py
> --- a/mercurial/patch.py	Thu Dec 02 18:14:04 2010 +0900
> +++ b/mercurial/patch.py	Fri Dec 03 11:40:30 2010 +0900
> @@ -425,7 +425,7 @@
>          finally:
>              fp.close()
>  
> -    def writelines(self, fname, lines):
> +    def writelines(self, fname, lines, strict=False):
>          # Ensure supplied data ends in fname, being a regular file or
>          # a symlink. cmdutil.updatedir will -too magically- take care
>          # of setting it to the proper type afterwards.
> @@ -435,7 +435,9 @@
>          else:
>              fp = self.opener(fname, 'w')
>          try:
> -            if self.eolmode == 'auto':
> +            if strict:
> +                eol = None
> +            elif self.eolmode == 'auto':
>                  eol = self.eol
>              elif self.eolmode == 'crlf':
>                  eol = '\r\n'
> @@ -508,7 +510,7 @@
>                      if l[-1] != '\n':
>                          yield "\n\ No newline at end of file\n"
>  
> -        self.writelines(fname, rejlines())
> +        self.writelines(fname, rejlines(), strict=True)
>  
>      def apply(self, h):
>          if not h.complete():
> diff -r cec6140b0f3c -r ad4e934ef9db tests/test-mq-eol.t
> --- a/tests/test-mq-eol.t	Thu Dec 02 18:14:04 2010 +0900
> +++ b/tests/test-mq-eol.t	Fri Dec 03 11:40:30 2010 +0900
> @@ -141,3 +141,94 @@
>    $ hg qpop
>    popping eol.diff
>    patch queue now empty
> +
> +
> +.rej file should not apply eol adaptaion.
> +For example, .rej should not have CRCRLF agaist CRLF file when eol=auto.
> +
> +  $ echo "[extensions]" >> $HGRCPATH
> +  $ echo "mq=" >> $HGRCPATH
> +
> +  $ hg init r
> +  $ cd r
> +
> +  $ printf '1 hello\r\n' >> a.txt
> +  $ printf '2 hello\r\n' >> a.txt
> +  $ printf '3 hello\r\n' >> a.txt
> +  $ printf '4 hello\r\n' >> a.txt
> +
> +  $ hg ci -Am 1
> +  adding a.txt
> +
> +  $ rm a.txt
> +  $ printf '1 hello\r\n' >> a.txt
> +  $ printf '2 hello\r\n' >> a.txt
> +  $ printf '3 HELLO\r\n' >> a.txt
> +  $ printf '4 hello\r\n' >> a.txt
> +
> +  $ hg qnew -fm "patch" m1
> +  $ hg qpop
> +  popping m1
> +  patch queue now empty
> +
> +  $ rm a.txt
> +  $ printf '1 hello\r\n' >> a.txt
> +  $ printf '2 good morning\r\n' >> a.txt
> +  $ printf '3 HELLO\r\n' >> a.txt
> +  $ printf '4 hello\r\n' >> a.txt
> +
> +  $ hg ci -m 2
> +
> +  $ hg --config 'patch.eol=LF' qpush
> +  applying m1
> +  patching file a.txt
> +  Hunk #1 FAILED at 0
> +  1 out of 1 hunks FAILED -- saving rejects to file a.txt.rej
> +  patch failed, unable to continue (try -v)
> +  patch failed, rejects left in working dir
> +  errors during apply, please fix and refresh m1
> +  [2]
> +  $ hg qpop
> +  popping m1
> +  patch queue now empty
> +  $ cat a.txt
> +  1 hello\r (esc)
> +  2 good morning\r (esc)
> +  3 HELLO\r (esc)
> +  4 hello\r (esc)
> +  $ cat a.txt.rej
> +  --- a.txt
> +  +++ a.txt
> +  @@ -1,4 +1,4 @@
> +   1 hello\r (esc)
> +   2 hello\r (esc)
> +  -3 hello\r (esc)
> +  +3 HELLO\r (esc)
> +   4 hello\r (esc)
> +
> +  $ hg --config 'patch.eol=auto' qpush
> +  applying m1
> +  patching file a.txt
> +  Hunk #1 FAILED at 0
> +  1 out of 1 hunks FAILED -- saving rejects to file a.txt.rej
> +  patch failed, unable to continue (try -v)
> +  patch failed, rejects left in working dir
> +  errors during apply, please fix and refresh m1
> +  [2]
> +  $ hg qpop
> +  popping m1
> +  patch queue now empty
> +  $ cat a.txt
> +  1 hello\r (esc)
> +  2 good morning\r (esc)
> +  3 HELLO\r (esc)
> +  4 hello\r (esc)
> +  $ cat a.txt.rej
> +  --- a.txt
> +  +++ a.txt
> +  @@ -1,4 +1,4 @@
> +   1 hello\r (esc)
> +   2 hello\r (esc)
> +  -3 hello\r (esc)
> +  +3 HELLO\r (esc)
> +   4 hello\r (esc)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list