[PATCH] cg-pull: summarize the number of pulled objects

From: Jonas Fonseca <fonseca@diku.dk>
Date: 2005-05-30 11:56:50
Show cg-pull progress by summarizing the very verbose output of the pull
backends into a continously updated line specifying the number of
objects which have already been pulled.
		     
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---

Straight from the bloat department, perhaps, but it is nice to not have
the terminal backlog ruined and the object count is quite nice too. :)

Interesting, it counts 4950 objects when pulling over rsync and 4454
objects when pulling locally. Didn't test HTTP pulling other than to see
if the "got <sha>" lines was matched correctly.

 cg-pull |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/cg-pull b/cg-pull
--- a/cg-pull
+++ b/cg-pull
@@ -29,6 +29,29 @@ if echo "$uri" | grep -q '#'; then
 	uri=$(echo $uri | cut -d '#' -f 1)
 fi
 
+pull_progress() {
+	objects=0
+	last_objects=0
+
+	while read line; do
+		case "$line" in
+		link*| symlink*| \
+		[a-f0-9][a-f0-9]/[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*| \
+		"got "[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*)
+			objects=$(($objects + 1));
+			echo -ne "Pulling objects: $objects\r"
+			;;
+		*)
+			if [ "$last_objects" != "$objecst" ]; then
+				last_objects=$objects
+				echo;
+			fi
+			echo "$line"
+			;;
+		esac 
+	done;
+	[ "$last_objects" != "$objecst" ] && echo
+}
 
 fetch_rsync () {
 	redir=
@@ -62,7 +85,7 @@ fetch_rsync () {
 }
 
 pull_rsync () {
-	fetch_rsync -s -u -d "$2/objects" "$_git_objects"
+	fetch_rsync -s -u -d "$2/objects" "$_git_objects" | pull_progress
 }
 
 
@@ -107,7 +130,7 @@ fetch_http () {
 }
 
 pull_http () {
-	git-http-pull -a -v "$(cat "$_git/refs/heads/$1")" "$2/"
+	(git-http-pull -a -v "$(cat "$_git/refs/heads/$1")" "$2/" 2>&1 /dev/null) | pull_progress
 }
 
 
@@ -170,7 +193,7 @@ fetch_local () {
 }
 
 pull_local () {
-	git-local-pull -a -l -v "$(cat "$_git/refs/heads/$1")" "$2"
+	(git-local-pull -a -l -v "$(cat "$_git/refs/heads/$1")" "$2" 2>&1 /dev/null) | pull_progress
 }
 
 if echo "$uri" | grep -q "^http://"; then
-- 
Jonas Fonseca
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Mon May 30 11:57:01 2005

This archive was generated by hypermail 2.1.8 : 2005-05-30 11:57:02 EST