Merge branch 'jk/ext-diff-with-relative' into maint-2.39
"git diff --relative" did not mix well with "git diff --ext-diff", which has been corrected. * jk/ext-diff-with-relative: diff: drop "name" parameter from prepare_temp_file() diff: clean up external-diff argv setup diff: use filespec path to set up tempfiles for ext-diff
This commit is contained in:
commit
f8382a6396
30
diff.c
30
diff.c
@ -4213,7 +4213,6 @@ static void prep_temp_blob(struct index_state *istate,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
||||||
const char *name,
|
|
||||||
struct diff_filespec *one)
|
struct diff_filespec *one)
|
||||||
{
|
{
|
||||||
struct diff_tempfile *temp = claim_diff_tempfile();
|
struct diff_tempfile *temp = claim_diff_tempfile();
|
||||||
@ -4231,18 +4230,18 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
|||||||
|
|
||||||
if (!S_ISGITLINK(one->mode) &&
|
if (!S_ISGITLINK(one->mode) &&
|
||||||
(!one->oid_valid ||
|
(!one->oid_valid ||
|
||||||
reuse_worktree_file(r->index, name, &one->oid, 1))) {
|
reuse_worktree_file(r->index, one->path, &one->oid, 1))) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(name, &st) < 0) {
|
if (lstat(one->path, &st) < 0) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
goto not_a_valid_file;
|
goto not_a_valid_file;
|
||||||
die_errno("stat(%s)", name);
|
die_errno("stat(%s)", one->path);
|
||||||
}
|
}
|
||||||
if (S_ISLNK(st.st_mode)) {
|
if (S_ISLNK(st.st_mode)) {
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
if (strbuf_readlink(&sb, name, st.st_size) < 0)
|
if (strbuf_readlink(&sb, one->path, st.st_size) < 0)
|
||||||
die_errno("readlink(%s)", name);
|
die_errno("readlink(%s)", one->path);
|
||||||
prep_temp_blob(r->index, name, temp, sb.buf, sb.len,
|
prep_temp_blob(r->index, one->path, temp, sb.buf, sb.len,
|
||||||
(one->oid_valid ?
|
(one->oid_valid ?
|
||||||
&one->oid : null_oid()),
|
&one->oid : null_oid()),
|
||||||
(one->oid_valid ?
|
(one->oid_valid ?
|
||||||
@ -4251,7 +4250,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* we can borrow from the file in the work tree */
|
/* we can borrow from the file in the work tree */
|
||||||
temp->name = name;
|
temp->name = one->path;
|
||||||
if (!one->oid_valid)
|
if (!one->oid_valid)
|
||||||
oid_to_hex_r(temp->hex, null_oid());
|
oid_to_hex_r(temp->hex, null_oid());
|
||||||
else
|
else
|
||||||
@ -4269,7 +4268,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
|||||||
else {
|
else {
|
||||||
if (diff_populate_filespec(r, one, NULL))
|
if (diff_populate_filespec(r, one, NULL))
|
||||||
die("cannot read data blob for %s", one->path);
|
die("cannot read data blob for %s", one->path);
|
||||||
prep_temp_blob(r->index, name, temp,
|
prep_temp_blob(r->index, one->path, temp,
|
||||||
one->data, one->size,
|
one->data, one->size,
|
||||||
&one->oid, one->mode);
|
&one->oid, one->mode);
|
||||||
}
|
}
|
||||||
@ -4278,10 +4277,9 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
|
|||||||
|
|
||||||
static void add_external_diff_name(struct repository *r,
|
static void add_external_diff_name(struct repository *r,
|
||||||
struct strvec *argv,
|
struct strvec *argv,
|
||||||
const char *name,
|
|
||||||
struct diff_filespec *df)
|
struct diff_filespec *df)
|
||||||
{
|
{
|
||||||
struct diff_tempfile *temp = prepare_temp_file(r, name, df);
|
struct diff_tempfile *temp = prepare_temp_file(r, df);
|
||||||
strvec_push(argv, temp->name);
|
strvec_push(argv, temp->name);
|
||||||
strvec_push(argv, temp->hex);
|
strvec_push(argv, temp->hex);
|
||||||
strvec_push(argv, temp->mode);
|
strvec_push(argv, temp->mode);
|
||||||
@ -4308,11 +4306,9 @@ static void run_external_diff(const char *pgm,
|
|||||||
strvec_push(&cmd.args, name);
|
strvec_push(&cmd.args, name);
|
||||||
|
|
||||||
if (one && two) {
|
if (one && two) {
|
||||||
add_external_diff_name(o->repo, &cmd.args, name, one);
|
add_external_diff_name(o->repo, &cmd.args, one);
|
||||||
if (!other)
|
add_external_diff_name(o->repo, &cmd.args, two);
|
||||||
add_external_diff_name(o->repo, &cmd.args, name, two);
|
if (other) {
|
||||||
else {
|
|
||||||
add_external_diff_name(o->repo, &cmd.args, other, two);
|
|
||||||
strvec_push(&cmd.args, other);
|
strvec_push(&cmd.args, other);
|
||||||
strvec_push(&cmd.args, xfrm_msg);
|
strvec_push(&cmd.args, xfrm_msg);
|
||||||
}
|
}
|
||||||
@ -7037,7 +7033,7 @@ static char *run_textconv(struct repository *r,
|
|||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
temp = prepare_temp_file(r, spec->path, spec);
|
temp = prepare_temp_file(r, spec);
|
||||||
strvec_push(&child.args, pgm);
|
strvec_push(&child.args, pgm);
|
||||||
strvec_push(&child.args, temp->name);
|
strvec_push(&child.args, temp->name);
|
||||||
|
|
||||||
|
@ -162,6 +162,35 @@ check_diff_relative_option subdir file2 true --no-relative --relative
|
|||||||
check_diff_relative_option . file2 false --no-relative --relative=subdir
|
check_diff_relative_option . file2 false --no-relative --relative=subdir
|
||||||
check_diff_relative_option . file2 true --no-relative --relative=subdir
|
check_diff_relative_option . file2 true --no-relative --relative=subdir
|
||||||
|
|
||||||
|
test_expect_success 'external diff with --relative' '
|
||||||
|
test_when_finished "git reset --hard" &&
|
||||||
|
echo changed >file1 &&
|
||||||
|
echo changed >subdir/file2 &&
|
||||||
|
|
||||||
|
write_script mydiff <<-\EOF &&
|
||||||
|
# hacky pretend diff; the goal here is just to make sure we got
|
||||||
|
# passed sensible input that we _could_ diff, without relying on
|
||||||
|
# the specific output of a system diff tool.
|
||||||
|
echo "diff a/$1 b/$1" &&
|
||||||
|
echo "--- a/$1" &&
|
||||||
|
echo "+++ b/$1" &&
|
||||||
|
echo "@@ -1 +0,0 @@" &&
|
||||||
|
sed "s/^/-/" "$2" &&
|
||||||
|
sed "s/^/+/" "$5"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
diff a/file2 b/file2
|
||||||
|
--- a/file2
|
||||||
|
+++ b/file2
|
||||||
|
@@ -1 +0,0 @@
|
||||||
|
-other content
|
||||||
|
+changed
|
||||||
|
EOF
|
||||||
|
GIT_EXTERNAL_DIFF=./mydiff git diff --relative=subdir >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'setup diff --relative unmerged' '
|
test_expect_success 'setup diff --relative unmerged' '
|
||||||
test_commit zero file0 &&
|
test_commit zero file0 &&
|
||||||
test_commit base subdir/file0 &&
|
test_commit base subdir/file0 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user