Merge branch 'jc/binary'
* jc/binary: diff --binary generates full index on binary files. Make apply --binary a no-op.
This commit is contained in:
commit
ae44b235d4
@ -110,15 +110,10 @@ OPTIONS
|
|||||||
deletion part but not addition part.
|
deletion part but not addition part.
|
||||||
|
|
||||||
--allow-binary-replacement, --binary::
|
--allow-binary-replacement, --binary::
|
||||||
When applying a patch, which is a git-enhanced patch
|
Historically we did not allow binary patch applied
|
||||||
that was prepared to record the pre- and post-image object
|
without an explicit permission from the user, and this
|
||||||
name in full, and the path being patched exactly matches
|
flag was the way to do so. Currently we always allow binary
|
||||||
the object the patch applies to (i.e. "index" line's
|
patch application, so this is a no-op.
|
||||||
pre-image object name is what is in the working tree),
|
|
||||||
and the post-image object is available in the object
|
|
||||||
database, use the post-image object as the patch
|
|
||||||
result. This allows binary files to be patched in a
|
|
||||||
very limited way.
|
|
||||||
|
|
||||||
--exclude=<path-pattern>::
|
--exclude=<path-pattern>::
|
||||||
Don't apply changes to files matching the given path pattern. This can
|
Don't apply changes to files matching the given path pattern. This can
|
||||||
|
@ -28,7 +28,6 @@ static int prefix_length = -1;
|
|||||||
static int newfd = -1;
|
static int newfd = -1;
|
||||||
|
|
||||||
static int p_value = 1;
|
static int p_value = 1;
|
||||||
static int allow_binary_replacement;
|
|
||||||
static int check_index;
|
static int check_index;
|
||||||
static int write_index;
|
static int write_index;
|
||||||
static int cached;
|
static int cached;
|
||||||
@ -1228,14 +1227,12 @@ static int parse_chunk(char *buffer, unsigned long size, struct patch *patch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Empty patch cannot be applied if:
|
/* Empty patch cannot be applied if it is a text patch
|
||||||
* - it is a binary patch and we do not do binary_replace, or
|
* without metadata change. A binary patch appears
|
||||||
* - text patch without metadata change
|
* empty to us here.
|
||||||
*/
|
*/
|
||||||
if ((apply || check) &&
|
if ((apply || check) &&
|
||||||
(patch->is_binary
|
(!patch->is_binary && !metadata_changes(patch)))
|
||||||
? !allow_binary_replacement
|
|
||||||
: !metadata_changes(patch)))
|
|
||||||
die("patch with only garbage at line %d", linenr);
|
die("patch with only garbage at line %d", linenr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1676,11 +1673,6 @@ static int apply_binary(struct buffer_desc *desc, struct patch *patch)
|
|||||||
unsigned char hdr[50];
|
unsigned char hdr[50];
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
|
||||||
if (!allow_binary_replacement)
|
|
||||||
return error("cannot apply binary patch to '%s' "
|
|
||||||
"without --allow-binary-replacement",
|
|
||||||
name);
|
|
||||||
|
|
||||||
/* For safety, we require patch index line to contain
|
/* For safety, we require patch index line to contain
|
||||||
* full 40-byte textual SHA1 for old and new, at least for now.
|
* full 40-byte textual SHA1 for old and new, at least for now.
|
||||||
*/
|
*/
|
||||||
@ -2497,8 +2489,7 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
if (!strcmp(arg, "--allow-binary-replacement") ||
|
if (!strcmp(arg, "--allow-binary-replacement") ||
|
||||||
!strcmp(arg, "--binary")) {
|
!strcmp(arg, "--binary")) {
|
||||||
allow_binary_replacement = 1;
|
continue; /* now no-op */
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "--numstat")) {
|
if (!strcmp(arg, "--numstat")) {
|
||||||
apply = 0;
|
apply = 0;
|
||||||
|
8
diff.c
8
diff.c
@ -1588,6 +1588,12 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o)
|
|||||||
if (hashcmp(one->sha1, two->sha1)) {
|
if (hashcmp(one->sha1, two->sha1)) {
|
||||||
int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
|
int abbrev = o->full_index ? 40 : DEFAULT_ABBREV;
|
||||||
|
|
||||||
|
if (o->binary) {
|
||||||
|
mmfile_t mf;
|
||||||
|
if ((!fill_mmfile(&mf, one) && mmfile_is_binary(&mf)) ||
|
||||||
|
(!fill_mmfile(&mf, two) && mmfile_is_binary(&mf)))
|
||||||
|
abbrev = 40;
|
||||||
|
}
|
||||||
len += snprintf(msg + len, sizeof(msg) - len,
|
len += snprintf(msg + len, sizeof(msg) - len,
|
||||||
"index %.*s..%.*s",
|
"index %.*s..%.*s",
|
||||||
abbrev, sha1_to_hex(one->sha1),
|
abbrev, sha1_to_hex(one->sha1),
|
||||||
@ -1818,7 +1824,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
options->full_index = 1;
|
options->full_index = 1;
|
||||||
else if (!strcmp(arg, "--binary")) {
|
else if (!strcmp(arg, "--binary")) {
|
||||||
options->output_format |= DIFF_FORMAT_PATCH;
|
options->output_format |= DIFF_FORMAT_PATCH;
|
||||||
options->full_index = options->binary = 1;
|
options->binary = 1;
|
||||||
}
|
}
|
||||||
else if (!strcmp(arg, "-a") || !strcmp(arg, "--text")) {
|
else if (!strcmp(arg, "-a") || !strcmp(arg, "--text")) {
|
||||||
options->text = 1;
|
options->text = 1;
|
||||||
|
@ -94,11 +94,11 @@ test_expect_failure 'apply binary diff (copy) -- should fail.' \
|
|||||||
'do_reset
|
'do_reset
|
||||||
git-apply --index C.diff'
|
git-apply --index C.diff'
|
||||||
|
|
||||||
test_expect_failure 'apply binary diff without replacement -- should fail.' \
|
test_expect_success 'apply binary diff without replacement.' \
|
||||||
'do_reset
|
'do_reset
|
||||||
git-apply BF.diff'
|
git-apply BF.diff'
|
||||||
|
|
||||||
test_expect_failure 'apply binary diff without replacement (copy) -- should fail.' \
|
test_expect_success 'apply binary diff without replacement (copy).' \
|
||||||
'do_reset
|
'do_reset
|
||||||
git-apply CF.diff'
|
git-apply CF.diff'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user