Skip to contentSkip to conversation

diff: generate prettier filenames when using GIT_EXTERNAL_DIFF

PATCH New David Aguilar 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 diff: generate prettier filenames when using GIT_EXTERNAL_DIFF

Naturally, prep_temp_blob() did not care about filenames. As a result, scripts that use GIT_EXTERNAL_DIFF ended up with filenames such as ".diff_XXXXXX".

This specializes the GIT_EXTERNAL_DIFF code to generate prettier filenames.

Diffing "name.ext" now generates "name.XXXX.ext". Diffing files with no extension now generates "name_XXXX".

---

This includes a mkstemps implementation for cross-platform use. The git_mkstemps() function was adapted from libguile's GPLv2 mkstemp.c.

The original patch depended on the non-portable mkstemps() BSD extension =(

 cache.h                  |    2 +
 diff.c                   |   55 ++++++++++++++++++++++++++++++++-----
 path.c                   |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 t/t4020-diff-external.sh |   18 ++++++++++++
 4 files changed, 134 insertions(+), 8 deletions(-)
cache.h +2 -0
index b8503ad..871c984 100644
@@ -614,6 +614,8 @@ extern int is_empty_blob_sha1(const unsigned char *sha1);
 
 int git_mkstemp(char *path, size_t n, const char *template);
 
+int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
+
 /*
  * NOTE NOTE NOTE!!
  *
diff.c +47 -8

96 lines not on this page · raw message

path.c +67 -0

79 lines not on this page · raw message

t/t4020-diff-external.sh +18 -0
index 0720001..a9fdcb0 100755
@@ -136,6 +136,24 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' '
 	GIT_EXTERNAL_DIFF=echo git diff
 '
 
+test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths with no ext' '
+	touch filenoext &&
+	git add filenoext &&
+	echo no extension > filenoext &&
+	GIT_EXTERNAL_DIFF=echo git diff filenoext | grep filenoext_ &&
+	git update-index --force-remove filenoext &&
+	rm filenoext
+'
+
+test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths with ext' '
+	touch file.ext &&
+	git add file.ext &&
+	echo with extension > file.ext &&
+	GIT_EXTERNAL_DIFF=echo git diff file.ext | grep file\.......\.ext &&
+	git update-index --force-remove file.ext &&
+	rm file.ext
+'
+
 echo "#!$SHELL_PATH" >fake-diff.sh
 cat >> fake-diff.sh <<\EOF
 cat $2 >> crlfed.txt
Signature · 1 line
1.6.3.1.153.g6540