Skip over empty commits.
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 24 Apr 2009 21:53:10 +0000 (17:53 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 24 Apr 2009 21:53:10 +0000 (17:53 -0400)
But we still need to get rid of unnecessary merge commits somehow...

git-subtree.sh

index 1e1237f52006db612a4e69d1565672456bc07854..7ae71886f443b4cd12b4af8ee12674b1e18d0755 100755 (executable)
@@ -167,6 +167,32 @@ merge_msg()
        EOF
 }
 
+tree_for_commit()
+{
+       git ls-tree "$1" -- "$dir" |
+       while read mode type tree name; do
+               assert [ "$name" = "$dir" ]
+               echo $tree
+               break
+       done
+}
+
+tree_changed()
+{
+       tree=$1
+       shift
+       if [ $# -ne 1 ]; then
+               return 0   # weird parents, consider it changed
+       else
+               ptree=$(tree_for_commit $1)
+               if [ "$ptree" != "$tree" ]; then
+                       return 0   # changed
+               else
+                       return 1   # not changed
+               fi
+       fi
+}
+
 cmd_split()
 {
        debug "Splitting $dir..."
@@ -199,21 +225,24 @@ cmd_split()
                newparents=$(cache_get $parents)
                debug "  newparents: $newparents"
                
-               git ls-tree $rev -- "$dir" |
-               while read mode type tree name; do
-                       assert [ "$name" = "$dir" ]
-                       debug "  tree is: $tree"
-                       p=""
-                       for parent in $newparents; do
-                               p="$p -p $parent"
-                       done
+               tree=$(tree_for_commit $rev)
+               debug "  tree is: $tree"
+               [ -z $tree ] && continue
+
+               p=""
+               for parent in $newparents; do
+                       p="$p -p $parent"
+               done
                        
+               if tree_changed $tree $parents; then
                        newrev=$(copy_commit $rev $tree "$p") || exit $?
-                       debug "  newrev is: $newrev"
-                       cache_set $rev $newrev
-                       cache_set latest_new $newrev
-                       cache_set latest_old $rev
-               done || exit $?
+               else
+                       newrev="$newparents"
+               fi
+               debug "  newrev is: $newrev"
+               cache_set $rev $newrev
+               cache_set latest_new $newrev
+               cache_set latest_old $rev
        done || exit $?
        latest_new=$(cache_get latest_new)
        if [ -z "$latest_new" ]; then