From: Robert Luberda <robert@debian.org>
To: git@vger.kernel.org
Subject: BUG: git filter-branch does not make tree replacements permanent
Date: Thu, 11 Apr 2013 23:08:16 +0200 [thread overview]
Message-ID: <20130411210816.GA15810@vox.robbo.home> (raw)
Hi,
The git filter-branch man page states:
NOTE: This command honors .git/info/grafts and .git/refs/replace/.
If you have any grafts or replacement refs defined, running
this command will make them permanent.
However the command does not seem to honor tree (or blob) objects
replacements. The bug can be reproduced (with both git 1.7.10 and
1.8.2.1.342.gfa7285d) in the following simple steps:
1. Setup:
git init
for i in a b c d; do echo $i >> f; git add f; git commit -m "$i"; done
git diff HEAD~2..HEAD~1 # the output is non-empty
2. Add replacement for some tree object
git replace `git log --format=raw | sed -ne 's/^tree //p' | sed -n 2,3p | tac`
git diff HEAD~2..HEAD~1 # the output is now empty
3. Run filter-branch:
git filter-branch
4. Verify that unfortunatelly it did nothing:
git replace | xargs git replace -d
git diff HEAD~2..HEAD~1 # the output is still not empty
The following work-around works for me for tree objects replacements,
but I don't think it is suitable for inclusion in git sources. Most
probably git write-tree should be changed instead to take both the blob
and tree replacements into account.
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index ac2a005..68064f2 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -276,6 +276,16 @@ test $commits -eq 0 && die "Found nothing to rewrite"
# Rewrite the commits
+write_tree_func()
+{
+ m="$(git write-tree "$@")"
+ if [ -e "$ORIG_GIT_DIR/refs/replace/$m" ] ; then
+ n="$(cat "$ORIG_GIT_DIR/refs/replace/$m")"
+ echo "Replaced tree $m with $n" >&2
+ m="$n"
+ fi
+ echo "$m"
+}
git_filter_branch__commit_count=0
while read commit parents; do
git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
@@ -342,8 +352,8 @@ while read commit parents; do
sed -e '1,/^$/d' <../commit | \
eval "$filter_msg" > ../message ||
die "msg filter failed: $filter_msg"
- workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
- $(git write-tree) $parentstr < ../message > ../map/$commit ||
+ workdir=$workdir /bin/sh -c "$filter_commit" "git commit-tree" \
+ $(write_tree_func) $parentstr < ../message > ../map/$commit ||
die "could not write rewritten commit"
done <../revs
Regards,
robert
reply other threads:[~2013-04-11 21:27 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130411210816.GA15810@vox.robbo.home \
--to=robert@debian.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).