@ -1948,17 +1948,23 @@ void diff_free_filespec_data(struct diff_filespec *s)
s->cnt_data = NULL;
s->cnt_data = NULL;
}
}
static void prep_temp_blob(struct diff_tempfile *temp,
static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
void *blob,
void *blob,
unsigned long size,
unsigned long size,
const unsigned char *sha1,
const unsigned char *sha1,
int mode)
int mode)
{
{
int fd;
int fd;
struct strbuf buf = STRBUF_INIT;
fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
if (fd < 0)
if (fd < 0)
die("unable to create temp-file: %s", strerror(errno));
die("unable to create temp-file: %s", strerror(errno));
if (convert_to_working_tree(path,
(const char *)blob, (size_t)size, &buf)) {
blob = buf.buf;
size = buf.len;
}
if (write_in_full(fd, blob, size) != size)
if (write_in_full(fd, blob, size) != size)
die("unable to write temp-file");
die("unable to write temp-file");
close(fd);
close(fd);
@ -1966,6 +1972,7 @@ static void prep_temp_blob(struct diff_tempfile *temp,
strcpy(temp->hex, sha1_to_hex(sha1));
strcpy(temp->hex, sha1_to_hex(sha1));
temp->hex[40] = 0;
temp->hex[40] = 0;
sprintf(temp->mode, "%06o", mode);
sprintf(temp->mode, "%06o", mode);
strbuf_release(&buf);
}
}
static struct diff_tempfile *prepare_temp_file(const char *name,
static struct diff_tempfile *prepare_temp_file(const char *name,
@ -2006,7 +2013,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
die("readlink(%s)", name);
die("readlink(%s)", name);
if (ret == sizeof(buf))
if (ret == sizeof(buf))
die("symlink too long: %s", name);
die("symlink too long: %s", name);
prep_temp_blob(temp, buf, ret,
prep_temp_blob(name, temp, buf, ret,
(one->sha1_valid ?
(one->sha1_valid ?
one->sha1 : null_sha1),
one->sha1 : null_sha1),
(one->sha1_valid ?
(one->sha1_valid ?
@ -2032,7 +2039,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
else {
else {
if (diff_populate_filespec(one, 0))
if (diff_populate_filespec(one, 0))
die("cannot read data blob for %s", one->path);
die("cannot read data blob for %s", one->path);
prep_temp_blob(temp, one->data, one->size,
prep_temp_blob(name, temp, one->data, one->size,
one->sha1, one->mode);
one->sha1, one->mode);
}
}
return temp;
return temp;