From: Niko Tyni <[email protected]>
There's currently no notes filter for git-filter-branch, so we need
to use the commit filter instead.
---
only small changes from Niko's second version:
- add notes also to stdout exported patches (mbox)
- some newlines to debugging output
- add some comments to the parts that initially puzzled me
The revised version seems OK to me.
git-debcherry | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/git-debcherry b/git-debcherry
index b01e161..dac6f5c 100755
--- a/git-debcherry
+++ b/git-debcherry
@@ -171,6 +171,16 @@ git clone "$orig_git_dir" "$tmpdir"/clone 1>$log || _die
"clone failed"
export GIT_WORK_TREE=$tmpdir/clone
export GIT_DIR=$tmpdir/clone/.git
+# note that origin here is $orig_git_dir, so the following does
+# not do any network access
+if git fetch origin refs/notes/commits:refs/notes/commits >/dev/null 2>&1; then
+ debug "git notes found in the repository\n"
+ NOTES=true
+else
+ debug "no git notes found in the repository\n"
+ NOTES=false
+fi
+
tmp_upstream=$(tmpbranch upstream $upstream_sha1)
tmp_head=$(tmpbranch head $head_sha1)
@@ -187,9 +197,17 @@ _time $LINENO
{
# git-filter-branch doesn't really understand GIT_WORK_TREE
+# git_commit_non_empty_tree provided by git-filter-branch
cd $GIT_WORK_TREE
-if ! git filter-branch -f --prune-empty --index-filter \
+if ! git filter-branch -f --index-filter \
'git rm --ignore-unmatch --cached -r .pc debian' \
+ --commit-filter '\
+ NEW=$(git_commit_non_empty_tree "$@"); \
+ if $NOTES && [ -n "$NEW" ] && \
+ git notes show "$GIT_COMMIT" >/dev/null 2>&1 && \
+ ! git notes show "$NEW" >/dev/null 2>&1; then \
+ git notes copy "$GIT_COMMIT" "$NEW"; \
+ fi; echo "$NEW"' \
"$tmp_upstream".."$tmp_head" 1>$log 2>&1 ; then
_die "filtering failed"
fi
@@ -299,6 +317,9 @@ if [ -s $tmpdir/patch-list ]; then
fi
_die "cherry-pick $hash failed"
fi
+ if $NOTES && git notes show $hash >/dev/null 2>&1; then
+ git notes copy $hash HEAD;
+ fi
if [ -z "$(git diff $base)" ]; then
base=$(git rev-parse HEAD);
debug "new base ${base}"
@@ -313,7 +334,7 @@ else
if [ -n "$patch_dir" ]; then
mkdir -p "$patch_dir" || _die "mkdir failed";
echo "# exported from git by git-debcherry" > "$patch_dir/series"
- if PATCHES=$(git format-patch -o "$patch_dir" "$base"..HEAD ); then
+ if PATCHES=$(git format-patch --notes -o "$patch_dir" "$base"..HEAD );
then
if [ -n "$PATCHES" ]; then
echo "$PATCHES" | sed -e "s,$patch_dir/,,g" -e 's, ,\n,g' >>
"$patch_dir/series"
else
@@ -323,7 +344,7 @@ else
_die "git format-patch failed"
fi
else
- git format-patch --stdout $base..HEAD
+ git format-patch --notes --stdout $base..HEAD
fi
fi
--
2.1.4
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]