Merge branch 'js/filter-branch-prime'
authorJunio C Hamano <gitster@pobox.com>
Thu, 7 Jan 2010 23:40:30 +0000 (15:40 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 7 Jan 2010 23:40:30 +0000 (15:40 -0800)
* js/filter-branch-prime:
filter-branch: remove an unnecessary use of 'git read-tree'

1  2 
git-filter-branch.sh
diff --combined git-filter-branch.sh
index cb9d2022cc93f1f371264098828a52e0d6bf1d7c,cfead301eee1dfab75112a5f5302f866e0e9e34b..195b5ef48ed3371b2010f9caf711e12089da9c06
@@@ -125,7 -125,6 +125,7 @@@ filter_subdir
  orig_namespace=refs/original/
  force=
  prune_empty=
 +remap_to_ancestor=
  while :
  do
        case "$1" in
                force=t
                continue
                ;;
 +      --remap-to-ancestor)
 +              shift
 +              remap_to_ancestor=t
 +              continue
 +              ;;
        --prune-empty)
                shift
                prune_empty=t
                ;;
        --subdirectory-filter)
                filter_subdir="$OPTARG"
 +              remap_to_ancestor=t
                ;;
        --original)
                orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
@@@ -259,29 -252,19 +259,28 @@@ test -s "$tempdir"/heads |
  
  GIT_INDEX_FILE="$(pwd)/../index"
  export GIT_INDEX_FILE
- git read-tree || die "Could not seed the index"
  
  # map old->new commit ids for rewriting parents
  mkdir ../map || die "Could not create map/ directory"
  
 +# we need "--" only if there are no path arguments in $@
 +nonrevs=$(git rev-parse --no-revs "$@") || exit
 +test -z "$nonrevs" && dashdash=-- || dashdash=
 +rev_args=$(git rev-parse --revs-only "$@")
 +
  case "$filter_subdir" in
  "")
 -      git rev-list --reverse --topo-order --default HEAD \
 -              --parents --simplify-merges "$@"
 +      eval set -- "$(git rev-parse --sq --no-revs "$@")"
        ;;
  *)
 -      git rev-list --reverse --topo-order --default HEAD \
 -              --parents --simplify-merges "$@" -- "$filter_subdir"
 -esac > ../revs || die "Could not get the commits"
 +      eval set -- "$(git rev-parse --sq --no-revs "$@" $dashdash \
 +              "$filter_subdir")"
 +      ;;
 +esac
 +
 +git rev-list --reverse --topo-order --default HEAD \
 +      --parents --simplify-merges $rev_args "$@" > ../revs ||
 +      die "Could not get the commits"
  commits=$(wc -l <../revs | tr -d " ")
  
  test $commits -eq 0 && die "Found nothing to rewrite"
@@@ -361,19 -344,19 +360,19 @@@ while read commit parents; d
                        die "could not write rewritten commit"
  done <../revs
  
 -# In case of a subdirectory filter, it is possible that a specified head
 -# is not in the set of rewritten commits, because it was pruned by the
 -# revision walker.  Fix it by mapping these heads to the unique nearest
 -# ancestor that survived the pruning.
 +# If we are filtering for paths, as in the case of a subdirectory
 +# filter, it is possible that a specified head is not in the set of
 +# rewritten commits, because it was pruned by the revision walker.
 +# Ancestor remapping fixes this by mapping these heads to the unique
 +# nearest ancestor that survived the pruning.
  
 -if test "$filter_subdir"
 +if test "$remap_to_ancestor" = t
  then
        while read ref
        do
                sha1=$(git rev-parse "$ref"^0)
                test -f "$workdir"/../map/$sha1 && continue
 -              ancestor=$(git rev-list --simplify-merges -1 \
 -                              $ref -- "$filter_subdir")
 +              ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
                test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1
        done < "$tempdir"/heads
  fi