debug messages are off by default; use -d to enable.
[gitweb.git] / git-subtree.sh
index ffd3e0b865f5d12a42428e80c03f6272931ce878..39c377c173ac3e74006a2cfa2095f3692b557c9a 100755 (executable)
@@ -15,6 +15,7 @@ git subtree pull  --prefix=<prefix> <repository> <refspec...>
 --
 h,help        show the help
 q             quiet
+d             show debug messages
 prefix=       the name of the subdir to split out
  options for 'split'
 annotate=     add a prefix to commit message of new commits
@@ -27,6 +28,7 @@ eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)
 require_work_tree
 
 quiet=
+debug=
 command=
 onto=
 rejoin=
@@ -34,6 +36,13 @@ ignore_joins=
 annotate=
 
 debug()
+{
+       if [ -n "$debug" ]; then
+               echo "$@" >&2
+       fi
+}
+
+say()
 {
        if [ -z "$quiet" ]; then
                echo "$@" >&2
@@ -57,6 +66,7 @@ while [ $# -gt 0 ]; do
        shift
        case "$opt" in
                -q) quiet=1 ;;
+               -d) debug=1 ;;
                --annotate) annotate="$1"; shift ;;
                --no-annotate) annotate= ;;
                --prefix) prefix="$1"; shift ;;
@@ -258,6 +268,7 @@ copy_or_skip()
        assert [ -n "$tree" ]
 
        identical=
+       nonidentical=
        p=
        gotparents=
        for parent in $newparents; do
@@ -266,6 +277,8 @@ copy_or_skip()
                if [ "$ptree" = "$tree" ]; then
                        # an identical parent could be used in place of this rev.
                        identical="$parent"
+               else
+                       nonidentical="$parent"
                fi
                
                # sometimes both old parents map to the same newparent;
@@ -283,7 +296,7 @@ copy_or_skip()
                fi
        done
        
-       if [ -n "$identical" -a "$gotparents" = " $identical" ]; then
+       if [ -n "$identical" ]; then
                echo $identical
        else
                copy_commit $rev $tree "$p" || exit $?
@@ -354,15 +367,21 @@ cmd_split()
        # We can't restrict rev-list to only $dir here, because some of our
        # parents have the $dir contents the root, and those won't match.
        # (and rev-list --follow doesn't seem to solve this)
-       git rev-list --reverse --parents $revs $unrevs |
+       grl='git rev-list --reverse --parents $revs $unrevs'
+       revmax=$(eval "$grl" | wc -l)
+       revcount=0
+       createcount=0
+       eval "$grl" |
        while read rev parents; do
-               debug
+               revcount=$(($revcount + 1))
+               say -n "$revcount/$revmax ($createcount)\r"
                debug "Processing commit: $rev"
                exists=$(cache_get $rev)
                if [ -n "$exists" ]; then
                        debug "  prior: $exists"
                        continue
                fi
+               createcount=$(($createcount + 1))
                debug "  parents: $parents"
                newparents=$(cache_get $parents)
                debug "  newparents: $newparents"