Issue1763

Title patch.patch incorrectly reads crlf (dos style) git patches
Priority bug Status done-cbb
Superseder Nosy List BillBarry, mg, pmezard, tonfa
Assigned To Topics patch

Created on 2009-07-24.15:51:17 by BillBarry, last changed 2012-02-01.00:17:21 by mpm.

Files
File name Uploaded Type Edit Remove
simple BillBarry, 2009-07-24.16:38:18 application/octet-stream
Messages
msg12103 (view) Author: mg Date: 2010-03-19.20:13:13
The patch.eol=auto setting is for file content: line-endings are ignored in
the patch and line-endings are preserved in the patched files.

I don't think it affects this report since this is about parsing the patch
in the first place?
msg12099 (view) Author: tonfa Date: 2010-03-19.19:37:53
What is the status of this with the patch.eol option?
msg11364 (view) Author: pmezard Date: 2010-01-03.12:40:15
Because your working directory is in CRLF?

I am not sure what this issue is about.
msg10222 (view) Author: BillBarry Date: 2009-07-26.18:34:49
I was wrong. The code below which I am using to shelve does create patches
with LF line endings only in the header. So why did my patch have incorrect
line endings?
msg10213 (view) Author: pmezard Date: 2009-07-25.17:18:12
Could you elaborate how?

Here is what I tried:

"""
>hg init t
>cd t
>echo a > a
>echo b >> a
>echo c >> a
>hg add
adding a
>hg ci -m adda
>echo a > a
>echo d >> a
>echo c >> a
>hg diff > test.diff
>python -c "print repr(file('test.diff', 'rb').read())"
'diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1,3 +1,3 @@\n a \r\n-b \r\n+d \r\n c
\r\n'
>hg qnew -f -e test
>hg export . > test2.diff
>python -c "print repr(file('test2.diff', 'rb').read())"
'# HG changeset patch\n# User Patrick Mezard <pmezard@gmail.com>\n# Date 1248542
070 -7200\n# Node ID c44c87ce654a895c526878ec1c389757c76aa6fc\n# Parent  249f520
79d7a991acf52bbaa235fe701a5ec7318\nline1\nline2\nline3\n\ndiff --git a/a b/a\n--
- a/a\n+++ b/a\n@@ -1,3 +1,3 @@\n a \r\n-b \r\n+d \r\n c \r\n'
>python -c "print repr(file('.hg/patches/test', 'rb').read())"

'line1\nline2\nline3\n\ndiff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1,3 +1,3 @@\n
a \r\n-b \r\n+d \r\n c \r\n'
"""
msg10206 (view) Author: BillBarry Date: 2009-07-24.17:14:06
This being the case then mq is generating patches wrong on windows (I can
generate that exact same patch with mq except that it will not have the "#
Parent" line).
msg10205 (view) Author: pmezard Date: 2009-07-24.16:48:28
The thing is diff headers are currently supposed to be LF only, on Windows
and everywhere else. This is also the behaviour of my cygwin diff. So, we
have to decide whether we want to support CRLF diff headers, and if so
update the whole parser accordingly rather than fixing up this specific part.
msg10204 (view) Author: BillBarry Date: 2009-07-24.16:38:18
patch file attached
--
I generated the patch with Mercurial via attic ("hg shelve simple") using
[1]; nothing too special though, it just iterates through patch.diff and
outputs to a file the chunks after writing an hg changeset header (readable
by patch.extract).

1:
    def createpatch(self, repo, name, msg, user, date, pats=[], opts={}):
        """creates a patch from the current state of the working copy"""
        fp = self.opener(name, 'w')
        ctx = repo[None]
        fp.write('# HG changeset patch\n')
        if user:
            fp.write('# User %s\n' % user)
        if date:
            fp.write('# Date %d %d\n' % date)
        parents = [p.node() for p in ctx.parents() if p]
        if parents and parents[0]:
            fp.write('# Parent  %s\n' % hex(parents[0]))
        if msg:
            if not isinstance(msg, str):
                msg = '\n'.join(msg)
            if msg and msg[-1] != '\n':
                msg += '\n'
            fp.write(msg)
        m = cmdutil.match(repo, pats, opts)
        chunks = patch.diff(repo, match = m, opts = self.diffopts(opts))
        for chunk in chunks:
            fp.write(chunk)
        fp.close()
        self.currentpatch=name
        self.persiststate()
msg10203 (view) Author: pmezard Date: 2009-07-24.16:05:40
Could you attach the patch file to the issue?
Did you generate the patch with Mercurial?
msg10202 (view) Author: BillBarry Date: 2009-07-24.15:51:17
With the following patch (dos style crlf line endings):

# HG changeset patch
# User Bill Barry <after.fallout@gmail.com>
# Parent  a0dd4aaaaaff120d5e743c4a33857f856b8fc2fe
diff --git a/test.txt b/test.txt
--- a/test.txt
+++ b/test.txt
@@ -23,6 +23,7 @@
 m
 n
 o
+a simple change
 p
 q
 r


patch.patch is setting the files output parameter to:
{'test.txt': None, 'test.txt\r': <mercurial.patch.patchmeta object at
0x00DD89D0>}

causing an immediate patch.updatedir call to emit:
: The filename, directory name, or volume label syntax is incorrect

when it iterates over ['test.txt', 'test.txt\r'] in the call to
cmdutil.addremove
History
Date User Action Args
2012-02-01 00:17:21mpmsetstatus: chatting -> done-cbb
nosy: tonfa, pmezard, mg, BillBarry
2010-03-19 20:13:13mgsetnosy: tonfa, pmezard, mg, BillBarry
messages: + msg12103
2010-03-19 19:37:53tonfasettopic: + patch
nosy: + tonfa, mg
messages: + msg12099
2010-01-03 12:40:15pmezardsetnosy: pmezard, BillBarry
messages: + msg11364
2009-07-26 18:34:49BillBarrysetnosy: pmezard, BillBarry
messages: + msg10222
2009-07-25 17:18:12pmezardsetnosy: pmezard, BillBarry
messages: + msg10213
2009-07-24 17:14:06BillBarrysetnosy: pmezard, BillBarry
messages: + msg10206
2009-07-24 16:48:28pmezardsetnosy: pmezard, BillBarry
messages: + msg10205
2009-07-24 16:38:18BillBarrysetfiles: + simple
nosy: pmezard, BillBarry
messages: + msg10204
2009-07-24 16:05:40pmezardsetstatus: unread -> chatting
nosy: + pmezard
messages: + msg10203
2009-07-24 15:51:18BillBarrycreate