Skip to content

Commit 70aadac

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] Show dissimilarity index for D and N case.
The way broken deletes and creates are shown in the -p (diff-patch) output format has become consistent with how rename/copy edits are shown. They will show "dissimilarity index" value, immediately following the "deleted file mode" and "new file mode" lines. The git-apply is taught to grok such an extended header. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent af5323e commit 70aadac

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

apply.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ static int gitdiff_similarity(const char *line, struct patch *patch)
336336
return 0;
337337
}
338338

339+
static int gitdiff_dissimilarity(const char *line, struct patch *patch)
340+
{
341+
return 0;
342+
}
343+
339344
/*
340345
* This is normal for a diff that doesn't change anything: we'll fall through
341346
* into the next diff. Tell the parser to break out.
@@ -437,6 +442,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch
437442
{ "rename from ", gitdiff_renamesrc },
438443
{ "rename to ", gitdiff_renamedst },
439444
{ "similarity index ", gitdiff_similarity },
445+
{ "dissimilarity index ", gitdiff_dissimilarity },
440446
{ "", gitdiff_unrecognized },
441447
};
442448
int i;

diff.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,16 @@ static void builtin_diff(const char *name_a,
132132
diff_arg, input_name_sq[0], input_name_sq[1]);
133133

134134
printf("diff --git a/%s b/%s\n", name_a, name_b);
135-
if (!path1[0][0])
135+
if (!path1[0][0]) {
136136
printf("new file mode %s\n", temp[1].mode);
137-
else if (!path1[1][0])
137+
if (xfrm_msg && xfrm_msg[0])
138+
puts(xfrm_msg);
139+
}
140+
else if (!path1[1][0]) {
138141
printf("deleted file mode %s\n", temp[0].mode);
142+
if (xfrm_msg && xfrm_msg[0])
143+
puts(xfrm_msg);
144+
}
139145
else {
140146
if (strcmp(temp[0].mode, temp[1].mode)) {
141147
printf("old mode %s\n", temp[0].mode);
@@ -733,6 +739,16 @@ static void diff_flush_patch(struct diff_filepair *p)
733739
p->one->path, p->two->path);
734740
msg = msg_;
735741
break;
742+
case 'D': case 'N':
743+
if (DIFF_PAIR_BROKEN(p)) {
744+
sprintf(msg_,
745+
"dissimilarity index %d%%",
746+
(int)(0.5 + p->score * 100.0/MAX_SCORE));
747+
msg = msg_;
748+
}
749+
else
750+
msg = NULL;
751+
break;
736752
default:
737753
msg = NULL;
738754
}

0 commit comments

Comments
 (0)