filter-branch: Use rev-list arguments to specify revision ranges.
A subset of commits in a branch used to be specified by options (-k, -r) as well as the branch tip itself (-s). It is more natural (for git users) to specify revision ranges like 'master..next' instead. This makes it so. If no range is specified it defaults to 'HEAD'. As a consequence, the new name of the filtered branch must be the first non-option argument. All remaining arguments are passed to 'git rev-list' unmodified. The tip of the branch that gets filtered is implied: It is the first commit that git rev-list would print for the specified range. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jun 6, 2007 at 09:43 UTC
2766ce28150597677bb91c424e6033a298c71510
2 files changed
+13
-28
git-filter-branch.sh
+12
-27
@@ -42,15 +42,6 @@
42
# does this in the '.git-rewrite/' directory but you can override
43
# that choice by this parameter.
44
#
45
-# -r STARTREV:: The commit id to start the rewrite at
46
-# Normally, the command will rewrite the entire history. If you
47
-# pass this argument, though, this will be the first commit it
48
-# will rewrite and keep the previous commits intact.
49
-#
50
-# -k KEEPREV:: A commit id until which _not_ to rewrite history
51
-# If you pass this argument, this commit and all of its
52
-# predecessors are kept intact.
53
-#
45
# Filters
46
# ~~~~~~~
47
# The filters are applied in the order as listed below. The COMMAND
@@ -164,27 +155,31 @@
155
# and all children of the merge will become merge commits with P1,P2
156
# as their parents instead of the merge commit.
157
#
167
-# To restrict rewriting to only part of the history, use -r or -k or both.
158
+# To restrict rewriting to only part of the history, specify a revision
159
+# range in addition to the new branch name. The new branch name will
160
+# point to the top-most revision that a 'git rev-list' of this range
161
+# will print.
162
+#
163
# Consider this history:
164
#
165
# D--E--F--G--H
166
# / /
167
# A--B-----C
168
#
174
-# To rewrite only commits F,G,H, use:
169
+# To rewrite commits D,E,F,G,H, use:
170
#
176
-# git-filter-branch -r F ...
171
+# git-filter-branch ... new-H C..H
172
#
173
# To rewrite commits E,F,G,H, use one of these:
174
#
180
-# git-filter-branch -r E -k C ...
181
-# git-filter-branch -k D -k C ...
175
+# git-filter-branch ... new-H C..H --not D
176
+# git-filter-branch ... new-H D..H --not C
177
178
# Testsuite: TODO
179
180
set -e
181
187
-USAGE="git-filter-branch [-d TEMPDIR] [-r STARTREV]... [-k KEEPREV]... [-s SRCBRANCH] [FILTERS] DESTBRANCH"
182
+USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]"
183
. git-sh-setup
184
185
map()
@@ -232,7 +227,6 @@ get_parents () {
227
}
228
229
tempdir=.git-rewrite
235
-unchanged=" "
230
filter_env=
231
filter_tree=
232
filter_index=
@@ -240,7 +234,6 @@ filter_parent=
234
filter_msg=cat
235
filter_commit='git-commit-tree "$@"'
236
filter_tag_name=
243
-srcbranch=HEAD
237
while case "$#" in 0) usage;; esac
238
do
239
case "$1" in
@@ -265,12 +258,6 @@ do
258
-d)
259
tempdir="$OPTARG"
260
;;
268
- -r)
269
- unchanged="$(get_parents "$OPTARG") $unchanged"
270
- ;;
271
- -k)
272
- unchanged="$(git-rev-parse "$OPTARG"^{commit}) $unchanged"
273
- ;;
261
--env-filter)
262
filter_env="$OPTARG"
263
;;
@@ -292,9 +279,6 @@ do
279
--tag-name-filter)
280
filter_tag_name="$OPTARG"
281
;;
295
- -s)
296
- srcbranch="$OPTARG"
297
- ;;
282
*)
283
usage
284
;;
@@ -302,6 +286,7 @@ do
286
done
287
288
dstbranch="$1"
289
+shift
290
test -n "$dstbranch" || die "missing branch name"
291
git-show-ref "refs/heads/$dstbranch" 2> /dev/null &&
292
die "branch $dstbranch already exists"
@@ -327,7 +312,7 @@ ret=0
312
313
mkdir ../map # map old->new commit ids for rewriting parents
314
330
-git-rev-list --reverse --topo-order $srcbranch --not $unchanged >../revs
315
+git-rev-list --reverse --topo-order --default HEAD "$@" >../revs
316
commits=$(cat ../revs | wc -l | tr -d " ")
317
318
test $commits -eq 0 && die "Found nothing to rewrite"
t/t7003-filter-branch.sh
+1
-1
@@ -47,7 +47,7 @@ test_expect_success 'test that the file was renamed' '
47
48
git tag oldD H3~4
49
test_expect_success 'rewrite one branch, keeping a side branch' '
50
- git-filter-branch --tree-filter "mv b boh || :" -k D -s oldD modD
50
+ git-filter-branch --tree-filter "mv b boh || :" modD D..oldD
51
'
52
53
test_expect_success 'common ancestor is still common (unchanged)' '