Merge branch 'en/merge-cleanup-more'
[gitweb.git] / contrib / subtree / git-subtree.sh
index d8861f306593ade478ae4eb76a83d591859d154c..147201dc6c5786c9cfedbbbff0df0b1dced171db 100755 (executable)
@@ -231,12 +231,14 @@ cache_miss () {
 }
 
 check_parents () {
-       missed=$(cache_miss "$@")
+       missed=$(cache_miss "$1")
+       local indent=$(($2 + 1))
        for miss in $missed
        do
                if ! test -r "$cachedir/notree/$miss"
                then
                        debug "  incorrect order: $miss"
+                       process_split_commit "$miss" "" "$indent"
                fi
        done
 }
@@ -539,6 +541,7 @@ copy_or_skip () {
        nonidentical=
        p=
        gotparents=
+       copycommit=
        for parent in $newparents
        do
                ptree=$(toptree_for_commit $parent) || exit $?
@@ -546,7 +549,24 @@ copy_or_skip () {
                if test "$ptree" = "$tree"
                then
                        # an identical parent could be used in place of this rev.
-                       identical="$parent"
+                       if test -n "$identical"
+                       then
+                               # if a previous identical parent was found, check whether
+                               # one is already an ancestor of the other
+                               mergebase=$(git merge-base $identical $parent)
+                               if test "$identical" = "$mergebase"
+                               then
+                                       # current identical commit is an ancestor of parent
+                                       identical="$parent"
+                               elif test "$parent" != "$mergebase"
+                               then
+                                       # no common history; commit must be copied
+                                       copycommit=1
+                               fi
+                       else
+                               # first identical parent detected
+                               identical="$parent"
+                       fi
                else
                        nonidentical="$parent"
                fi
@@ -569,7 +589,6 @@ copy_or_skip () {
                fi
        done
 
-       copycommit=
        if test -n "$identical" && test -n "$nonidentical"
        then
                extras=$(git rev-list --count $identical..$nonidentical)
@@ -606,8 +625,20 @@ ensure_valid_ref_format () {
 process_split_commit () {
        local rev="$1"
        local parents="$2"
-       revcount=$(($revcount + 1))
-       progress "$revcount/$revmax ($createcount)"
+       local indent=$3
+
+       if test $indent -eq 0
+       then
+               revcount=$(($revcount + 1))
+       else
+               # processing commit without normal parent information;
+               # fetch from repo
+               parents=$(git rev-parse "$rev^@")
+               extracount=$(($extracount + 1))
+       fi
+
+       progress "$revcount/$revmax ($createcount) [$extracount]"
+
        debug "Processing commit: $rev"
        exists=$(cache_get "$rev")
        if test -n "$exists"
@@ -617,14 +648,13 @@ process_split_commit () {
        fi
        createcount=$(($createcount + 1))
        debug "  parents: $parents"
+       check_parents "$parents" "$indent"
        newparents=$(cache_get $parents)
        debug "  newparents: $newparents"
 
        tree=$(subtree_for_commit "$rev" "$dir")
        debug "  tree is: $tree"
 
-       check_parents $parents
-
        # ugly.  is there no better way to tell if this is a subtree
        # vs. a mainline commit?  Does it matter?
        if test -z "$tree"
@@ -744,10 +774,11 @@ cmd_split () {
        revmax=$(eval "$grl" | wc -l)
        revcount=0
        createcount=0
+       extracount=0
        eval "$grl" |
        while read rev parents
        do
-               process_split_commit "$rev" "$parents"
+               process_split_commit "$rev" "$parents" 0
        done || exit $?
 
        latest_new=$(cache_get latest_new)