@matheusbsbs / matheus-bagliano / commits / 2c1d2d8188
Fork 0

filter-branch: stop special-casing $filter_subdir argument

Handling $filter_subdir in the usual way requires a separate case at every use, because the variable is empty when unused. Furthermore, --subdirectory-filter supplies its own '--', and if the user provided one himself, such as in git filter-branch --subdirectory-filter subdir -- --all -- subdir/file an extra '--' was used as path filter in the call to git-rev-list that determines the commits that shall be rewritten. To keep the argument handling sane, we filter $@ to contain only the non-revision arguments, and store all revisions in $ref_args. The $ref_args are easy to handle since only the SHA1s are needed; the actual branch names have already been stored in $tempdir/heads at this point. An extra separating -- is only required if the user did not provide any non-revision arguments, as the latter disambiguate the $filter_subdir following after them (or fail earlier because they are ambiguous themselves). Thanks to Johannes Sixt for suggesting this solution. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Nov 11, 2009 at 09:53 UTC 2c1d2d818895d896f706835142a75978aabdbdc9
1 file changed +15 -7
git-filter-branch.sh
+15 -7
@@ -257,15 +257,24 @@ git read-tree || die "Could not seed the index"
257 # map old->new commit ids for rewriting parents
258 mkdir ../map || die "Could not create map/ directory"
259
260 +# we need "--" only if there are no path arguments in $@
261 +nonrevs=$(git rev-parse --no-revs "$@") || exit
262 +test -z "$nonrevs" && dashdash=-- || dashdash=
263 +rev_args=$(git rev-parse --revs-only "$@")
264 +
265 case "$filter_subdir" in
266 "")
262 - git rev-list --reverse --topo-order --default HEAD \
263 - --parents --simplify-merges "$@"
267 + eval set -- "$(git rev-parse --sq --no-revs "$@")"
268 ;;
269 *)
266 - git rev-list --reverse --topo-order --default HEAD \
267 - --parents --simplify-merges "$@" -- "$filter_subdir"
268 -esac > ../revs || die "Could not get the commits"
270 + eval set -- "$(git rev-parse --sq --no-revs "$@" $dashdash \
271 + "$filter_subdir")"
272 + ;;
273 +esac
274 +
275 +git rev-list --reverse --topo-order --default HEAD \
276 + --parents --simplify-merges $rev_args "$@" > ../revs ||
277 + die "Could not get the commits"
278 commits=$(wc -l <../revs | tr -d " ")
279
280 test $commits -eq 0 && die "Found nothing to rewrite"
@@ -356,8 +365,7 @@ then
365 do
366 sha1=$(git rev-parse "$ref"^0)
367 test -f "$workdir"/../map/$sha1 && continue
359 - ancestor=$(git rev-list --simplify-merges -1 \
360 - $ref -- "$filter_subdir")
368 + ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
369 test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1
370 done < "$tempdir"/heads
371 fi