@matheusbsbs / matheus-bagliano / commits / 3520e1e868
Fork 0

filter-branch: also don't fail in map() if a commit cannot be mapped

The map() function can be used by filters to map a commit id to its rewritten id. Such a mapping may not exist, in which case the identity mapping is used (the commit is returned unchanged). In the rewrite loop, this mapping is also needed, but was done explicitly in the same way. Use the map() function instead. 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 20:38 UTC 3520e1e86878c6787c3abfe677e6472ce2c97f66
1 file changed +5 -9
git-filter-branch.sh
+5 -9
@@ -184,7 +184,8 @@ USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]"
184
185 map()
186 {
187 - [ -r "$workdir/../map/$1" ] || return 1
187 + # if it was not rewritten, take the original
188 + test -r "$workdir/../map/$1" || echo "$1"
189 cat "$workdir/../map/$1"
190 }
191
@@ -347,14 +348,9 @@ while read commit; do
348
349 parentstr=
350 for parent in $(get_parents $commit); do
350 - if [ -r "../map/$parent" ]; then
351 - for reparent in $(cat "../map/$parent"); do
352 - parentstr="$parentstr -p $reparent"
353 - done
354 - else
355 - # if it was not rewritten, take the original
356 - parentstr="$parentstr -p $parent"
357 - fi
351 + for reparent in $(map "$parent"); do
352 + parentstr="$parentstr -p $reparent"
353 + done
354 done
355 if [ "$filter_parent" ]; then
356 parentstr="$(echo "$parentstr" | eval "$filter_parent")"