Skip to content

Commit 813b473

Browse files
Johannes Sixtgitster
authored andcommitted
filter-branch: Simplify parent computation.
We can use git rev-list --parents when we list the commits to rewrite. It is not necessary to run git rev-list --parents for each commit in the loop. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 685ef54 commit 813b473

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

git-filter-branch.sh

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,6 @@ set_ident () {
226226
echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
227227
}
228228

229-
# list all parent's object names for a given commit
230-
get_parents () {
231-
case "$filter_subdir" in
232-
"")
233-
git-rev-list -1 --parents "$1"
234-
;;
235-
*)
236-
git-rev-list -1 --parents "$1" -- "$filter_subdir"
237-
esac | sed "s/^[0-9a-f]*//"
238-
}
239-
240229
tempdir=.git-rewrite
241230
filter_env=
242231
filter_tree=
@@ -329,18 +318,19 @@ mkdir ../map # map old->new commit ids for rewriting parents
329318

330319
case "$filter_subdir" in
331320
"")
332-
git-rev-list --reverse --topo-order --default HEAD "$@"
321+
git-rev-list --reverse --topo-order --default HEAD \
322+
--parents "$@"
333323
;;
334324
*)
335-
git-rev-list --reverse --topo-order --default HEAD "$@" \
336-
-- "$filter_subdir"
325+
git-rev-list --reverse --topo-order --default HEAD \
326+
--parents "$@" -- "$filter_subdir"
337327
esac > ../revs
338328
commits=$(cat ../revs | wc -l | tr -d " ")
339329

340330
test $commits -eq 0 && die "Found nothing to rewrite"
341331

342332
i=0
343-
while read commit; do
333+
while read commit parents; do
344334
i=$(($i+1))
345335
printf "$commit ($i/$commits) "
346336

@@ -374,7 +364,7 @@ while read commit; do
374364
eval "$filter_index" < /dev/null
375365

376366
parentstr=
377-
for parent in $(get_parents $commit); do
367+
for parent in $parents; do
378368
for reparent in $(map "$parent"); do
379369
parentstr="$parentstr -p $reparent"
380370
done
@@ -389,7 +379,7 @@ while read commit; do
389379
tee ../map/$commit
390380
done <../revs
391381

392-
src_head=$(tail -n 1 ../revs)
382+
src_head=$(tail -n 1 ../revs | sed -e 's/ .*//')
393383
target_head=$(head -n 1 ../map/$src_head)
394384
case "$target_head" in
395385
'')

0 commit comments

Comments
 (0)