Skip to content

Commit 3520e1e

Browse files
Johannes Sixtgitster
authored andcommitted
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 <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2766ce2 commit 3520e1e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

git-filter-branch.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]"
184184

185185
map()
186186
{
187-
[ -r "$workdir/../map/$1" ] || return 1
187+
# if it was not rewritten, take the original
188+
test -r "$workdir/../map/$1" || echo "$1"
188189
cat "$workdir/../map/$1"
189190
}
190191

@@ -347,14 +348,9 @@ while read commit; do
347348

348349
parentstr=
349350
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
358354
done
359355
if [ "$filter_parent" ]; then
360356
parentstr="$(echo "$parentstr" | eval "$filter_parent")"

0 commit comments

Comments
 (0)