git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/3] apply: handle traditional patches with spaces in filename

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 24, 2010, 01:06 UTC
Message-ID
<20100724010618.GA13670@burratino>

The goal: let ‘git apply’ handle such filenames as “b/debian/licenses/LICENSE.Apache (v2.0)” in patches produced by non-git tools without erroring out.

When we last left our heroes[1] in April:
Show 5 quoted lines
> | The name and last modification time of each file shall be output in
> | the following format:
> |
> | "---[space]%s  %s%s%s", file1, <file1 timestamp>, <file1 frac>, <file1 zone>
> | "+++[space]%s  %s%s%s", file2, <file2 timestamp>, <file2 frac>, <file2 zone>
[...]
> If this is really describing the format of patches in the wild, that
> means we should only look for a tab character to terminate the filename.
[...]
Show 5 quoted lines
> A big downside: this does not cope with copy-and-pasted patches with
> tabs transformed to spaces.  The example [2] consists mostly of
> file-creation patches, so we can’t look to the repository for hints.
> Maybe the space-plus-date-plus-newline sequence should be used as a
> delimiter.

It turns out that is not so hard. Maybe it could be rewritten using regcomp() and regexec(); if someone wants to do that, I won’t stop them. ;-)

Patch 1 factors out a function to handle "GNU-format" C-style quoted filenames in patches. The only tool I know of that produces this format is git; the discussion in [2] about what characters to escape seems to have come to no conclusion.

Patch 2 adds some tests for all those weird characters that might appear in a filename. They abuse “diff” and “pr”; testing on weird platforms would be helpful.

Patch 3 adds the logic to search for a date at the end of a filename line, for traditional (non --git) patches only. If no date is found at the end, we return to the previous heuristic, except that the only accepted filename terminator is a tab. Whitespace damage is only accepted if there is a timestamp at the end of the line.

Thoughts, suggestions, improvements welcome.
Jonathan Nieder (3):
  apply: Split quoted filename handling into new function
  tests: Test how well “git apply” copes with weird filenames
  apply: Handle traditional patches with space in filename
 builtin/apply.c                  |  251 ++++++++++++++++++++++++++++++++------
 t/t4120-apply-popt.sh            |   35 +++++-
 t/t4135-apply-weird-filenames.sh |  119 ++++++++++++++++++
 3 files changed, 363 insertions(+), 42 deletions(-)
 create mode 100755 t/t4135-apply-weird-filenames.sh

[1] http://thread.gmane.org/gmane.linux.debian.devel.bugs.general/697969/focus=145543 [2] http://thread.gmane.org/gmane.comp.version-control.git/9813/focus=10046

Next: Jonathan Nieder
Message 1 of 6 in “apply: handle traditional patches with spaces in filename”
  1. 0/3 apply: handle traditional patches with spaces in filenameJonathan Nieder, Jul 24, 2010
  2. 1/3 apply: Split quoted filename handling into new functionJonathan Nieder, Jul 24, 2010
  3. 2/3 tests: Test how well "git apply" copes with weird filenamesJonathan Nieder, Jul 24, 2010
  4. Andreas SchwabJul 24, 2010
  5. Jonathan NiederJul 24, 2010
  6. 3/3 apply: Handle traditional patches with space in filenameJonathan Nieder, Jul 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.