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

[PATCH 6/8] vcs-svn: Let caller set up sliding window for delta preimage

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 20, 2010, 19:28 UTC
Message-ID
<20101120192845.GG17823@burratino>
In-Reply-To
<20101120192153.GA17823@burratino>

The content of symlinks starts with the word "link " in SVN's worldview, so we need to prepend that text the sake of delta application. Move responsibility for setting up the input state from svndiff0_apply to the calling program, so programs have a chance to seed the sliding window with text of their choice.

[jn: extracted from the patch "svn-fe: Use the --report-fd feature"]
Signed-off-by: David Barr <david.barr@cordelta.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
I'm a big fan of this trick.
 test-svn-fe.c     |    8 +++++---
 vcs-svn/svndiff.c |   23 ++++++++---------------
 vcs-svn/svndiff.h |    3 ++-
 3 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/test-svn-fe.c b/test-svn-fe.c
index 4ea0cd6..64f63cf 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -5,6 +5,7 @@
 #include "git-compat-util.h"
 #include "vcs-svn/svndump.h"
 #include "vcs-svn/svndiff.h"
+#include "vcs-svn/sliding_window.h"
 #include "vcs-svn/line_buffer.h"
 
 int main(int argc, char *argv[])
@@ -22,20 +23,21 @@ int main(int argc, char *argv[])
 		return 0;
 	}
 	if (argc == 5 && !strcmp(argv[1], "-d")) {
-		int preimage_fd = -1;
 		struct line_buffer delta = LINE_BUFFER_INIT;
-		preimage_fd = open(argv[2], O_RDONLY);
+		int preimage_fd = open(argv[2], O_RDONLY);
+		struct view preimage_view = {preimage_fd, 0, STRBUF_INIT};
 		if (preimage_fd < 0)
 			die_errno("cannot open preimage");
 		if (buffer_init(&delta, argv[3]))
 			die_errno("cannot open delta");
 		if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
-				   preimage_fd, stdout))
+				   &preimage_view, stdout))
 			return 1;
 		if (close(preimage_fd))
 			die_errno("cannot close preimage");
 		if (buffer_deinit(&delta))
 			die_errno("cannot close delta");
+		strbuf_release(&preimage_view.buf);
 		buffer_reset(&delta);
 		return 0;
 	}
diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c
index ef3a921..308c734 100644
--- a/vcs-svn/svndiff.c
+++ b/vcs-svn/svndiff.c
@@ -283,31 +283,24 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len,
 }
 
 int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
-		   int preimage_fd, FILE *postimage)
+			struct view *preimage_view, FILE *postimage)
 {
-	struct view preimage_view = {preimage_fd, 0, STRBUF_INIT};
-	assert(delta && preimage_fd >= 0 && postimage);
+	assert(delta && preimage_view && postimage);
 
 	if (read_magic(delta, &delta_len))
-		goto fail;
+		return -1;
 	while (delta_len > 0) {	/* For each window: */
 		off_t pre_off = pre_off;
 		size_t pre_len;
 		if (read_offset(delta, &pre_off, &delta_len) ||
 		    read_length(delta, &pre_len, &delta_len) ||
-		    move_window(&preimage_view, pre_off, pre_len) ||
+		    move_window(preimage_view, pre_off, pre_len) ||
 		    apply_one_window(delta, &delta_len,
-				     &preimage_view, postimage))
-			goto fail;
-		if (delta_len && buffer_at_eof(delta)) {
-			error("Delta ends early! (%"PRIu64" bytes remaining)",
+				     preimage_view, postimage))
+			return -1;
+		if (delta_len && buffer_at_eof(delta))
+			return error("Delta ends early! (%"PRIu64" bytes remaining)",
 			      (uint64_t) delta_len);
-			goto fail;
-		}
 	}
-	strbuf_release(&preimage_view.buf);
 	return 0;
- fail:
-	strbuf_release(&preimage_view.buf);
-	return -1;
 }
diff --git a/vcs-svn/svndiff.h b/vcs-svn/svndiff.h
index 9003d6e..bb5afd0 100644
--- a/vcs-svn/svndiff.h
+++ b/vcs-svn/svndiff.h
@@ -2,8 +2,9 @@
 #define SVNDIFF_H_
 
 #include "line_buffer.h"
+#include "sliding_window.h"
 
 extern int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
-				int preimage_fd, FILE *postimage);
+				struct view *preimage_view, FILE *postimage);
 
 #endif
-- 
1.7.2.3
Previous: Jonathan NiederNext: Jonathan Nieder
Message 33 of 40 in “svn-fe: recognize v3 dumps”
  1. 0/2 svn-fe: recognize v3 dumpsJonathan Nieder, Nov 18, 2010
  2. 1/2 vcs-svn: Error out for v3 dumpsJonathan Nieder, Nov 18, 2010
  3. 2/2 vcs-svn: Allow simple v3 dumps (no deltas yet)Jonathan Nieder, Nov 18, 2010
  4. 0/15 svn-fe: support for property deltas (but not text deltas yet)Jonathan Nieder, Nov 20, 2010
  5. 01/15 vcs-svn: Check for errors from open()Jonathan Nieder, Nov 20, 2010
  6. 02/15 vcs-svn: Eliminate node_ctx.srcRev globalJonathan Nieder, Nov 20, 2010
  7. 03/15 vcs-svn: Eliminate node_ctx.mark globalJonathan Nieder, Nov 20, 2010
  8. 04/15 vcs-svn: Unclutter handle_node by introducing have_props varJonathan Nieder, Nov 20, 2010
  9. 05/15 vcs-svn: Use mark to indicate nodes with included textJonathan Nieder, Nov 20, 2010
  10. 06/15 vcs-svn: handle_node: Handle deletion case earlyJonathan Nieder, Nov 20, 2010
  11. 07/15 vcs-svn: Replace = Delete + AddJonathan Nieder, Nov 20, 2010
  12. 08/15 vcs-svn: Combine repo_replace and repo_modify functionsJonathan Nieder, Nov 20, 2010
  13. 09/15 vcs-svn: Delay read of per-path propertiesJonathan Nieder, Nov 20, 2010
  14. 10/15 vcs-svn: Reject path nodes without Node-actionJonathan Nieder, Nov 20, 2010
  15. Jonathan NiederNov 20, 2010
  16. 11/15 vcs-svn: More dump format sanity checksJonathan Nieder, Nov 20, 2010
  17. Jonathan NiederNov 30, 2010
  18. 0/2 intermittent repo_tree corruptionJonathan Nieder, Dec 5, 2010
  19. 1/2 treap: make treap_insert return inserted nodeJonathan Nieder, Dec 5, 2010
  20. vcs-svn: Allow change nodes for root of tree (/)Jonathan Nieder, Dec 6, 2010
  21. Jonathan NiederDec 6, 2010
  22. 12/15 vcs-svn: Make source easier to read on small screensJonathan Nieder, Nov 20, 2010
  23. 13/15 vcs-svn: Split off function for handling of individual propertiesJonathan Nieder, Nov 20, 2010
  24. 14/15 vcs-svn: Sharpen parsing of property linesJonathan Nieder, Nov 20, 2010
  25. 15/15 vcs-svn: Implement Prop-delta handlingJonathan Nieder, Nov 20, 2010
  26. 0/8 svn-fe: support for text deltasJonathan Nieder, Nov 20, 2010
  27. 1/8 svn-fe: Prepare for strbuf useJonathan Nieder, Nov 20, 2010
  28. 2/8 vcs-svn: Internal fast_export_save_blob helperJonathan Nieder, Nov 20, 2010
  29. 3/8 vcs-svn: Introduce repo_read_path to check the content at a pathJonathan Nieder, Nov 20, 2010
  30. Jonathan NiederMar 6, 2011
  31. 4/8 vcs-svn: Introduce fd_buffer routinesJonathan Nieder, Nov 20, 2010
  32. 5/8 vcs-svn: Read delta preimage from file descriptorJonathan Nieder, Nov 20, 2010
  33. 6/8 vcs-svn: Let caller set up sliding window for delta preimageJonathan Nieder, Nov 20, 2010
  34. Jonathan NiederNov 20, 2010
  35. 7/8 vcs-svn: Teach line_buffer about temporary filesJonathan Nieder, Nov 20, 2010
  36. 8/8 vcs-svn: Implement text-delta handlingJonathan Nieder, Nov 20, 2010
  37. 10/8 vcs-svn: Consume whole preimage when applying deltasJonathan Nieder, Dec 4, 2010
  38. 9/8 svn-fe: Test script for handling of dumps with --deltasJonathan Nieder, Nov 20, 2010
  39. Jonathan NiederDec 4, 2010
  40. 2/2 vcs-svn: fix intermittent repo_tree corruptionJonathan Nieder, Dec 5, 2010

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.