summaryrefslogtreecommitdiff
path: root/git-filter-branch.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-04-29 15:48:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-04-29 17:01:04 (GMT)
commitdf0620108b9710a06d5a2d9c125d43b97590cce6 (patch)
treee412b2280f96dee205ed20cb9c772d0477fb76f3 /git-filter-branch.sh
parent282616c72d1d08a77ca4fe1186cb708c38408d87 (diff)
downloadgit-df0620108b9710a06d5a2d9c125d43b97590cce6.zip
git-df0620108b9710a06d5a2d9c125d43b97590cce6.tar.gz
git-df0620108b9710a06d5a2d9c125d43b97590cce6.tar.bz2
filter-branch: avoid passing commit message through sed
On some systems (like OS X), if sed encounters input without a trailing newline, it will silently add it. As a result, "git filter-branch" on such systems may silently rewrite commit messages that omit a trailing newline. Even though this is not something we generate ourselves with "git commit", it's better for filter-branch to preserve the original data as closely as possible. We're using sed here only to strip the header fields from the commit object. We can accomplish the same thing with a shell loop. Since shell "read" calls are slow (usually one syscall per byte), we use "cat" once we've skipped past the header. Depending on the size of your commit messages, this is probably faster (you pay the cost to fork, but then read the data in saner-sized chunks). This idea is shamelessly stolen from Junio. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-filter-branch.sh')
-rwxr-xr-xgit-filter-branch.sh10
1 files changed, 9 insertions, 1 deletions
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index e6e99f5..5b3f63d 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -346,7 +346,15 @@ while read commit parents; do
die "parent filter failed: $filter_parent"
fi
- sed -e '1,/^$/d' <../commit | \
+ {
+ while read -r header_line && test -n "$header_line"
+ do
+ # skip header lines...
+ :;
+ done
+ # and output the actual commit message
+ cat
+ } <../commit |
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \