Handling $filter_subdir in the usual way requires a separate case at every use, because the variable is empty when unused. Furthermore, the case for --subdirectory-filter supplies its own --, so the user cannot provide one himself (though there is also very little point in doing so). Instead, tack the $filter_subdir onto $@ in the right place automatically, and only use a -- if it was not already provided by the user. We set non_ref_args again after changing "$@"; the next patch wants to use it again afterwards, so we better not leave a stale value in there. Signed-off-by: Thomas Rast <trast@xxxxxxxxxxxxxxx> --- This is preparatory for the next patch; introducing another 'case' along the lines of the existing one annoyed me, so I went for this instead. I would greatly appreciate extra eyes on my use of 'eval'. I originally expected this to work without eval, but apparently this is how one does it. Quoting rules in the shell are annoying. Incidentally, the last hunk sneak fixes a previously unquoted use of $ref that is my fault from back in a0e4639 (filter-branch: fix ref rewriting with --subdirectory-filter, 2008-08-12). git-filter-branch.sh | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index a480d6f..3890c22 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -257,15 +257,29 @@ 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" +non_ref_args=$(git rev-parse --no-revs --sq "$@") +dashdash=-- +for arg in "$non_ref_args"; do + if test arg = --; then + dashdash= + break + fi +done + case "$filter_subdir" in "") - git rev-list --reverse --topo-order --default HEAD \ - --parents --simplify-merges "$@" + filter_subdir_sq= ;; *) - git rev-list --reverse --topo-order --default HEAD \ - --parents --simplify-merges "$@" -- "$filter_subdir" -esac > ../revs || die "Could not get the commits" + filter_subdir_sq=$(git rev-parse --sq-quote "$filter_subdir") +esac + +eval "set -- \"\$@\" $dashdash $filter_subdir_sq" +non_ref_args=$(git rev-parse --no-revs --sq "$@") + +git rev-list --reverse --topo-order --default HEAD \ + --parents --simplify-merges "$@" \ + > ../revs || die "Could not get the commits" commits=$(wc -l <../revs | tr -d " ") test $commits -eq 0 && die "Found nothing to rewrite" @@ -356,8 +370,8 @@ then do sha1=$(git rev-parse "$ref"^0) test -f "$workdir"/../map/$sha1 && continue - ancestor=$(git rev-list --simplify-merges -1 \ - $ref -- "$filter_subdir") + ancestor=$(eval "git rev-list --simplify-merges " \ + "-1 \"$ref\" $non_ref_args") test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1 done < "$tempdir"/heads fi -- 1.6.5.1.139.g12527 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html