1

I have a file with DOS-style line endings in an *.orig.tar.xz source package that I need to patch before building a 3.0 (quilt) debian package. My patch currently has unix-style line endings.

We can inspect the files to see the patch has 29 unix-style line ending, and the source file has 5000 dos-style line endings.

$ dos2unix -i debian/patches/model_icd CONFIG/model_config_file.txt 0 29 0 no_bom text debian/patches/model_icd 5000 0 0 no_bom text CONFIG/model_config_file.txt 

Building results:

$ dpkg-buildpackage ... dpkg-source --before-build . dpkg-source: info: using patch list from debian/patches/series dpkg-source: info: applying model_icd patching file CONFIG/model_config_file.txt Hunk #1 FAILED at 1638 (different line endings). Hunk #2 FAILED at 4997 (different line endings). 2 out of 2 hunks FAILED dpkg-source: info: the patch has fuzz which is not allowed, or is malformed dpkg-source: info: if patch 'model_icd' is correctly applied by quilt, use 'quilt refresh' to update it dpkg-source: info: restoring quilt backup files for model_icd dpkg-source: error: LC_ALL=C patch -t -F 0 -N -p1 -u -V never -E -b -B .pc/model_icd/ --reject-file=- < debian/patches/model_icd subprocess returned exit status 1 dpkg-buildpackage: error: dpkg-source --before-build . subprocess returned exit status 2 

Things I've tried:

First, I simply modified my patch to use dos-style line endings, but quilt strips that out and I get the same result

$ unix2dos debian/patches/model_icd $ dos2unix -i debian/patches/model_icd CONFIG/model_config_file.txt 29 0 0 no_bom text debian/patches/model_icd 5000 0 0 no_bom text CONFIG/model_config_file.txt $ dpkg-buildpackage ... dpkg-source: info: applying model_icd (Stripping trailing CRs from patch; use --binary to disable.) patching file CONFIG/model_config_file.txt Hunk #1 FAILED at 1638 (different line endings). Hunk #2 FAILED at 4997 (different line endings). 2 out of 2 hunks FAILED ... 

If I test with quilt directly, I can get it to work with the --binary option:

$ quilt push -a --binary Applying patch model_icd patching file CONFIG/model_config_file.txt Now at patch model_icd 

To get this to work more automatically, I've tried setting QUILT_PATCH_OPTS=:

$ QUILT_PATCH_OPTS="--binary" quilt push -a Applying patch model_icd patching file CONFIG/model_config_file.txt Now at patch model_icd 

So next, I tried setting this in debian/rules:

export QUILT_PATCH_OPTS="--binary" %: dh $@ 

But this doesn't get used by dpkg-source which uses patch directly, not quilt

Next, I tried to fool it by setting this flag in the patches/series file. dpkg-source(1) recommends against this, which suggests it could be possible.

# debian/patches/series model_icd --binary 

But that still doesn't work.

I've tried looking in source/options hoping for something, and I've been reading the maintainer's guide but I don't see this covered anywhere.

1
  • 1
    Regarding patch options in patches/series, note that the dpkg-source man page doesn’t just recommend against it: “it does ignore those options and always expects patches that can be applied with the -p1 option of patch.” Commented Apr 15 at 9:22

1 Answer 1

2

I've read that dpkg-source --commit is a bit of a sledge-hammer, and quilt gives more control, but in this case, it was my easiest solution.

First make sure no patches are applied

$ quilt pop -a No patch removed 

Dos-ify the patch so the line endings match the source file

$ unix2dos debian/patches/model_icd unix2dos: converting file debian/patches/model_icd to DOS format... 

Apply the patch, using --binary to preserve the CRs

$ patch -p1 --binary < debian/patches/model_icd patching file CONFIG/model_config_file.txt 

Remove the original patch file

$ rm debian/patches/model_icd 

Remove the patch from the series file

$ sed -i '/model_icd/d' debian/patches/series 

Use dpkg-source --commit to regenerate the patch file

$ dpkg-source --commit dpkg-source: info: using patch list from debian/patches/series dpkg-source: info: local changes detected, the modified files are: CONFIG/model_config_file.txt Enter the desired patch name: model_icd dpkg-source: info: local changes have been recorded in a new patch: debian/patches/model_icd 

I'm sure there must be a more elegant solution, as this doesn't seem like a new or uncommon problem. But it wasn't easy to find online or in any official docs which is why I'm writing up this answer.

This patch is actually the last in a series, and it still worked with multiple patches. There might be some difficulty if this isn't the last in the sequence though. You'd need to do the patches one-at-a-time in that case.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.