Re: Status of the svn remote helper project (Nov 2010, #2)

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

 



David Michael Barr wrote:
> Jonathan Nieder wrote:

>> A delta in r36 of <http://svn.apache.org/repos/asf> does not apply
>> with this brand of svn-fe.
>
> That's odd, I was able to import up to r354 before receiving:
> fatal: missing newline after cat-blob response

Apparently sometimes deltas use the whole preimage and sometimes they
don't.

Here's a fix (still needs a simple reproduction script).

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
diff --git a/test-svn-fe.c b/test-svn-fe.c
index 64f63cf..71de02b 100644
--- a/test-svn-fe.c
+++ b/test-svn-fe.c
@@ -11,7 +11,7 @@
 int main(int argc, char *argv[])
 {
 	static const char test_svnfe_usage[] =
-		"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)";
+		"test-svn-fe (<dumpfile> | [-d] <preimage> [<preimage len>] <delta> <len>)";
 	if (argc < 2)
 		usage(test_svnfe_usage);
 	if (argc == 2) {
@@ -22,16 +22,26 @@ int main(int argc, char *argv[])
 		svndump_reset();
 		return 0;
 	}
-	if (argc == 5 && !strcmp(argv[1], "-d")) {
+	if ((argc == 5 || argc == 6) && !strcmp(argv[1], "-d")) {
+		char **arg = argv + 2;
 		struct line_buffer delta = LINE_BUFFER_INIT;
-		int preimage_fd = open(argv[2], O_RDONLY);
+		int preimage_fd = open(*arg++, O_RDONLY);
 		struct view preimage_view = {preimage_fd, 0, STRBUF_INIT};
+		off_t preimage_len;
 		if (preimage_fd < 0)
 			die_errno("cannot open preimage");
-		if (buffer_init(&delta, argv[3]))
+		if (argc == 6) {
+			preimage_len = (off_t) strtoull(*arg++, NULL, 0);
+		} else {
+			struct stat st;
+			if (fstat(preimage_fd, &st))
+				die_errno("cannot stat preimage");
+			preimage_len = st.st_size;
+		}
+		if (buffer_init(&delta, *arg++))
 			die_errno("cannot open delta");
-		if (svndiff0_apply(&delta, (off_t) strtoull(argv[4], NULL, 0),
-				   &preimage_view, stdout))
+		if (svndiff0_apply(&delta, (off_t) strtoull(*arg++, NULL, 0),
+				   &preimage_view, preimage_len, stdout))
 			return 1;
 		if (close(preimage_fd))
 			die_errno("cannot close preimage");
diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c
index ceb1fc5..02456cf 100644
--- a/vcs-svn/fast_export.c
+++ b/vcs-svn/fast_export.c
@@ -119,6 +119,7 @@ static long apply_delta(uint32_t mark, off_t len, struct line_buffer *input,
 			uint32_t old_mark, uint32_t old_mode)
 {
 	long ret;
+	off_t preimage_len = 0;
 	struct view preimage = {REPORT_FILENO, 0, STRBUF_INIT};
 	FILE *out;
 
@@ -130,13 +131,12 @@ static long apply_delta(uint32_t mark, off_t len, struct line_buffer *input,
 		printf("cat-blob :%"PRIu32"\n", old_mark);
 		fflush(stdout);
 		response = get_response_line();
-		/* Not necessary, just for robustness */
-		if (parse_cat_response_line(response, &dummy))
+		if (parse_cat_response_line(response, &preimage_len))
 			die("invalid cat-blob response: %s", response);
 	}
 	if (old_mode == REPO_MODE_LNK)
 		strbuf_addstr(&preimage.buf, "link ");
-	if (svndiff0_apply(input, len, &preimage, out))
+	if (svndiff0_apply(input, len, &preimage, preimage_len, out))
 		die("cannot apply delta");
 	if (old_mark) {
 		/* Discard trailing newline from cat-blob-fd. */
diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c
index 308c734..8210561 100644
--- a/vcs-svn/svndiff.c
+++ b/vcs-svn/svndiff.c
@@ -283,7 +283,8 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len,
 }
 
 int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
-			struct view *preimage_view, FILE *postimage)
+			struct view *preimage_view, off_t preimage_len,
+			FILE *postimage)
 {
 	assert(delta && preimage_view && postimage);
 
@@ -302,5 +303,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
 			return error("Delta ends early! (%"PRIu64" bytes remaining)",
 			      (uint64_t) delta_len);
 	}
+	if (move_window(preimage_view, preimage_len, 0))
+		return -1;
 	return 0;
 }
diff --git a/vcs-svn/svndiff.h b/vcs-svn/svndiff.h
index bb5afd0..640e04f 100644
--- a/vcs-svn/svndiff.h
+++ b/vcs-svn/svndiff.h
@@ -5,6 +5,7 @@
 #include "sliding_window.h"
 
 extern int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
-				struct view *preimage_view, FILE *postimage);
+				struct view *preimage_view, off_t preimage_len,
+				FILE *postimage);
 
 #endif
--
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]