Smudge the files fed to external diff and textconv
When preparing temporary files for an external diff or textconv, it is easier on the external tools, especially when they are implemented using platform tools, if they are fed the input after convert_to_working_tree(). This fixes msysGit issue 177. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Mar 21, 2009 at 12:42 UTC
4e218f54b3de6aa8ef7d15020c4507031a519f7d
2 files changed
+26
-3
diff.c
+10
-3
@@ -1948,17 +1948,23 @@ void diff_free_filespec_data(struct diff_filespec *s)
1948
s->cnt_data = NULL;
1949
}
1950
1951
-static void prep_temp_blob(struct diff_tempfile *temp,
1951
+static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
1952
void *blob,
1953
unsigned long size,
1954
const unsigned char *sha1,
1955
int mode)
1956
{
1957
int fd;
1958
+ struct strbuf buf = STRBUF_INIT;
1959
1960
fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
1961
if (fd < 0)
1962
die("unable to create temp-file: %s", strerror(errno));
1963
+ if (convert_to_working_tree(path,
1964
+ (const char *)blob, (size_t)size, &buf)) {
1965
+ blob = buf.buf;
1966
+ size = buf.len;
1967
+ }
1968
if (write_in_full(fd, blob, size) != size)
1969
die("unable to write temp-file");
1970
close(fd);
@@ -1966,6 +1972,7 @@ static void prep_temp_blob(struct diff_tempfile *temp,
1972
strcpy(temp->hex, sha1_to_hex(sha1));
1973
temp->hex[40] = 0;
1974
sprintf(temp->mode, "%06o", mode);
1975
+ strbuf_release(&buf);
1976
}
1977
1978
static struct diff_tempfile *prepare_temp_file(const char *name,
@@ -2006,7 +2013,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2013
die("readlink(%s)", name);
2014
if (ret == sizeof(buf))
2015
die("symlink too long: %s", name);
2009
- prep_temp_blob(temp, buf, ret,
2016
+ prep_temp_blob(name, temp, buf, ret,
2017
(one->sha1_valid ?
2018
one->sha1 : null_sha1),
2019
(one->sha1_valid ?
@@ -2032,7 +2039,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2039
else {
2040
if (diff_populate_filespec(one, 0))
2041
die("cannot read data blob for %s", one->path);
2035
- prep_temp_blob(temp, one->data, one->size,
2042
+ prep_temp_blob(name, temp, one->data, one->size,
2043
one->sha1, one->mode);
2044
}
2045
return temp;
t/t4020-diff-external.sh
+16
@@ -136,4 +136,20 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
136
GIT_EXTERNAL_DIFF=echo git diff
137
'
138
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
+
155
test_done