git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Guido Günther" <agx@sigxcpu.org>,
	"Giuseppe Iuculano" <iuculano@debian.org>
Subject: [PATCH 0/3] apply: handle traditional patches with spaces in filename
Date: Fri, 23 Jul 2010 20:06:18 -0500	[thread overview]
Message-ID: <20100724010618.GA13670@burratino> (raw)

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:

> | 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.
[...]
> 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

             reply	other threads:[~2010-07-24  1:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-24  1:06 Jonathan Nieder [this message]
2010-07-24  1:09 ` [PATCH 1/3] apply: Split quoted filename handling into new function Jonathan Nieder
2010-07-24  1:11 ` [PATCH 2/3] tests: Test how well "git apply" copes with weird filenames Jonathan Nieder
2010-07-24  8:03   ` Andreas Schwab
2010-07-24  8:48     ` Jonathan Nieder
2010-07-24  1:20 ` [PATCH 3/3] apply: Handle traditional patches with space in filename Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100724010618.GA13670@burratino \
    --to=jrnieder@gmail.com \
    --cc=agx@sigxcpu.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=iuculano@debian.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).