summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2009-05-31 08:35:52 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-06-01 00:57:59 (GMT)
commit003b33a8ad686ee4a0d0b36635bfd6aba940b24a (patch)
treea4fb990bc62930d859f8343c41f5a3162aca6449 /diff.c
parente1c068869216c8c231c1585bbfa9fda42b4756f8 (diff)
downloadgit-003b33a8ad686ee4a0d0b36635bfd6aba940b24a.zip
git-003b33a8ad686ee4a0d0b36635bfd6aba940b24a.tar.gz
git-003b33a8ad686ee4a0d0b36635bfd6aba940b24a.tar.bz2
diff: generate pretty filenames in prep_temp_blob()
Naturally, prep_temp_blob() did not care about filenames. As a result, GIT_EXTERNAL_DIFF and textconv generated filenames such as ".diff_XXXXXX". This modifies prep_temp_blob() to generate user-friendly filenames when creating temporary files. Diffing "name.ext" now generates "XXXXXX_name.ext". Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index dcfbcb0..4d0a5b9 100644
--- a/diff.c
+++ b/diff.c
@@ -1964,8 +1964,16 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
{
int fd;
struct strbuf buf = STRBUF_INIT;
+ struct strbuf template = STRBUF_INIT;
+ char *path_dup = xstrdup(path);
+ const char *base = basename(path_dup);
- fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
+ /* Generate "XXXXXX_basename.ext" */
+ strbuf_addstr(&template, "XXXXXX_");
+ strbuf_addstr(&template, base);
+
+ fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf,
+ strlen(base) + 1);
if (fd < 0)
die("unable to create temp-file: %s", strerror(errno));
if (convert_to_working_tree(path,
@@ -1981,6 +1989,8 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
temp->hex[40] = 0;
sprintf(temp->mode, "%06o", mode);
strbuf_release(&buf);
+ strbuf_release(&template);
+ free(path_dup);
}
static struct diff_tempfile *prepare_temp_file(const char *name,