Skip to content

Commit 9fdade0

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Mode only changes from diff.
This fixes another bug. - Mode-only changes were pruned incorrectly from the output. - Added test to catch the above problem. - Normalize rename/copy similarity score in the diff-raw output to per-cent, no matter what scale we internally use. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 96716a1 commit 9fdade0

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

diff-helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "cache.h"
55
#include "strbuf.h"
66
#include "diff.h"
7+
#include "diffcore.h" /* just for MAX_SCORE */
78

89
static const char *pickaxe = NULL;
910
static int line_termination = '\n';
@@ -77,6 +78,7 @@ int main(int ac, const char **av) {
7778
if (status == 'R' || status == 'C') {
7879
two_paths = 1;
7980
sscanf(cp, "%d", &score);
81+
score = score * MAX_SCORE / 100;
8082
if (line_termination) {
8183
cp = strchr(cp,
8284
inter_name_termination);

diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ static void diff_flush_raw(struct diff_filepair *p,
517517
switch (p->status) {
518518
case 'C': case 'R':
519519
two_paths = 1;
520-
sprintf(status, "%c%1d", p->status, p->score);
520+
sprintf(status, "%c%03d", p->status,
521+
(int)(0.5 + p->score * 100.0/MAX_SCORE));
521522
break;
522523
default:
523524
two_paths = 0;
@@ -750,7 +751,8 @@ static void diff_resolve_rename_copy(void)
750751
if (!p->status)
751752
p->status = 'R';
752753
}
753-
else if (memcmp(p->one->sha1, p->two->sha1, 20))
754+
else if (memcmp(p->one->sha1, p->two->sha1, 20) ||
755+
p->one->mode != p->two->mode)
754756
p->status = 'M';
755757
else
756758
/* this is a "no-change" entry */

t/t4006-diff-mode.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2005 Junio C Hamano
4+
#
5+
6+
test_description='Test mode change diffs.
7+
8+
'
9+
. ./test-lib.sh
10+
11+
test_expect_success \
12+
'setup' \
13+
'echo frotz >rezrov &&
14+
git-update-cache --add rezrov &&
15+
tree=`git-write-tree` &&
16+
echo $tree'
17+
18+
test_expect_success \
19+
'chmod' \
20+
'chmod +x rezrov &&
21+
git-update-cache rezrov &&
22+
git-diff-cache $tree >current'
23+
24+
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
25+
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
26+
sed -e 's/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /' <current >check
27+
echo ":100644 100755 X X M rezrov" >expected
28+
29+
test_expect_success \
30+
'verify' \
31+
'diff -u expected check'
32+
33+
test_done
34+

0 commit comments

Comments
 (0)