{"thread":{"id":"772","subject":"[PATCH] Show dissimilarity index for D and N case.","startedAt":"2005-05-30T23:40:16Z","lastAt":"2005-05-30T23:40:16Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4280","messageId":"7v1x7oz3j3.fsf@assigned-by-dhcp.cox.net","threadId":"772","inReplyTo":null,"subject":"[PATCH] Show dissimilarity index for D and N case.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-30T23:40:16Z","receivedAt":"2005-05-30T23:40:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The way broken deletes and creates are shown in the -p\n(diff-patch) output format has become consistent with how\nrename/copy edits are shown.  They will show \"dissimilarity\nindex\" value, immediately following the \"deleted file mode\" and\n\"new file mode\" lines.\n\nThe git-apply is taught to grok such an extended header.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n apply.c |    6 ++++++\n diff.c  |   20 ++++++++++++++++++--\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/apply.c b/apply.c\n--- a/apply.c\n+++ b/apply.c\n@@ -336,6 +336,11 @@ static int gitdiff_similarity(const char\n \treturn 0;\n }\n \n+static int gitdiff_dissimilarity(const char *line, struct patch *patch)\n+{\n+\treturn 0;\n+}\n+\n /*\n  * This is normal for a diff that doesn't change anything: we'll fall through\n  * into the next diff. Tell the parser to break out.\n@@ -437,6 +442,7 @@ static int parse_git_header(char *line, \n \t\t\t{ \"rename from \", gitdiff_renamesrc },\n \t\t\t{ \"rename to \", gitdiff_renamedst },\n \t\t\t{ \"similarity index \", gitdiff_similarity },\n+\t\t\t{ \"dissimilarity index \", gitdiff_dissimilarity },\n \t\t\t{ \"\", gitdiff_unrecognized },\n \t\t};\n \t\tint i;\ndiff --git a/diff.c b/diff.c\n--- a/diff.c\n+++ b/diff.c\n@@ -132,10 +132,16 @@ static void builtin_diff(const char *nam\n \t\t\t    diff_arg, input_name_sq[0], input_name_sq[1]);\n \n \tprintf(\"diff --git a/%s b/%s\\n\", name_a, name_b);\n-\tif (!path1[0][0])\n+\tif (!path1[0][0]) {\n \t\tprintf(\"new file mode %s\\n\", temp[1].mode);\n-\telse if (!path1[1][0])\n+\t\tif (xfrm_msg && xfrm_msg[0])\n+\t\t\tputs(xfrm_msg);\n+\t}\n+\telse if (!path1[1][0]) {\n \t\tprintf(\"deleted file mode %s\\n\", temp[0].mode);\n+\t\tif (xfrm_msg && xfrm_msg[0])\n+\t\t\tputs(xfrm_msg);\n+\t}\n \telse {\n \t\tif (strcmp(temp[0].mode, temp[1].mode)) {\n \t\t\tprintf(\"old mode %s\\n\", temp[0].mode);\n@@ -733,6 +739,16 @@ static void diff_flush_patch(struct diff\n \t\t\tp->one->path, p->two->path);\n \t\tmsg = msg_;\n \t\tbreak;\n+\tcase 'D': case 'N':\n+\t\tif (DIFF_PAIR_BROKEN(p)) {\n+\t\t\tsprintf(msg_,\n+\t\t\t\t\"dissimilarity index %d%%\",\n+\t\t\t\t(int)(0.5 + p->score * 100.0/MAX_SCORE));\n+\t\t\tmsg = msg_;\n+\t\t}\n+\t\telse\n+\t\t\tmsg = NULL;\n+\t\tbreak;\n \tdefault:\n \t\tmsg = NULL;\n \t}\n------------\n\n"}]}