diff options
author | Andreas Gruenbacher <agruen@linbit.com> | 2012-08-11 11:09:11 +0200 |
---|---|---|
committer | Andreas Gruenbacher <agruen@linbit.com> | 2012-08-11 11:09:11 +0200 |
commit | 66aeedee12d621113fe0906b7cbd124cc4e9ebd5 (patch) | |
tree | bf849e2ff9d3241e090d2df13929ed37f5f3c4fe | |
parent | 9a37354cc6e56a18e297087a861ee7435e7fb9c6 (diff) | |
download | patch-66aeedee12d621113fe0906b7cbd124cc4e9ebd5.tar.gz |
Support double-quoted filenames in all context diff formats
* src/util.c (fetchname): Always recognize double-quoted filenames.
* src/util.h (fetchname): Update prototype.
* src/pch.c (intuit_diff_type): Update calls to fetchname().
* tests/quoted-filenames: Change to a normal unified diff.
* NEWS: Update.
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | src/pch.c | 8 | ||||
-rw-r--r-- | src/util.c | 4 | ||||
-rw-r--r-- | src/util.h | 2 | ||||
-rw-r--r-- | tests/quoted-filenames | 6 |
5 files changed, 15 insertions, 13 deletions
@@ -4,10 +4,10 @@ * Support for most features of the "diff --git" format, including renames and copies, permission changes, and symlink diffs. Binary diffs are not supported yet; patch will complain and skip them. -* Support for double-quoted filenames in the "diff --git" format: when a - filename starts with a double quote, it is interpreted as a C string literal. - The escape sequences \\, \", \a, \b, \f, \n, \r, \t, \v, and \ooo (a - three-digit octal number between 0 and 255) are recognized. +* Support for double-quoted filenames: when a filename starts with a double + quote, it is interpreted as a C string literal. The escape sequences \\, \", + \a, \b, \f, \n, \r, \t, \v, and \ooo (a three-digit octal number between 0 + and 255) are recognized. * Refuse to apply a normal patch to a symlink. (Previous versions of patch were replacing the symlink with a regular file.) * When trying to modify a read-only file, warn about the potential problem @@ -556,21 +556,21 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) } if (!stars_last_line && strnEQ(s, "*** ", 4)) { - fetchname (s+4, strippath, p_git_diff, &p_name[OLD], &p_timestr[OLD], + fetchname (s+4, strippath, &p_name[OLD], &p_timestr[OLD], &p_timestamp[OLD]); need_header = false; } else if (strnEQ(s, "+++ ", 4)) { /* Swap with NEW below. */ - fetchname (s+4, strippath, p_git_diff, &p_name[OLD], &p_timestr[OLD], + fetchname (s+4, strippath, &p_name[OLD], &p_timestr[OLD], &p_timestamp[OLD]); need_header = false; p_strip_trailing_cr = strip_trailing_cr; } else if (strnEQ(s, "Index:", 6)) { - fetchname (s+6, strippath, p_git_diff, &p_name[INDEX], (char **) 0, NULL); + fetchname (s+6, strippath, &p_name[INDEX], (char **) 0, NULL); need_header = false; p_strip_trailing_cr = strip_trailing_cr; } @@ -713,7 +713,7 @@ intuit_diff_type (bool need_header, mode_t *p_file_type) { struct timespec timestamp; timestamp.tv_sec = -1; - fetchname (t+4, strippath, p_git_diff, &p_name[NEW], &p_timestr[NEW], + fetchname (t+4, strippath, &p_name[NEW], &p_timestr[NEW], ×tamp); need_header = false; if (timestamp.tv_sec != -1) @@ -1431,7 +1431,7 @@ strip_leading_slashes (char *name, int strip_leading) /* Make filenames more reasonable. */ void -fetchname (char const *at, int strip_leading, bool maybe_quoted, char **pname, +fetchname (char const *at, int strip_leading, char **pname, char **ptimestr, struct timespec *pstamp) { char *name; @@ -1447,7 +1447,7 @@ fetchname (char const *at, int strip_leading, bool maybe_quoted, char **pname, if (debug & 128) say ("fetchname %s %d\n", at, strip_leading); - if (maybe_quoted && *at == '"') + if (*at == '"') { name = parse_c_string (at, &t); if (! name) @@ -40,7 +40,7 @@ void fatal (char const *, ...) void pfatal (char const *, ...) __attribute__ ((noreturn, format (printf, 1, 2))); -void fetchname (char const *, int, bool, char **, char **, struct timespec *); +void fetchname (char const *, int, char **, char **, struct timespec *); char *parse_name (char const *, int, char const **); char *savebuf (char const *, size_t); char *savestr (char const *); diff --git a/tests/quoted-filenames b/tests/quoted-filenames index 92aae6c..5fb9f12 100644 --- a/tests/quoted-filenames +++ b/tests/quoted-filenames @@ -18,8 +18,6 @@ use_tmpdir # \ / : * ? " < > | cat > d.diff <<EOF -diff --git "\\t \\040" "\\t \\040" -index 5626abf..f719efd 100644 --- "\\t \\040" +++ "\\t \\040" @@ -1 +1 @@ @@ -29,3 +27,7 @@ EOF ncheck 'echo one > " "' ncheck 'patch -s -p0 < d.diff' + +check 'cat " "' <<EOF +two +EOF |