Teach the svndiff routines to read the preimage for a delta from a file descriptor without reading ahead. This way, the delta applier can stream its input directly from fast-import's cat-blob-fd pipe. Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx> --- test-svn-fe.c | 10 +++++----- vcs-svn/sliding_window.c | 21 +++++++++------------ vcs-svn/sliding_window.h | 2 +- vcs-svn/svndiff.c | 6 +++--- vcs-svn/svndiff.h | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/test-svn-fe.c b/test-svn-fe.c index 4799e4c..4ea0cd6 100644 --- a/test-svn-fe.c +++ b/test-svn-fe.c @@ -22,20 +22,20 @@ int main(int argc, char *argv[]) return 0; } if (argc == 5 && !strcmp(argv[1], "-d")) { - struct line_buffer preimage = LINE_BUFFER_INIT; + int preimage_fd = -1; struct line_buffer delta = LINE_BUFFER_INIT; - if (buffer_init(&preimage, argv[2])) + preimage_fd = open(argv[2], O_RDONLY); + 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, stdout)) + preimage_fd, stdout)) return 1; - if (buffer_deinit(&preimage)) + if (close(preimage_fd)) die_errno("cannot close preimage"); if (buffer_deinit(&delta)) die_errno("cannot close delta"); - buffer_reset(&preimage); buffer_reset(&delta); return 0; } diff --git a/vcs-svn/sliding_window.c b/vcs-svn/sliding_window.c index 5c08828..6d4261a 100644 --- a/vcs-svn/sliding_window.c +++ b/vcs-svn/sliding_window.c @@ -5,7 +5,7 @@ #include "git-compat-util.h" #include "sliding_window.h" -#include "line_buffer.h" +#include "fd_buffer.h" #include "strbuf.h" static void strbuf_remove_from_left(struct strbuf *sb, size_t nbytes) @@ -30,7 +30,7 @@ static int check_overflow(off_t a, size_t b) int move_window(struct view *view, off_t off, size_t len) { off_t file_offset; - assert(view && view->file); + assert(view && view->fd >= 0); assert(!check_overflow(view->off, view->buf.len)); if (check_overflow(off, len)) @@ -47,21 +47,18 @@ int move_window(struct view *view, off_t off, size_t len) if (off > file_offset) { /* Seek ahead to skip the gap. */ const off_t gap = off - file_offset; - const off_t nread = buffer_skip_bytes(view->file, gap); + const off_t nread = fd_skip_bytes(view->fd, gap); if (nread != gap) { - if (!buffer_ferror(view->file)) + if (!nread) return error("Preimage ends early"); - return error("Cannot seek forward in input: %s", - strerror(errno)); + return error("Cannot seek forward in input"); } file_offset += gap; } - buffer_read_binary(&view->buf, len - view->buf.len, view->file); - if (view->buf.len != len) { - if (!buffer_ferror(view->file)) - return error("Preimage ends early"); - return error("Cannot read preimage: %s", strerror(errno)); - } + if (fd_read_binary(&view->buf, len - view->buf.len, view->fd)) + return error("Cannot read preimage"); + if (view->buf.len != len) + return error("Preimage ends early"); view->off = off; return 0; } diff --git a/vcs-svn/sliding_window.h b/vcs-svn/sliding_window.h index b9f0552..532dc93 100644 --- a/vcs-svn/sliding_window.h +++ b/vcs-svn/sliding_window.h @@ -4,7 +4,7 @@ #include "strbuf.h" struct view { - struct line_buffer *file; + int fd; off_t off; struct strbuf buf; }; diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c index 9ee7411..ef3a921 100644 --- a/vcs-svn/svndiff.c +++ b/vcs-svn/svndiff.c @@ -283,10 +283,10 @@ 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 line_buffer *preimage, FILE *postimage) + int preimage_fd, FILE *postimage) { - struct view preimage_view = {preimage, 0, STRBUF_INIT}; - assert(delta && preimage && postimage); + struct view preimage_view = {preimage_fd, 0, STRBUF_INIT}; + assert(delta && preimage_fd >= 0 && postimage); if (read_magic(delta, &delta_len)) goto fail; diff --git a/vcs-svn/svndiff.h b/vcs-svn/svndiff.h index a986099..9003d6e 100644 --- a/vcs-svn/svndiff.h +++ b/vcs-svn/svndiff.h @@ -4,6 +4,6 @@ #include "line_buffer.h" extern int svndiff0_apply(struct line_buffer *delta, off_t delta_len, - struct line_buffer *preimage, FILE *postimage); + int preimage_fd, 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