Subject: [PATCH] Fix git-deltafy-script off-by-one errors

From: Stephen Tweedie <[email-masked]>
Date: Fri, 27 May 2005 06:36:31 -0400

git-deltafy-script contains two off-by-one errors that prevent it from
deltafying either the last file it encounters, or the oldest version of
any file.

The script decides that it needs to run git-mkdelta when it encounters
the next filename in its inner loop.  The last file obviously doesn't 
have a next file, so does not get processed.  Fix this by factoring
out the test that runs the file processing, and forcibly run that test
again at the end of the loop to catch the last file.

There's a second problem; the script only passes one revision to
git-mkdelta per change it finds in the tree history.  For each change,
it only adds the hash of the file's new version to the list of hashes
being built up.  The oldest version is ignored.  Fix this by outputing
both the old AND new versions when we encounter an "M" line in the tree
diff; that will mean that hashes crop up multiple times if the old 
version from one commit matches the new version of an older commit, but
we're already doing a "uniq" which strips those duplicates out.

Signed-off-by: Stephen Tweedie <[email-masked]>

---
commit a1d358812e6796a1ebdac740dcd666a567adb462
tree 9bfe10668d8220dd1a6642e06fa9c8d726134675
parent a95abde1074b8bf5bb4e4dab930397188e1bb3fa
author Stephen Tweedie <[email-masked]> Fri, 27 May 2005 11:25:51 +0100
committer Stephen Tweedie <[email-masked]> Fri, 27 May 2005 11:25:51 +0100

 git-deltafy-script |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)

Index: git-deltafy-script
===================================================================
--- af5e58731609986ed53e05508b55f801b3d5c51d/git-deltafy-script  (mode:100644)
+++ 9bfe10668d8220dd1a6642e06fa9c8d726134675/git-deltafy-script  (mode:100644)
@@ -19,22 +19,30 @@
 depth=
 [ "$1" == "-d" ] && depth="--max-depth=$2" && shift 2
 
-curr_file=""
+function process_one () {
+	if [ "$list" ]; then
+		echo "Processing $curr_file"
+		echo "$head $list" | xargs git-mkdelta $depth -v
+	fi
+}
+
 
 git-rev-list HEAD |
 git-diff-tree -r --stdin |
-awk '/^:/ { if ($5 == "M" || $5 == "N") print $4, $6 }' |
-LC_ALL=C sort -s -k 2 | uniq |
-while read sha1 file; do
-	if [ "$file" == "$curr_file" ]; then
-		list="$list $sha1"
-	else
-		if [ "$list" ]; then
-			echo "Processing $curr_file"
-			echo "$head $list" | xargs git-mkdelta $depth -v
+awk '/^:/ { if ($5 == "M" || $5 == "N") print $4, $6; 
+	    if ($5 == "M") print $3, $6 }' |
+LC_ALL=C sort -s -k 2 | uniq | 
+{
+	curr_file=""
+	while read sha1 file; do
+		if [ "$file" == "$curr_file" ]; then
+			list="$list $sha1"
+		else
+			process_one
+			curr_file="$file"
+			list=""
+			head="$sha1"
 		fi
-		curr_file="$file"
-		list=""
-		head="$sha1"
-	fi
-done
+	done
+	process_one
+}