git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Devin J. Pohly" <djpohly@gmail.com>
To: git@vger.kernel.org
Cc: "Devin J. Pohly" <djpohly@gmail.com>
Subject: [PATCH 3/4] filter-branch: fix --prune-empty on parentless commits
Date: Thu, 23 Feb 2017 02:27:35 -0600	[thread overview]
Message-ID: <20170223082736.31283-3-djpohly@gmail.com> (raw)
In-Reply-To: <20170223082736.31283-1-djpohly@gmail.com>

Previously, the git_commit_non_empty_tree function would always pass any
commit with no parents to git-commit-tree, regardless of whether the
tree was nonempty.  The new commit would then be recorded in the
filter-branch revision map, and subsequent commits which leave the tree
untouched would be correctly filtered.

With this change, parentless commits with an empty tree are correctly
pruned, and an empty file is recorded in the revision map, signifying
that it was rewritten to "no commits."  This works naturally with the
parent mapping for subsequent commits.

Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
---
 Documentation/git-filter-branch.txt | 14 ++++++--------
 git-filter-branch.sh                |  2 ++
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 0a09698c0..6e4bb0220 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -167,14 +167,12 @@ to other tags will be rewritten to point to the underlying commit.
 	project root. Implies <<Remap_to_ancestor>>.
 
 --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.
+	Some filters will generate empty commits that leave the tree untouched.
+	This option instructs git-filter-branch to remove such commits if they
+	have exactly one or zero non-pruned parents; merge commits will
+	therefore remain intact.  This option cannot be used together with
+	`--commit-filter`, though the same effect can be achieved by using the
+	provided `git_commit_non_empty_tree` function in a commit filter.
 
 --original <namespace>::
 	Use this option to set the namespace where the original commits
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86b2ff1e0..2b8cdba15 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -46,6 +46,8 @@ git_commit_non_empty_tree()
 {
 	if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
 		map "$3"
+	elif test $# = 1 && test "$1" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904; then
+		:
 	else
 		git commit-tree "$@"
 	fi
-- 
2.11.1


  parent reply	other threads:[~2017-02-23  8:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23  8:27 [PATCH 1/4] t7003: ensure --prune-empty can prune root commit Devin J. Pohly
2017-02-23  8:27 ` [PATCH 2/4] t7003: ensure --prune-empty removes entire branch when applicable Devin J. Pohly
2017-02-23  8:27 ` Devin J. Pohly [this message]
2017-02-23 21:17   ` [PATCH 3/4] filter-branch: fix --prune-empty on parentless commits Junio C Hamano
2017-02-23 21:33     ` Devin J. Pohly
2017-03-02 19:36       ` Junio C Hamano
2017-03-02 21:18         ` Devin J. Pohly
2017-03-02 21:39           ` Junio C Hamano
2017-03-02 23:28         ` Jacob Keller
2017-03-03  7:55         ` Jeff King
2017-03-03 20:30           ` Devin J. Pohly
2017-03-03 20:43           ` Junio C Hamano
2017-02-23  8:27 ` [PATCH 4/4] p7000: add test for filter-branch with --prune-empty Devin J. Pohly
2017-03-03  7:56   ` Jeff King
2017-03-03 20:34     ` Devin J. Pohly

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170223082736.31283-3-djpohly@gmail.com \
    --to=djpohly@gmail.com \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).