@matheusbsbs / matheus-bagliano / commits / 813b4734fc
Fork 0

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 <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Sixt committed Jun 8, 2007 at 23:28 UTC 813b4734fcb82e541658b33b8563387c197d6247
1 file changed +7 -17
git-filter-branch.sh
+7 -17
@@ -226,17 +226,6 @@ set_ident () {
226 echo "[ -n \"\$GIT_${uid}_NAME\" ] || export GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\""
227 }
228
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 -
229 tempdir=.git-rewrite
230 filter_env=
231 filter_tree=
@@ -329,18 +318,19 @@ mkdir ../map # map old->new commit ids for rewriting parents
318
319 case "$filter_subdir" in
320 "")
332 - git-rev-list --reverse --topo-order --default HEAD "$@"
321 + git-rev-list --reverse --topo-order --default HEAD \
322 + --parents "$@"
323 ;;
324 *)
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"
327 esac > ../revs
328 commits=$(cat ../revs | wc -l | tr -d " ")
329
330 test $commits -eq 0 && die "Found nothing to rewrite"
331
332 i=0
343 -while read commit; do
333 +while read commit parents; do
334 i=$(($i+1))
335 printf "$commit ($i/$commits) "
336
@@ -374,7 +364,7 @@ while read commit; do
364 eval "$filter_index" < /dev/null
365
366 parentstr=
377 - for parent in $(get_parents $commit); do
367 + for parent in $parents; do
368 for reparent in $(map "$parent"); do
369 parentstr="$parentstr -p $reparent"
370 done
@@ -389,7 +379,7 @@ while read commit; do
379 tee ../map/$commit
380 done <../revs
381
392 -src_head=$(tail -n 1 ../revs)
382 +src_head=$(tail -n 1 ../revs | sed -e 's/ .*//')
383 target_head=$(head -n 1 ../map/$src_head)
384 case "$target_head" in
385 '')