From: Pierre Habouzit <madcoder@debian.org>
To: git@vger.kernel.org
Cc: pasky@suse.cz, srabbelier@gmail.com,
Pierre Habouzit <madcoder@debian.org>
Subject: [Proof of concept PATCH] implement --prune-empty switch for filter-branch
Date: Thu, 30 Oct 2008 17:18:58 +0100 [thread overview]
Message-ID: <1225383538-23666-3-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <1225383538-23666-2-git-send-email-madcoder@debian.org>
This is not a real patch (lacks a test at least) and is absolutely not
tested, though should basically work as expected.
This is only meant as a basis for discussion.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
Documentation/git-filter-branch.txt | 14 ++++++++++++++
git-filter-branch.sh | 26 +++++++++++++++++++++++++-
2 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index fed6de6..451950b 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -122,6 +122,10 @@ You can use the 'map' convenience function in this filter, and other
convenience functions, too. For example, calling 'skip_commit "$@"'
will leave out the current commit (but not its changes! If you want
that, use 'git-rebase' instead).
++
+You can also use the 'git_commit_non_empty_tree "$@"' instead of
+'git commit-tree "$@"' if you don't wish to keep commits with a single parent
+and that makes no change to the tree.
--tag-name-filter <command>::
This is the filter for rewriting tag names. When passed,
@@ -151,6 +155,16 @@ to other tags will be rewritten to point to the underlying commit.
The result will contain that directory (and only that) as its
project root.
+--prune-empty::
+ Some kind of filters will generate empty commits, that left the tree
+ untouched. This switch allow git-filter-branch to ignore such
+ commits. Though, this switch only applies for commits that have one
+ and only one parent, it will hence keep merges points. Also, this
+ option is not compatible with the use of '--commit-filter'. Though you
+ just need to use the function 'git_commit_non_empty_tree "$@"' instead
+ of the 'git commit-tree "$@"' idiom in your commit filter to make that
+ happen.
+
--original <namespace>::
Use this option to set the namespace where the original commits
will be stored. The default value is 'refs/original'.
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 8af3126..9c83402 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -49,6 +49,15 @@ die()
echo "$*" >&2
exit 1
}
+
+git_commit_non_empty_tree()
+{
+ if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
+ map "$3"
+ else
+ git commit-tree "$@"
+ fi
+}
EOF
)
@@ -95,6 +104,7 @@ d= temporary path to use for rewriting
f,force force filter-branch to run
subdirectory-filter= only look at the history touching that specific subdirectory
original= namespace where the original commits will be stored (default: refs/original)
+prune-empty use this if you want to automatically prune empty commits
Filters that you can run:
@@ -121,11 +131,12 @@ filter_tree=
filter_index=
filter_parent=
filter_msg=cat
-filter_commit='git commit-tree "$@"'
+filter_commit=
filter_tag_name=
filter_subdir=
orig_namespace=refs/original/
force=
+prune_empty=
while :
do
case "$1" in
@@ -138,6 +149,8 @@ do
--original)
orig_namespace=$(expr "$2/" : '\(.*[^/]\)/*$')/
shift;;
+ --prune-empty)
+ prune_empty=t;;
--env-filter)
filter_env="$2"; shift;;
@@ -161,6 +174,17 @@ do
shift
done
+case "$prune_empty,$filter_commit" in
+',')
+ filter_commit='git commit-tree "$@"';;
+'t,')
+ filter_commit='git_commit_non_empty_tree "$@"';;
+','*)
+ ;;
+*)
+ die "Cannot set --prune-empty and --filter-commit at the same time"
+esac
+
case "$force" in
t)
rm -rf "$tempdir"
--
1.6.0.3.758.gc29b0
next prev parent reply other threads:[~2008-10-30 16:20 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-30 0:33 [PATCH] git-filter-branch: Add an example on how to remove empty commits Petr Baudis
2008-10-30 0:39 ` Sam Vilain
2008-10-30 0:56 ` Johannes Schindelin
2008-10-30 13:26 ` Pierre Habouzit
2008-10-30 15:06 ` Deskin Miller
2008-10-30 15:10 ` Pierre Habouzit
2008-10-30 16:18 ` filter-branch enhancements Pierre Habouzit
2008-10-30 16:18 ` [PATCH] make git-filter-branch use parse-options Pierre Habouzit
2008-10-30 16:18 ` Pierre Habouzit [this message]
2008-10-31 8:22 ` Pierre Habouzit
2008-10-31 9:26 ` [PATCH] filter-branch: add git_commit_non_empty_tree and --prune-empty Pierre Habouzit
2008-10-31 22:36 ` Johannes Schindelin
2008-10-31 22:42 ` Pierre Habouzit
2008-11-03 4:58 ` Junio C Hamano
2008-11-03 9:27 ` Pierre Habouzit
2008-11-03 15:18 ` Pierre Habouzit
2009-01-09 19:29 ` Jay Soffian
2009-01-11 11:18 ` Pierre Habouzit
2009-01-11 13:35 ` Johannes Schindelin
2009-01-11 14:27 ` Pierre Habouzit
2009-01-11 14:40 ` Sverre Rabbelier
2009-01-11 14:55 ` Pierre Habouzit
2009-01-11 15:08 ` Sverre Rabbelier
2009-01-11 20:52 ` Junio C Hamano
2009-01-11 20:55 ` Johannes Schindelin
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=1225383538-23666-3-git-send-email-madcoder@debian.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=pasky@suse.cz \
--cc=srabbelier@gmail.com \
/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).