views:

198

answers:

6

Standard linux patch hard-coded only for unix text files.

PS: I do no want convert ALL to unix and then convert result back.

+3  A: 

Will the dos2unix command fix the file?

M. S. B.
problem may be solved by converting ALL source to unix and after converting back. but it's sucks.
vitaly.v.ch
A: 

perl -i.bak -pe's/\R/\n/g' inputfile to convert any line ending to the standard.

Anonymous
Thanks, it's interested but not applicable in my situation.
vitaly.v.ch
It answers the question in the title if the diff is based on lines, as they usually are.
Anonymous
+1  A: 

I've run into this problem before a few times. This is what I've discovered:

  • The Linux patch command will not recognize a patchfile that has CRLF in the patch 'meta-lines'.
  • The line-endings of the actual patch content must match the line endings of files being patched.

So this is what I did:

  1. Use dos2unix to convert patch files to LF line-endings only.
  2. Use dos2unix to convert the files being patched to LF line-endings only.
  3. Apply patch.

You can use unix2dos to convert patched files back to CRLF line-endings if you want to maintain that convention.

cscrimge
A: 

I don't know if this will help, but JavaScript is platform neutral, and achieves such by representing the Windows CRLF and the Unix LF as a single \n character. The software interpreting the JavaScript will automatically convert the \n character to the proper new line character(s) depending upon what OS the software is installed upon. As a result if the patches were formed from a JavaScript function process then it would be OS neutral.

That can be achieved if the JavaScript expects to receive certain raw data as a function argument. This can be achieved in an automated method using PERL to submit the data to the software interpreting the JavaScript in Linux or using one of the various command line shells batched into a file for Windows.

A: 

It can be solved by hacking patch utility

vitaly.v.ch
+1  A: 

Combined:

dos2unix patchfile.diff
dos2unix $(grep 'Index:' patchfile.diff | awk '{print $2}')
patch --verbose -p0 -i patchfile.diff
unix2dos $(grep 'Index:' patchfile.diff | awk '{print $2}')

The last line depends on whether you want to keep the CRLFs or not.

M.

PS. This should've been a reply to cscrimge's post. DS.

Martin