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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]