summaryrefslogtreecommitdiff
path: root/git-filter-branch.sh
diff options
context:
space:
mode:
authorThomas Rast <trast@student.ethz.ch>2009-11-10 21:04:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-11-13 19:26:43 (GMT)
commitf2f3a6b802e3dae09a1c414cd8516ff2a546a527 (patch)
treeca23c536248b2861bca602b5b6d5c32863a8f7a2 /git-filter-branch.sh
parent2c1d2d818895d896f706835142a75978aabdbdc9 (diff)
downloadgit-f2f3a6b802e3dae09a1c414cd8516ff2a546a527.zip
git-f2f3a6b802e3dae09a1c414cd8516ff2a546a527.tar.gz
git-f2f3a6b802e3dae09a1c414cd8516ff2a546a527.tar.bz2
filter-branch: nearest-ancestor rewriting outside subdir filter
Since a0e4639 (filter-branch: fix ref rewriting with --subdirectory-filter, 2008-08-12) git-filter-branch has done nearest-ancestor rewriting when using a --subdirectory-filter. However, that rewriting strategy is also a useful building block in other tasks. For example, if you want to split out a subset of files from your history, you would typically call git filter-branch -- <refs> -- <files> But this fails for all refs that do not point directly to a commit that affects <files>, because their referenced commit will not be rewritten and the ref remains untouched. The code was already there for the --subdirectory-filter case, so just introduce an option that enables it independently. 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>
Diffstat (limited to 'git-filter-branch.sh')
-rwxr-xr-xgit-filter-branch.sh18
1 files changed, 13 insertions, 5 deletions
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index ed3db7d..6b8b6a4 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -125,6 +125,7 @@ filter_subdir=
orig_namespace=refs/original/
force=
prune_empty=
+remap_to_ancestor=
while :
do
case "$1" in
@@ -137,6 +138,11 @@ do
force=t
continue
;;
+ --remap-to-ancestor)
+ shift
+ remap_to_ancestor=t
+ continue
+ ;;
--prune-empty)
shift
prune_empty=t
@@ -182,6 +188,7 @@ do
;;
--subdirectory-filter)
filter_subdir="$OPTARG"
+ remap_to_ancestor=t
;;
--original)
orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
@@ -354,12 +361,13 @@ while read commit parents; do
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