aboutsummaryrefslogtreecommitdiff
path: root/git-filter-branch.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-06-08 01:30:35 +0100
committerJunio C Hamano <gitster@pobox.com>2007-06-09 12:16:49 -0700
commit685ef546b62d063c72b401cd38b83a879301aac4 (patch)
treee77b86327c888b55739f79c1ca939b89f947e193 /git-filter-branch.sh
parent3520e1e86878c6787c3abfe677e6472ce2c97f66 (diff)
downloadgit-685ef546b62d063c72b401cd38b83a879301aac4.tar.gz
git-685ef546b62d063c72b401cd38b83a879301aac4.tar.xz
Teach filter-branch about subdirectory filtering
With git-filter-branch --subdirectory-filter <subdirectory> you can get at the history, as seen by a certain subdirectory. The history of the rewritten branch will only contain commits that touched that subdirectory, and the subdirectory will be rewritten to be the new project root. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-filter-branch.sh')
-rwxr-xr-xgit-filter-branch.sh33
1 files changed, 30 insertions, 3 deletions
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 9d61b7fff..efb8f2dbc 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -119,6 +119,10 @@
# attached, the rewritten tag won't have it. Sorry. (It is by
# definition impossible to preserve signatures at any rate, though.)
#
+# --subdirectory-filter DIRECTORY:: Only regard the history, as seen by
+# the given subdirectory. The result will contain that directory as
+# its project root.
+#
# EXAMPLE USAGE
# -------------
# Suppose you want to remove a file (containing confidential information
@@ -224,7 +228,13 @@ set_ident () {
# list all parent's object names for a given commit
get_parents () {
- git-rev-list -1 --parents "$1" | sed "s/^[0-9a-f]*//"
+ case "$filter_subdir" in
+ "")
+ git-rev-list -1 --parents "$1"
+ ;;
+ *)
+ git-rev-list -1 --parents "$1" -- "$filter_subdir"
+ esac | sed "s/^[0-9a-f]*//"
}
tempdir=.git-rewrite
@@ -235,6 +245,7 @@ filter_parent=
filter_msg=cat
filter_commit='git-commit-tree "$@"'
filter_tag_name=
+filter_subdir=
while case "$#" in 0) usage;; esac
do
case "$1" in
@@ -280,6 +291,9 @@ do
--tag-name-filter)
filter_tag_name="$OPTARG"
;;
+ --subdirectory-filter)
+ filter_subdir="$OPTARG"
+ ;;
*)
usage
;;
@@ -313,7 +327,14 @@ ret=0
mkdir ../map # map old->new commit ids for rewriting parents
-git-rev-list --reverse --topo-order --default HEAD "$@" >../revs
+case "$filter_subdir" in
+"")
+ git-rev-list --reverse --topo-order --default HEAD "$@"
+ ;;
+*)
+ git-rev-list --reverse --topo-order --default HEAD "$@" \
+ -- "$filter_subdir"
+esac > ../revs
commits=$(cat ../revs | wc -l | tr -d " ")
test $commits -eq 0 && die "Found nothing to rewrite"
@@ -323,7 +344,13 @@ while read commit; do
i=$(($i+1))
printf "$commit ($i/$commits) "
- git-read-tree -i -m $commit
+ case "$filter_subdir" in
+ "")
+ git-read-tree -i -m $commit
+ ;;
+ *)
+ git-read-tree -i -m $commit:"$filter_subdir"
+ esac
export GIT_COMMIT=$commit
git-cat-file commit "$commit" >../commit