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

Re: [PATCH] filter-branch: resolve $commit^{tree} in no-index case

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jan 20, 2016, 01:22 UTC
Message-ID
<20160120012253.GD16090@google.com>
In-Reply-To
<20160119222802.GC6556@sigill.intra.peff.net>
Jeff King wrote:
> On Tue, Jan 19, 2016 at 04:59:28PM -0500, Jeff King wrote:
Show 11 quoted lines
>> We could get away "git diff --exit-code $1 $2" to do a single process
>> invocation (rather than two rev-parses), but I don't know if it is worth
>> the complexity.
>
> And here's that patch.
>
> I'm actually a little iffy on it because it switches to "diff-tree" from
> a raw-sha1 comparison. For a well-formed repo, that shouldn't matter.
> But what if you had a commit that was replacing a malformed tree object,
> but not otherwise changing the diff?  We might drop it as "empty", even
> though you'd prefer to keep it.

Mph. We could get the best of both worlds by introducing a "git rev-parse --compare <a> <b>" that compares object ids. Actually...

How about something like this?
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 git-filter-branch.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 86b2ff1..06f4e0f 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -44,7 +44,15 @@ skip_commit()
 # it will skip commits that leave the tree untouched, commit the other.
 git_commit_non_empty_tree()
 {
-	if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
+	if
+		test $# = 3 &&
+		git rev-parse "$1" "$3^{tree}" |
+		{
+			read a
+			read b
+			test "$a" = "$b"
+		}
+	then
 		map "$3"
 	else
 		git commit-tree "$@"
@@ -404,7 +412,7 @@ while read commit parents; do
 	then
 		tree=$(git write-tree)
 	else
-		tree=$(git rev-parse "$commit^{tree}")
+		tree="$commit^{tree}"
 	fi
 	workdir=$workdir @SHELL_PATH@ -c "$filter_commit" "git commit-tree" \
 		"$tree" $parentstr < ../message > ../map/$commit ||
-- 
2.7.0
Previous: Jeff KingNext: Jeff King
Message 12 of 19 in “git filter-branch not removing commits when it should in 2.7.0”
  1. John FultzJan 19, 2016
  2. Junio C HamanoJan 19, 2016
  3. Junio C HamanoJan 19, 2016
  4. Jeff KingJan 19, 2016
  5. Junio C HamanoJan 19, 2016
  6. filter-branch: resolve $commit^{tree} in no-index caseJeff King, Jan 19, 2016
  7. Jeff KingJan 19, 2016
  8. Jeff KingJan 19, 2016
  9. Junio C HamanoJan 19, 2016
  10. Jeff KingJan 19, 2016
  11. Jeff KingJan 19, 2016
  12. Jonathan NiederJan 20, 2016
  13. Jeff KingJan 20, 2016
  14. Junio C HamanoJan 20, 2016
  15. Jeff KingJan 20, 2016
  16. Junio C HamanoJan 20, 2016
  17. Junio C HamanoJan 20, 2016
  18. Jeff KingJan 20, 2016
  19. Jonathan NiederJan 20, 2016

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.