{"thread":{"id":"733","subject":"[PATCH] Fix git-deltafy-script off-by-one errors","startedAt":"2005-05-27T10:36:31Z","lastAt":"2005-05-27T10:36:31Z","messageCount":1,"participants":["Stephen Tweedie"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4042","messageId":"20050527103631.GA17730@devserv.devel.redhat.com","threadId":"733","inReplyTo":null,"subject":"[PATCH] Fix git-deltafy-script off-by-one errors","fromName":"Stephen Tweedie","fromEmail":"sct@redhat.com","sentAt":"2005-05-27T10:36:31Z","receivedAt":"2005-05-27T10:36:31Z","isPatch":true,"sender":{"key":"sct@redhat.com","avatar":null},"body":"git-deltafy-script contains two off-by-one errors that prevent it from\ndeltafying either the last file it encounters, or the oldest version of\nany file.\n\nThe script decides that it needs to run git-mkdelta when it encounters\nthe next filename in its inner loop.  The last file obviously doesn't \nhave a next file, so does not get processed.  Fix this by factoring\nout the test that runs the file processing, and forcibly run that test\nagain at the end of the loop to catch the last file.\n\nThere's a second problem; the script only passes one revision to\ngit-mkdelta per change it finds in the tree history.  For each change,\nit only adds the hash of the file's new version to the list of hashes\nbeing built up.  The oldest version is ignored.  Fix this by outputing\nboth the old AND new versions when we encounter an \"M\" line in the tree\ndiff; that will mean that hashes crop up multiple times if the old \nversion from one commit matches the new version of an older commit, but\nwe're already doing a \"uniq\" which strips those duplicates out.\n\nSigned-off-by: Stephen Tweedie <sct@redhat.com>\n\n---\ncommit a1d358812e6796a1ebdac740dcd666a567adb462\ntree 9bfe10668d8220dd1a6642e06fa9c8d726134675\nparent a95abde1074b8bf5bb4e4dab930397188e1bb3fa\nauthor Stephen Tweedie <sct@redhat.com> Fri, 27 May 2005 11:25:51 +0100\ncommitter Stephen Tweedie <sct@redhat.com> Fri, 27 May 2005 11:25:51 +0100\n\n git-deltafy-script |   38 +++++++++++++++++++++++---------------\n 1 files changed, 23 insertions(+), 15 deletions(-)\n\nIndex: git-deltafy-script\n===================================================================\n--- af5e58731609986ed53e05508b55f801b3d5c51d/git-deltafy-script  (mode:100644)\n+++ 9bfe10668d8220dd1a6642e06fa9c8d726134675/git-deltafy-script  (mode:100644)\n@@ -19,22 +19,30 @@\n depth=\n [ \"$1\" == \"-d\" ] && depth=\"--max-depth=$2\" && shift 2\n \n-curr_file=\"\"\n+function process_one () {\n+\tif [ \"$list\" ]; then\n+\t\techo \"Processing $curr_file\"\n+\t\techo \"$head $list\" | xargs git-mkdelta $depth -v\n+\tfi\n+}\n+\n \n git-rev-list HEAD |\n git-diff-tree -r --stdin |\n-awk '/^:/ { if ($5 == \"M\" || $5 == \"N\") print $4, $6 }' |\n-LC_ALL=C sort -s -k 2 | uniq |\n-while read sha1 file; do\n-\tif [ \"$file\" == \"$curr_file\" ]; then\n-\t\tlist=\"$list $sha1\"\n-\telse\n-\t\tif [ \"$list\" ]; then\n-\t\t\techo \"Processing $curr_file\"\n-\t\t\techo \"$head $list\" | xargs git-mkdelta $depth -v\n+awk '/^:/ { if ($5 == \"M\" || $5 == \"N\") print $4, $6; \n+\t    if ($5 == \"M\") print $3, $6 }' |\n+LC_ALL=C sort -s -k 2 | uniq | \n+{\n+\tcurr_file=\"\"\n+\twhile read sha1 file; do\n+\t\tif [ \"$file\" == \"$curr_file\" ]; then\n+\t\t\tlist=\"$list $sha1\"\n+\t\telse\n+\t\t\tprocess_one\n+\t\t\tcurr_file=\"$file\"\n+\t\t\tlist=\"\"\n+\t\t\thead=\"$sha1\"\n \t\tfi\n-\t\tcurr_file=\"$file\"\n-\t\tlist=\"\"\n-\t\thead=\"$sha1\"\n-\tfi\n-done\n+\tdone\n+\tprocess_one\n+}\n"}]}