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

Re: [PATCH] Teach git-apply about '-R'

From
Junio C Hamano <junkio@cox.net>
Date
Jul 28, 2006, 19:20 UTC
Message-ID
<7vhd11leny.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0607281748390.29667@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 7 quoted lines
> On Fri, 28 Jul 2006, Junio C Hamano wrote:
>> 
>> A quick comment without looking much at the code.  Do you sanely
>> bail out when asked to reverse-apply a binary patch?
>
> Nope. I swap old_sha1_prefix and new_sha1_prefix in that case, I hoped 
> that is enough?

You would need something like this, at least for now, since both deflated literal and deflated delta methods are irreversible. I'll cook up another binary diff output that can go bidirectional.

Note that --allow-binary-replacement uses the blob object name recorded on index lines of binary patch, and uses it to cheat (iow, when it knows your version is the old version recorded on index line and your repository happens to have the resulting blob, it just uses the blob without looking at the binary contents recorded in the patch), so you have to work a bit hard to cause it to fail in t/trash repository after you run t4103 test. Resetting to "master", apply BF.diff, and immediately reverse apply BF.diff would _work_, only because "master" and "binary" branch keep both preimage and postimage.

-- >8 --
diff --git a/builtin-apply.c b/builtin-apply.c
index 6b38a8a..d4381d9 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1535,6 +1535,12 @@ static int apply_binary_fragment(struct 
 	void *data;
 	void *result;
 
+	/* Binary patch is irreversible */
+	if (patch->is_reverse)
+		return error("cannot reverse-apply a binary patch to '%s'",
+			     patch->new_name
+			     ? patch->new_name : patch->old_name);
+
 	data = inflate_it(fragment->patch, fragment->size,
 			  patch->deflate_origlen);
 	if (!data)
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 21 of 22 in “t7001: add test for git-mv dir1 dir2/”
  1. 1/2 t7001: add test for git-mv dir1 dir2/Johannes Schindelin, Jul 26, 2006
  2. Jon SmirlJul 26, 2006
  3. Junio C HamanoJul 26, 2006
  4. Jon SmirlJul 26, 2006
  5. Junio C HamanoJul 26, 2006
  6. Junio C HamanoJul 26, 2006
  7. Jon SmirlJul 26, 2006
  8. Johannes SchindelinJul 26, 2006
  9. Josef WeidendorferJul 26, 2006
  10. Junio C HamanoJul 26, 2006
  11. Petr BaudisJul 28, 2006
  12. Junio C HamanoJul 28, 2006
  13. Petr BaudisJul 28, 2006
  14. Junio C HamanoJul 28, 2006
  15. Petr BaudisJul 28, 2006
  16. Teach git-apply about '-R'Johannes Schindelin, Jul 28, 2006
  17. Linus TorvaldsJul 28, 2006
  18. Teach git-apply about '-R'Johannes Schindelin, Jul 28, 2006
  19. Junio C HamanoJul 28, 2006
  20. Johannes SchindelinJul 28, 2006
  21. Junio C HamanoJul 28, 2006
  22. Johannes SchindelinJul 28, 2006

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.