git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] filter-branch: fix --prune-empty on parentless commits

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 23, 2017, 21:17 UTC
Message-ID
<xmqqbmts7gjm.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170223082736.31283-3-djpohly@gmail.com>
"Devin J. Pohly" <djpohly@gmail.com> writes:
Show 13 quoted lines
> 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>
> ---

I am not sure if a root that records an empty tree should be pruned with --prune-empty to begin with.

When we are pruning consecutive commits in the other parts of the history because they have identical (presumably non-empty) trees, should an empty root that the original history wanted to create be pruned because before the commit it was void, after the commit it is empty? Should "void" (lack of any tree) and "empty" (the tree is there, but it does not have anything in it) be treated the same? Shouldn't root be treated as a bit more special thing?

I myself do not have a good answer to the above questions.

I think the updated code makes sense, provided if we decide that void to empty is just like transitioning between two identical (presumably non-empty) trees. The updated documentation is a lot more readable as well.

Comments from those who have been involved in filter-branch?
Show 42 quoted lines
>  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
Previous: Devin J. PohlyNext: Devin J. Pohly
Message 4 of 15 in “t7003: ensure --prune-empty can prune root commit”
  1. 1/4 t7003: ensure --prune-empty can prune root commitDevin J. Pohly, Feb 23, 2017
  2. 2/4 t7003: ensure --prune-empty removes entire branch when applicableDevin J. Pohly, Feb 23, 2017
  3. 3/4 filter-branch: fix --prune-empty on parentless commitsDevin J. Pohly, Feb 23, 2017
  4. Junio C HamanoFeb 23, 2017
  5. Devin J. PohlyFeb 23, 2017
  6. Junio C HamanoMar 2, 2017
  7. Devin J. PohlyMar 2, 2017
  8. Junio C HamanoMar 2, 2017
  9. Jacob KellerMar 2, 2017
  10. Jeff KingMar 3, 2017
  11. Devin J. PohlyMar 3, 2017
  12. Junio C HamanoMar 3, 2017
  13. 4/4 p7000: add test for filter-branch with --prune-emptyDevin J. Pohly, Feb 23, 2017
  14. Jeff KingMar 3, 2017
  15. Devin J. PohlyMar 3, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.