]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-filter-branch.sh
strmap: enable allocations to come from a mem_pool
[thirdparty/git.git] / git-filter-branch.sh
index 1b7e4b2cdbdf36e090c4b1f531dcc48222d8f8b1..fea79646172184c630508908dd6eb61d3470074d 100755 (executable)
@@ -11,6 +11,8 @@
 # The following functions will also be available in the commit filter:
 
 functions=$(cat << \EOF
+EMPTY_TREE=$(git hash-object -t tree /dev/null)
+
 warn () {
        echo "$*" >&2
 }
@@ -46,7 +48,7 @@ git_commit_non_empty_tree()
 {
        if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
                map "$3"
-       elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
+       elif test $# = 1 && test "$1" = $EMPTY_TREE; then
                :
        else
                git commit-tree "$@"
@@ -81,6 +83,20 @@ set_ident () {
        finish_ident COMMITTER
 }
 
+if test -z "$FILTER_BRANCH_SQUELCH_WARNING$GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS"
+then
+       cat <<EOF
+WARNING: git-filter-branch has a glut of gotchas generating mangled history
+        rewrites.  Hit Ctrl-C before proceeding to abort, then use an
+        alternative filtering tool such as 'git filter-repo'
+        (https://github.com/newren/git-filter-repo/) instead.  See the
+        filter-branch manual page for more details; to squelch this warning,
+        set FILTER_BRANCH_SQUELCH_WARNING=1.
+EOF
+       sleep 10
+       printf "Proceeding with filter-branch...\n\n"
+fi
+
 USAGE="[--setup <command>] [--subdirectory-filter <directory>] [--env-filter <command>]
        [--tree-filter <command>] [--index-filter <command>]
        [--parent-filter <command>] [--msg-filter <command>]
@@ -251,8 +267,18 @@ done < "$tempdir"/backup-refs
 
 # The refs should be updated if their heads were rewritten
 git rev-parse --no-flags --revs-only --symbolic-full-name \
-       --default HEAD "$@" > "$tempdir"/raw-heads || exit
-sed -e '/^^/d' "$tempdir"/raw-heads >"$tempdir"/heads
+       --default HEAD "$@" > "$tempdir"/raw-refs || exit
+while read ref
+do
+       case "$ref" in ^?*) continue ;; esac
+
+       if git rev-parse --verify "$ref"^0 >/dev/null 2>&1
+       then
+               echo "$ref"
+       else
+               warn "WARNING: not rewriting '$ref' (not a committish)"
+       fi
+done >"$tempdir"/heads <"$tempdir"/raw-refs
 
 test -s "$tempdir"/heads ||
        die "You must specify a ref to rewrite."
@@ -310,7 +336,7 @@ git rev-list --reverse --topo-order --default HEAD \
        die "Could not get the commits"
 commits=$(wc -l <../revs | tr -d " ")
 
-test $commits -eq 0 && die "Found nothing to rewrite"
+test $commits -eq 0 && die_with_status 2 "Found nothing to rewrite"
 
 # Rewrite the commits
 report_progress ()
@@ -360,6 +386,7 @@ while read commit parents; do
        git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
 
        report_progress
+       test -f "$workdir"/../map/$commit && continue
 
        case "$filter_subdir" in
        "")
@@ -627,12 +654,12 @@ then
                                print H "$_:$f\n" or die;
                        }
                        close(H) or die;' || die "Unable to save state")
-       state_tree=$(/bin/echo -e "100644 blob $state_blob\tfilter.map" | git mktree)
+       state_tree=$(printf '100644 blob %s\tfilter.map\n' "$state_blob" | git mktree)
        if test -n "$state_commit"
        then
-               state_commit=$(/bin/echo "Sync" | git commit-tree "$state_tree" -p "$state_commit")
+               state_commit=$(echo "Sync" | git commit-tree "$state_tree" -p "$state_commit")
        else
-               state_commit=$(/bin/echo "Sync" | git commit-tree "$state_tree" )
+               state_commit=$(echo "Sync" | git commit-tree "$state_tree" )
        fi
        git update-ref "$state_branch" "$state_commit"
 fi