Skip to content

Commit b71fdc5

Browse files
committed
Merge branch 'js/maint-diff-temp-smudge'
* js/maint-diff-temp-smudge: Smudge the files fed to external diff and textconv
2 parents b2aa958 + 4e218f5 commit b71fdc5

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

diff.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,24 +1946,31 @@ void diff_free_filespec_data(struct diff_filespec *s)
19461946
s->cnt_data = NULL;
19471947
}
19481948

1949-
static void prep_temp_blob(struct diff_tempfile *temp,
1949+
static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
19501950
void *blob,
19511951
unsigned long size,
19521952
const unsigned char *sha1,
19531953
int mode)
19541954
{
19551955
int fd;
1956+
struct strbuf buf = STRBUF_INIT;
19561957

19571958
fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
19581959
if (fd < 0)
19591960
die("unable to create temp-file: %s", strerror(errno));
1961+
if (convert_to_working_tree(path,
1962+
(const char *)blob, (size_t)size, &buf)) {
1963+
blob = buf.buf;
1964+
size = buf.len;
1965+
}
19601966
if (write_in_full(fd, blob, size) != size)
19611967
die("unable to write temp-file");
19621968
close(fd);
19631969
temp->name = temp->tmp_path;
19641970
strcpy(temp->hex, sha1_to_hex(sha1));
19651971
temp->hex[40] = 0;
19661972
sprintf(temp->mode, "%06o", mode);
1973+
strbuf_release(&buf);
19671974
}
19681975

19691976
static struct diff_tempfile *prepare_temp_file(const char *name,
@@ -2004,7 +2011,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
20042011
die("readlink(%s)", name);
20052012
if (ret == sizeof(buf))
20062013
die("symlink too long: %s", name);
2007-
prep_temp_blob(temp, buf, ret,
2014+
prep_temp_blob(name, temp, buf, ret,
20082015
(one->sha1_valid ?
20092016
one->sha1 : null_sha1),
20102017
(one->sha1_valid ?
@@ -2030,7 +2037,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
20302037
else {
20312038
if (diff_populate_filespec(one, 0))
20322039
die("cannot read data blob for %s", one->path);
2033-
prep_temp_blob(temp, one->data, one->size,
2040+
prep_temp_blob(name, temp, one->data, one->size,
20342041
one->sha1, one->mode);
20352042
}
20362043
return temp;

t/t4020-diff-external.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,20 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
136136
GIT_EXTERNAL_DIFF=echo git diff
137137
'
138138

139+
echo "#!$SHELL_PATH" >fake-diff.sh
140+
cat >> fake-diff.sh <<\EOF
141+
cat $2 >> crlfed.txt
142+
EOF
143+
chmod a+x fake-diff.sh
144+
145+
keep_only_cr () {
146+
tr -dc '\015'
147+
}
148+
149+
test_expect_success 'external diff with autocrlf = true' '
150+
git config core.autocrlf true &&
151+
GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
152+
test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
153+
'
154+
139155
test_done

0 commit comments

Comments
 (0)