Skip to content

Commit b58f23b

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Fix diff output take #4.
This implements the output format suggested by Linus in <[email protected]>, except the imaginary diff option is spelled "diff --git" with double dashes as suggested by Matthias Urlichs. Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bf0f910 commit b58f23b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

diff.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static void builtin_diff(const char *name,
8383
struct diff_tempfile *temp)
8484
{
8585
int i, next_at;
86-
const char *git_prefix = "# mode: ";
8786
const char *diff_cmd = "diff -L'%s%s' -L'%s%s'";
8887
const char *diff_arg = "'%s' '%s'||:"; /* "||:" is to return 0 */
8988
const char *input_name_sq[2];
@@ -123,15 +122,16 @@ static void builtin_diff(const char *name,
123122
next_at += snprintf(cmd+next_at, cmd_size-next_at,
124123
diff_arg, input_name_sq[0], input_name_sq[1]);
125124

125+
printf("diff --git a/%s b/%s\n", name, name);
126126
if (!path1[0][0])
127-
printf("%s. %s %s\n", git_prefix, temp[1].mode, name);
127+
printf("new file mode %s\n", temp[1].mode);
128128
else if (!path1[1][0])
129-
printf("%s%s . %s\n", git_prefix, temp[0].mode, name);
129+
printf("deleted file mode %s\n", temp[0].mode);
130130
else {
131-
if (strcmp(temp[0].mode, temp[1].mode))
132-
printf("%s%s %s %s\n", git_prefix,
133-
temp[0].mode, temp[1].mode, name);
134-
131+
if (strcmp(temp[0].mode, temp[1].mode)) {
132+
printf("old mode %s\n", temp[0].mode);
133+
printf("new mode %s\n", temp[1].mode);
134+
}
135135
if (strncmp(temp[0].mode, temp[1].mode, 3))
136136
/* we do not run diff between different kind
137137
* of objects.

t/t4000-diff-format.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ test_expect_success \
2626
'git-diff-files -p after editing work tree.' \
2727
'git-diff-files -p >current'
2828
cat >expected <<\EOF
29-
# mode: 100644 100755 path0
29+
diff --git a/path0 b/path0
30+
old mode 100644
31+
new mode 100755
3032
--- a/path0
3133
+++ b/path0
3234
@@ -1,3 +1,3 @@
3335
Line 1
3436
Line 2
3537
-line 3
3638
+Line 3
37-
# mode: 100755 . path1
39+
diff --git a/path1 b/path1
40+
deleted file mode 100755
3841
--- a/path1
3942
+++ /dev/null
4043
@@ -1,3 +0,0 @@

0 commit comments

Comments
 (0)