{"thread":{"id":"828","subject":"[PATCH] diffcore-break.c: various fixes.","startedAt":"2005-06-04T06:05:57Z","lastAt":"2005-06-05T20:40:47Z","messageCount":2,"participants":["Junio C Hamano","Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4528","messageId":"7vwtpairlm.fsf@assigned-by-dhcp.cox.net","threadId":"828","inReplyTo":null,"subject":"[PATCH] diffcore-break.c: various fixes.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-06-04T06:05:57Z","receivedAt":"2005-06-04T06:05:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This fixes three bugs in the -B heuristics.\n\n - Although it was advertised that the initial break criteria\n   used was the same as what diffcore-rename uses, it was using\n   something different.  Instead of using smaller of src and dst\n   size to compare with \"edit\" size, (insertion and deletion),\n   it was using larger of src and dst, unlike the rename/copy\n   detection logic.  This caused the parameter to -B to mean\n   something different from the one to -M and -C.  To compensate\n   for this change, the default break score is also changed to\n   match that of the default for rename/copy.\n\n - The code would have crashed with division by zero when trying\n   to break an originally empty file.\n\n - Contrary to what the comment said, the algorithm was breaking\n   small files, only to later merge them together.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n diffcore.h       |    2 +-\n diffcore-break.c |   22 ++++++++--------------\n 2 files changed, 9 insertions(+), 15 deletions(-)\n\ndiff --git a/diffcore.h b/diffcore.h\n--- a/diffcore.h\n+++ b/diffcore.h\n@@ -17,7 +17,7 @@\n  */\n #define MAX_SCORE 60000\n #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */\n-#define DEFAULT_BREAK_SCORE  59400 /* minimum for break to happen (99%)*/\n+#define DEFAULT_BREAK_SCORE  30000 /* minimum for break to happen (50%)*/\n #define DEFAULT_MERGE_SCORE  48000 /* maximum for break-merge to happen (80%)*/\n \n #define MINIMUM_BREAK_SIZE     400 /* do not break a file smaller than this */\ndiff --git a/diffcore-break.c b/diffcore-break.c\n--- a/diffcore-break.c\n+++ b/diffcore-break.c\n@@ -61,14 +61,7 @@ static int should_break(struct diff_file\n \tif (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))\n \t\treturn 0; /* error but caught downstream */\n \n-\tdelta_size = ((src->size < dst->size) ?\n-\t\t      (dst->size - src->size) : (src->size - dst->size));\n-\n-\t/* Notice that we use max of src and dst as the base size,\n-\t * unlike rename similarity detection.  This is so that we do\n-\t * not mistake a large addition as a complete rewrite.\n-\t */\n-\tbase_size = ((src->size < dst->size) ? dst->size : src->size);\n+\tbase_size = ((src->size < dst->size) ? src->size : dst->size);\n \n \tdelta = diff_delta(src->data, src->size,\n \t\t\t   dst->data, dst->size,\n@@ -88,10 +81,11 @@ static int should_break(struct diff_file\n \t * less than the minimum, after rename/copy runs.\n \t */\n \tif (src->size <= src_copied)\n-\t\tdelta_size = 0; /* avoid wrapping around */\n-\telse\n+\t\t; /* all copied, nothing removed */\n+\telse {\n \t\tdelta_size = src->size - src_copied;\n-\t*merge_score_p = delta_size * MAX_SCORE / src->size;\n+\t\t*merge_score_p = delta_size * MAX_SCORE / src->size;\n+\t}\n \t\n \t/* Extent of damage, which counts both inserts and\n \t * deletes.\n@@ -174,7 +168,8 @@ void diffcore_break(int break_score)\n \t\t    !S_ISDIR(p->one->mode) && !S_ISDIR(p->two->mode) &&\n \t\t    !strcmp(p->one->path, p->two->path)) {\n \t\t\tif (should_break(p->one, p->two,\n-\t\t\t\t\t break_score, &score)) {\n+\t\t\t\t\t break_score, &score) &&\n+\t\t\t    MINIMUM_BREAK_SIZE <= p->one->size) {\n \t\t\t\t/* Split this into delete and create */\n \t\t\t\tstruct diff_filespec *null_one, *null_two;\n \t\t\t\tstruct diff_filepair *dp;\n@@ -185,8 +180,7 @@ void diffcore_break(int break_score)\n \t\t\t\t * Also we do not want to break very\n \t\t\t\t * small files.\n \t\t\t\t */\n-\t\t\t\tif ((score < merge_score) ||\n-\t\t\t\t    (p->one->size < MINIMUM_BREAK_SIZE))\n+\t\t\t\tif (score < merge_score)\n \t\t\t\t\tscore = 0;\n \n \t\t\t\t/* deletion of one */\n------------\n\n"},{"id":"4604","messageId":"20050605204047.GQ17462@pasky.ji.cz","threadId":"828","inReplyTo":"7vwtpairlm.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] diff.c: locate_size_cache() fix.","fromName":"Petr Baudis","fromEmail":"pasky@ucw.cz","sentAt":"2005-06-05T20:40:47Z","receivedAt":"2005-06-05T20:40:47Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"> This fixes two bugs.\n> \n>  - declaration of auto variable \"cmp\" was preceeded by a\n>    statement, causing compilation error on real C compilers;\n>    noticed and patch given by Yoichi Yuasa.\n> \n>  - the function's calling convention was overloading its size\n>    parameter to mean \"largest possible value means do not add\n>    entry\", which was a bad taste.  Brought up during a\n>    discussion with Peter Baudis.\n> \n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\n> This fixes a bug that was preventing non-default parameter to -B\n> option to be passed correctly; you could not give more than 50%\n> break score.\n> \n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\n> This fixes three bugs in the -B heuristics.\n> \n>  - Although it was advertised that the initial break criteria\n>    used was the same as what diffcore-rename uses, it was using\n>    something different.  Instead of using smaller of src and dst\n>    size to compare with \"edit\" size, (insertion and deletion),\n>    it was using larger of src and dst, unlike the rename/copy\n>    detection logic.  This caused the parameter to -B to mean\n>    something different from the one to -M and -C.  To compensate\n>    for this change, the default break score is also changed to\n>    match that of the default for rename/copy.\n> \n>  - The code would have crashed with division by zero when trying\n>    to break an originally empty file.\n> \n>  - Contrary to what the comment said, the algorithm was breaking\n>    small files, only to later merge them together.\n> \n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\n  Hello,\n\n  what's up with those three fixes? Were they pointed out to be wrong\nand thrown away in another thread, are they on hold or just dropped?\nShould I just apply them to git-pb?\n\n  Thanks,\n\n-- \n\t\t\t\tPetr \"Pasky\" Baudis\nStuff: http://pasky.or.cz/\nC++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor\n"}]}