{"thread":{"id":"42468","subject":"[PATCH] Require 0 context lines in git-blame algorithm","startedAt":"2016-05-27T14:16:32Z","lastAt":"2016-05-27T20:59:03Z","messageCount":2,"participants":["David Kastrup","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"287679","messageId":"1464358592-5409-1-git-send-email-dak@gnu.org","threadId":"42468","inReplyTo":null,"subject":"[PATCH] Require 0 context lines in git-blame algorithm","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2016-05-27T14:16:32Z","receivedAt":"2016-05-27T14:16:32Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Previously, the core part of git blame -M required 1 context line.\nThere is no rationale to be found in the code (one guess would be that\nthe old blame algorithm was unable to deal with immediately adjacent\nregions), and it causes artifacts like discussed in the thread\n<URL:http://thread.gmane.org/gmane.comp.version-control.git/255289/>\n---\n builtin/blame.c | 7 +++----\n 1 file changed, 3 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 21f42b0..a3f6874 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -134,7 +134,7 @@ struct progress_info {\n \tint blamed_lines;\n };\n \n-static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n+static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,\n \t\t      xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)\n {\n \txpparam_t xpp = {0};\n@@ -142,7 +142,6 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n \txdemitcb_t ecb = {NULL};\n \n \txpp.flags = xdl_opts;\n-\txecfg.ctxlen = ctxlen;\n \txecfg.hunk_func = hunk_func;\n \tecb.priv = cb_data;\n \treturn xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);\n@@ -980,7 +979,7 @@ static void pass_blame_to_parent(struct scoreboard *sb,\n \tfill_origin_blob(&sb->revs->diffopt, target, &file_o);\n \tnum_get_patch++;\n \n-\tif (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))\n+\tif (diff_hunks(&file_p, &file_o, blame_chunk_cb, &d))\n \t\tdie(\"unable to generate diff (%s -> %s)\",\n \t\t    oid_to_hex(&parent->commit->object.oid),\n \t\t    oid_to_hex(&target->commit->object.oid));\n@@ -1129,7 +1128,7 @@ static void find_copy_in_blob(struct scoreboard *sb,\n \t * file_p partially may match that image.\n \t */\n \tmemset(split, 0, sizeof(struct blame_entry [3]));\n-\tif (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))\n+\tif (diff_hunks(file_p, &file_o, handle_split_cb, &d))\n \t\tdie(\"unable to generate diff (%s)\",\n \t\t    oid_to_hex(&parent->commit->object.oid));\n \t/* remainder, if any, all match the preimage */\n-- \n2.7.4\n"},{"id":"287716","messageId":"xmqqtwhjp694.fsf@gitster.mtv.corp.google.com","threadId":"42468","inReplyTo":"1464358592-5409-1-git-send-email-dak@gnu.org","subject":"Re: [PATCH] Require 0 context lines in git-blame algorithm","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-05-27T20:59:03Z","receivedAt":"2016-05-27T20:59:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Kastrup <dak@gnu.org> writes:\n\n> Previously, the core part of git blame -M required 1 context line.\n> There is no rationale to be found in the code (one guess would be that\n> the old blame algorithm was unable to deal with immediately adjacent\n> regions), and it causes artifacts like discussed in the thread\n> <URL:http://thread.gmane.org/gmane.comp.version-control.git/255289/>\n\nThe only thing that remotely hints why we thought a non-zero context\nwas a good idea was this:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/28336/focus=28580\n\nin which I said:\n\n | we may need to use a handful surrounding context lines for\n | better identification of copy source by the \"ciff\" algorithm but\n | that is a minor implementation detail.\n\nBut I do not think the amount of context affects the quality of the\nmatch.  So it could be that it was completely a misguided attempt\nsince the very beginning, cee7f245 (git-pickaxe: blame rewritten.,\n2006-10-19), which allowed the caller to specify context when\ncalling compare_buffer(), the function that corresponds to\ndiff_hunks() in today's code.\n\n> ---\n>  builtin/blame.c | 7 +++----\n>  1 file changed, 3 insertions(+), 4 deletions(-)\n\nI totally forgot about the discussion around $gmane/255289; thanks\nfor bringing this back again.\n\nAs usual, we'd need your sign-off to use this patch.\n\nThanks.\n\n\n> diff --git a/builtin/blame.c b/builtin/blame.c\n> index 21f42b0..a3f6874 100644\n> --- a/builtin/blame.c\n> +++ b/builtin/blame.c\n> @@ -134,7 +134,7 @@ struct progress_info {\n>  \tint blamed_lines;\n>  };\n>  \n> -static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n> +static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,\n>  \t\t      xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)\n>  {\n>  \txpparam_t xpp = {0};\n> @@ -142,7 +142,6 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,\n>  \txdemitcb_t ecb = {NULL};\n>  \n>  \txpp.flags = xdl_opts;\n> -\txecfg.ctxlen = ctxlen;\n>  \txecfg.hunk_func = hunk_func;\n>  \tecb.priv = cb_data;\n>  \treturn xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);\n> @@ -980,7 +979,7 @@ static void pass_blame_to_parent(struct scoreboard *sb,\n>  \tfill_origin_blob(&sb->revs->diffopt, target, &file_o);\n>  \tnum_get_patch++;\n>  \n> -\tif (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))\n> +\tif (diff_hunks(&file_p, &file_o, blame_chunk_cb, &d))\n>  \t\tdie(\"unable to generate diff (%s -> %s)\",\n>  \t\t    oid_to_hex(&parent->commit->object.oid),\n>  \t\t    oid_to_hex(&target->commit->object.oid));\n> @@ -1129,7 +1128,7 @@ static void find_copy_in_blob(struct scoreboard *sb,\n>  \t * file_p partially may match that image.\n>  \t */\n>  \tmemset(split, 0, sizeof(struct blame_entry [3]));\n> -\tif (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))\n> +\tif (diff_hunks(file_p, &file_o, handle_split_cb, &d))\n>  \t\tdie(\"unable to generate diff (%s)\",\n>  \t\t    oid_to_hex(&parent->commit->object.oid));\n>  \t/* remainder, if any, all match the preimage */\n"}]}