-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vcs-svn: skeleton of an svn delta parser
A delta in the subversion delta (svndiff0) format consists of the magic bytes SVN\0 followed by a sequence of windows of a certain well specified format (starting with five integers). Add an svndiff0_apply function and test-svn-fe -d commandline tool to parse such a delta in the special case of not including any windows. Later patches will add features to turn this into a fully functional delta applier for svn-fe to use to parse the streams produced by "svnrdump dump" and "svnadmin dump --deltas". The content of symlinks starts with the word "link " in Subversion's worldview, so we need to be able to prepend that text to input for the sake of delta application. So initialization of the input state of the delta preimage is left to the calling program, giving callers a chance to seed the buffer with text of their choice. Improved-by: Ramkumar Ramachandra <artagnon@gmail.com> Improved-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
- Loading branch information
Jonathan Nieder
committed
Mar 28, 2011
1 parent
896e4bf
commit ddcc8c5
Showing
5 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
test_description='test parsing of svndiff0 files | ||
Using the "test-svn-fe -d" helper, check that svn-fe correctly | ||
interprets deltas using various facilities (some from the spec, | ||
some only learned from practice). | ||
' | ||
. ./test-lib.sh | ||
|
||
>empty | ||
printf foo >preimage | ||
|
||
test_expect_success 'reject empty delta' ' | ||
test_must_fail test-svn-fe -d preimage empty 0 | ||
' | ||
|
||
test_expect_success 'delta can empty file' ' | ||
printf "SVNQ" | q_to_nul >clear.delta && | ||
test-svn-fe -d preimage clear.delta 4 >actual && | ||
test_cmp empty actual | ||
' | ||
|
||
test_expect_success 'reject svndiff2' ' | ||
printf "SVN\002" >bad.filetype && | ||
test_must_fail test-svn-fe -d preimage bad.filetype 4 | ||
' | ||
|
||
test_expect_failure 'one-window empty delta' ' | ||
printf "SVNQ%s" "QQQQQ" | q_to_nul >clear.onewindow && | ||
test-svn-fe -d preimage clear.onewindow 9 >actual && | ||
test_cmp empty actual | ||
' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed under a two-clause BSD-style license. | ||
* See LICENSE for details. | ||
*/ | ||
|
||
#include "git-compat-util.h" | ||
#include "line_buffer.h" | ||
#include "svndiff.h" | ||
|
||
/* | ||
* svndiff0 applier | ||
* | ||
* See http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff. | ||
* | ||
* svndiff0 ::= 'SVN\0' window* | ||
*/ | ||
|
||
static int error_short_read(struct line_buffer *input) | ||
{ | ||
if (buffer_ferror(input)) | ||
return error("error reading delta: %s", strerror(errno)); | ||
return error("invalid delta: unexpected end of file"); | ||
} | ||
|
||
static int read_magic(struct line_buffer *in, off_t *len) | ||
{ | ||
static const char magic[] = {'S', 'V', 'N', '\0'}; | ||
struct strbuf sb = STRBUF_INIT; | ||
|
||
if (*len < sizeof(magic) || | ||
buffer_read_binary(in, &sb, sizeof(magic)) != sizeof(magic)) | ||
return error_short_read(in); | ||
|
||
if (memcmp(sb.buf, magic, sizeof(magic))) | ||
return error("invalid delta: unrecognized file type"); | ||
|
||
*len -= sizeof(magic); | ||
strbuf_release(&sb); | ||
return 0; | ||
} | ||
|
||
int svndiff0_apply(struct line_buffer *delta, off_t delta_len, | ||
struct sliding_view *preimage, FILE *postimage) | ||
{ | ||
assert(delta && preimage && postimage); | ||
|
||
if (read_magic(delta, &delta_len)) | ||
return -1; | ||
if (delta_len) | ||
return error("What do you think I am? A delta applier?"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef SVNDIFF_H_ | ||
#define SVNDIFF_H_ | ||
|
||
struct line_buffer; | ||
struct sliding_view; | ||
|
||
extern int svndiff0_apply(struct line_buffer *delta, off_t delta_len, | ||
struct sliding_view *preimage, FILE *postimage); | ||
|
||
#endif |