svn-fe: recognize v3 dumps
cover svn-fe: recognize v3 dumps
This mini-series is part of an effort to get David and Ram's svn import work integrated into mainline git[1]. It fixes a longstanding svn-fe bug that bit me a few times: when fed v3 (= --deltas) dumps, current svn-fe produces nonsense --- a directory full of svn-format deltas --- rather than erroring out. For example:
; git init
; svnrdump dump -r1:10 http://cvs2svn.tigris.org/svn/cvs2svn |
svn-fe |
git fast-import
; git show HEAD:trunk/README
SVN^@^@^@M-^N^D^CM-^N^DM-^@M-^N^DThis is a program to convert a CVS repository to Subversion.
After this series, svn-fe would instead die with the message "fatal:
text and property deltas not supported".
Ram and David: this code will probably look familiar. It is roughly based on David's "vcs-svn: Extend svndump to parse version 3 format" from about a month ago[2]. I would be particularly interested in hearing whether this still seems sensible in design and execution, so it can be deployed to a wider audience with your blessing if appropriate.
Thoughts? Improvements?
David Barr (1):
vcs-svn: Allow simple v3 dumps (no deltas yet)
Jonathan Nieder (1):
vcs-svn: Error out for v3 dumps
t/t9010-svn-fe.sh | 403 ++++++++++++++++++++++++++++++++++++++++++++++++++--- vcs-svn/svndump.c | 28 ++++- 2 files changed, 406 insertions(+), 25 deletions(-)
[1] http://thread.gmane.org/gmane.comp.version-control.git/160875
The dumpfile v3 code proper has been proving more trouble to review than anticipated. Mostly because it involves tracking down details of the svn repository model that aren't clearly documented in any obvious place:
* What do the five node actions (replace, delete, add, modify, unknown) represent? How can we deal with them without repeating the same code four times?
* Which actions preserve properties? Which preserve text?
[2] http://thread.gmane.org/gmane.comp.version-control.git/159117/focus=159114
PATCH 1/2 vcs-svn: Error out for v3 dumps
By ignoring the Text-Delta and Prop-Delta node fields, current svn-fe happily mistakes deltas for full text and instead of cleanly erroring out, it produces a valid but semantically bogus fast-import stream when fed a dump file in the modern "svnadmin dump --deltas" format.
Dump file parsers are supposed to ignore header fields they don't understand (to allow for backward-compatible extensions), but they are also supposed to check the SVN-fs-dump-format-version header to prevent misinterpretation of non backward-compatible extensions. Do so.
--- t/t9010-svn-fe.sh | 59 +++++++++++++++++++++++++++++++++------------------- vcs-svn/svndump.c | 13 +++++++++-- 2 files changed, 47 insertions(+), 25 deletions(-)
t/t9010-svn-fe.sh +37 -22
@@ -4,29 +4,44 @@ test_description='check svn dumpfile importer' . ./lib-git-svn.sh -test_dump() { - label=$1 - dump=$2 - test_expect_success "$dump" ' - svnadmin create "$label-svn" && - svnadmin load "$label-svn" < "$TEST_DIRECTORY/$dump" && - svn_cmd export "file://$PWD/$label-svn" "$label-svnco" && - git init "$label-git" && - test-svn-fe "$TEST_DIRECTORY/$dump" >"$label.fe" && - ( - cd "$label-git" && - git fast-import < ../"$label.fe" - ) && - ( - cd "$label-svnco" && - git init && - git add . && - git fetch "../$label-git" master && - git diff --exit-code FETCH_HEAD - ) - ' +reinit_git () { + rm -fr .git && + git init } -test_dump simple t9135/svn.dump +>empty + +test_expect_success 'empty dump' ' + reinit_git && + echo "SVN-fs-dump-format-version: 2" >input && + test-svn-fe input >stream && + git fast-import <stream +' + +test_expect_success 'v3 dumps not supported' ' + reinit_git && + echo "SVN-fs-dump-format-version: 3" >input && + test_must_fail test-svn-fe input >stream && + test_cmp empty stream +' + +test_expect_success 't9135/svn.dump' ' + svnadmin create simple-svn && + svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" && + svn_cmd export "file://$PWD/simple-svn" simple-svnco && + git init simple-git && + test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe && + ( + cd simple-git && + git fast-import <../simple.fe + ) && + ( + cd simple-svnco && + git init && + git add . && + git fetch ../simple-git master && + git diff --exit-code FETCH_HEAD + ) +' test_done
vcs-svn/svndump.c +10 -3
@@ -51,14 +51,14 @@ static struct { } rev_ctx;static struct { -uint32_t uuid, url; +uint32_t version, uuid, url; } dump_ctx;static struct {uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid, revision_number, node_path, node_kind, node_action, node_copyfrom_path, node_copyfrom_rev, text_content_length, - prop_content_length, content_length; + prop_content_length, content_length, svn_fs_dump_format_version; } keys;static void reset_node_ctx (char *fname)
@@ -85,6 +85,7 @@ static void reset_rev_ctx(uint32_t revision)static void reset_dump_ctx (uint32_t url) { dump_ctx.url = url; + dump_ctx.version =1 ; dump_ctx.uuid = ~0 ; }
@@ -105,6 +106,7 @@ static void init_keys(void) keys.text_content_length =pool_intern ("Text-content-length" ); keys.prop_content_length =pool_intern ("Prop-content-length" ); keys.content_length =pool_intern ("Content-length" ); + keys.svn_fs_dump_format_version =pool_intern ("SVN-fs-dump-format-version" ); }static void read_props (void )
@@ -206,7 +208,12 @@ void svndump_read(const char *url) *val++ ='\0' ; key =pool_intern (t); -if (key == keys.uuid) { +if (key == keys.svn_fs_dump_format_version) { + dump_ctx.version =atoi (val); +if (dump_ctx.version >2 ) +die ("expected svn dump format version <= 2, found %d" , + dump_ctx.version); + }else if (key == keys.uuid) { dump_ctx.uuid =pool_intern (val); }else if (key == keys.revision_number) {if (active_ctx ==NODE_CTX )
Signature · 1 line
1.7.2.3.551.g13682.dirty
PATCH 2/2 vcs-svn: Allow simple v3 dumps (no deltas yet)
In reply to Jonathan NiederFrom: David Barr <[email protected]>
Since the dumpfile version 1 days, the Subversion dump format gained some new fields:
- a unique identifier for the repository (version 2 format)
- whether the text and properties for a node should be interpreted as deltas
- checksums for a delta's preimage
- SHA-1 sums as alternatives to the existing MD5 checksums for copy source and the payload (delta).
For now what is relevant to us is the Text-delta and Prop-delta fields, since not noticing these causes a dump file to be misinterpreted (see the previous commit).
[jn: with tests]
--- t/t9010-svn-fe.sh | 350 ++++++++++++++++++++++++++++++++++++++++++++++++++++- vcs-svn/svndump.c | 21 +++- 2 files changed, 365 insertions(+), 6 deletions(-)
t/t9010-svn-fe.sh +347 -3
@@ -9,6 +9,30 @@ reinit_git () { git init } +properties () { + while test "$#" -ne 0 + do + property="$1" && + value="$2" && + printf "%s\n" "K ${#property}" && + printf "%s\n" "$property" && + printf "%s\n" "V ${#value}" && + printf "%s\n" "$value" && + shift 2 || + return 1 + done +} + +text_no_props () { + text="$1 +" && + printf "%s\n" "Prop-content-length: 10" && + printf "%s\n" "Text-content-length: ${#text}" && + printf "%s\n" "Content-length: $((${#text} + 10))" && + printf "%s\n" "" "PROPS-END" && + printf "%s\n" "$text" +} + >empty test_expect_success 'empty dump' '
@@ -18,13 +42,333 @@ test_expect_success 'empty dump' ' git fast-import <stream ' -test_expect_success 'v3 dumps not supported' ' +test_expect_success 'v4 dumps not supported' ' reinit_git && - echo "SVN-fs-dump-format-version: 3" >input && - test_must_fail test-svn-fe input >stream && + echo "SVN-fs-dump-format-version: 4" >v4.dump && + test_must_fail test-svn-fe v4.dump >stream && test_cmp empty stream ' +test_expect_failure 'empty revision' ' + reinit_git && + printf "rev <nobody, nobody@local>: %s\n" "" "" >expect && + cat >emptyrev.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 0 + Content-length: 0 + + Revision-number: 2 + Prop-content-length: 0 + Content-length: 0 + + EOF + test-svn-fe emptyrev.dump >stream && + git fast-import <stream && + git log -p --format="rev <%an, %ae>: %s" HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'empty properties' ' + reinit_git && + printf "rev <nobody, nobody@local>: %s\n" "" "" >expect && + cat >emptyprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test-svn-fe emptyprop.dump >stream && + git fast-import <stream && + git log -p --format="rev <%an, %ae>: %s" HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'author name and commit message' ' + reinit_git && + echo "<[email protected], [email protected]@local>" >expect.author && + cat >message <<-\EOF && + A concise summary of the change + + A detailed description of the change, why it is needed, what + was broken and why applying this is the best course of action. + + * file.c + Details pertaining to an individual file. + EOF + { + properties \ + svn:author [email protected] \ + svn:log "$(cat message)" && + echo PROPS-END + } >props && + { + echo "SVN-fs-dump-format-version: 3" && + echo && + echo "Revision-number: 1" && + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props + } >log.dump && + test-svn-fe log.dump >stream && + git fast-import <stream && + git log -p --format="%B" HEAD >actual.log && + git log --format="<%an, %ae>" >actual.author && + test_cmp message actual.log && + test_cmp expect.author actual.author +' + +test_expect_success 'unsupported properties are ignored' ' + reinit_git && + echo author >expect && + cat >extraprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 56 + Content-length: 56 + + K 8 + nonsense + V 1 + y + K 10 + svn:author + V 6 + author + PROPS-END + EOF + test-svn-fe extraprop.dump >stream && + git fast-import <stream && + git log -p --format=%an HEAD >actual && + test_cmp expect actual +' + +test_expect_failure 'timestamp and empty file' ' + echo [email protected] >expect.author && + echo 1999-01-01 >expect.date && + echo file >expect.files && + reinit_git && + { + properties \ + svn:author [email protected] \ + svn:date "1999-01-01T00:01:002.000000Z" \ + svn:log "add empty file" && + echo PROPS-END + } >props && + { + cat <<-EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF + + Node-path: empty-file + Node-kind: file + Node-action: add + Content-length: 0 + + EOF + } >emptyfile.dump && + test-svn-fe emptyfile.dump >stream && + git fast-import <stream && + git log --format=%an HEAD >actual.author && + git log --date=short --format=%ad HEAD >actual.date && + git ls-tree -r --name-only HEAD >actual.files && + test_cmp expect.author actual.author && + test_cmp expect.date actual.date && + test_cmp expect.files actual.files && + git checkout HEAD empty-file && + test_cmp empty file +' + +test_expect_success 'directory with files' ' + reinit_git && + printf "%s\n" directory/file1 directory/file2 >expect.files && + echo hi >hi && + echo hello >hello && + { + properties \ + svn:author [email protected] \ + svn:date "1999-02-01T00:01:002.000000Z" \ + svn:log "add directory with some files in it" && + echo PROPS-END + } >props && + { + cat <<-EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF && + + Node-path: directory + Node-kind: dir + Node-action: add + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: directory/file1 + Node-kind: file + Node-action: add + EOF + text_no_props hello && + cat <<-\EOF && + Node-path: directory/file2 + Node-kind: file + Node-action: add + EOF + text_no_props hi + } >directory.dump && + test-svn-fe directory.dump >stream && + git fast-import <stream && + + git ls-tree -r --name-only HEAD >actual.files && + git checkout HEAD directory && + test_cmp expect.files actual.files && + test_cmp hello directory/file1 && + test_cmp hi directory/file2 +' + +test_expect_success 'deltas not supported' ' + { + # (old) h + (inline) ello + (old) \n + printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" | + q_to_nul + } >delta && + { + properties \ + svn:author [email protected] \ + svn:date "1999-01-05T00:01:002.000000Z" \ + svn:log "add greeting" && + echo PROPS-END + } >props && + { + properties \ + svn:author [email protected] \ + svn:date "1999-01-06T00:01:002.000000Z" \ + svn:log "change it" && + echo PROPS-END + } >props2 && + { + echo SVN-fs-dump-format-version: 3 && + echo && + echo Revision-number: 1 && + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF && + + Node-path: hello + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 3 + Content-length: 13 + + PROPS-END + hi + + EOF + echo Revision-number: 2 && + echo Prop-content-length: $(wc -c <props2) && + echo Content-length: $(wc -c <props2) && + echo && + cat props2 && + cat <<-\EOF && + + Node-path: hello + Node-kind: file + Node-action: change + Text-delta: true + Prop-content-length: 10 + EOF + echo Text-content-length: $(wc -c <delta) && + echo Content-length: $((10 + $(wc -c <delta))) && + echo && + echo PROPS-END && + cat delta + } >delta.dump && + test_must_fail test-svn-fe delta.dump +' + +test_expect_success 'property deltas not supported' ' + { + properties \ + svn:author [email protected] \ + svn:date "1999-03-06T00:01:002.000000Z" \ + svn:log "make an executable, or chmod -x it" && + echo PROPS-END + } >revprops && + { + echo SVN-fs-dump-format-version: 3 && + echo && + echo Revision-number: 1 && + echo Prop-content-length: $(wc -c <revprops) && + echo Content-length: $(wc -c <revprops) && + echo && + cat revprops && + echo && + cat <<-\EOF && + Node-path: script.sh + Node-kind: file + Node-action: add + Text-content-length: 0 + Prop-content-length: 39 + Content-length: 39 + + K 14 + svn:executable + V 4 + true + PROPS-END + + EOF + echo Revision-number: 2 && + echo Prop-content-length: $(wc -c <revprops) && + echo Content-length: $(wc -c <revprops) && + echo && + cat revprops && + echo && + cat <<-\EOF + Node-path: script.sh + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 30 + Content-length: 30 + + D 14 + svn:executable + PROPS-END + EOF + } >propdelta.dump && + test_must_fail test-svn-fe propdelta.dump +' + test_expect_success 't9135/svn.dump' ' svnadmin create simple-svn && svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
vcs-svn/svndump.c +18 -3
@@ -42,6 +42,7 @@ static char* log_copy(uint32_t length, char *log)static struct {uint32_t action, propLength, textLength, srcRev, srcMode, mark, type;uint32_t src[REPO_MAX_PATH_DEPTH ], dst[REPO_MAX_PATH_DEPTH ]; +uint32_t text_delta, prop_delta; } node_ctx; static struct {
@@ -58,7 +59,9 @@ static struct {uint32_t svn_log, svn_author, svn_date, svn_executable, svn_special, uuid, revision_number, node_path, node_kind, node_action, node_copyfrom_path, node_copyfrom_rev, text_content_length, - prop_content_length, content_length, svn_fs_dump_format_version; + prop_content_length, content_length, svn_fs_dump_format_version, +/* version 3 format */ + text_delta, prop_delta; } keys;static void reset_node_ctx (char *fname)
@@ -72,6 +75,8 @@ static void reset_node_ctx(char *fname) node_ctx.srcMode =0 ;pool_tok_seq (REPO_MAX_PATH_DEPTH , node_ctx.dst,"/" , fname); node_ctx.mark =0 ; + node_ctx.text_delta =0 ; + node_ctx.prop_delta =0 ; }static void reset_rev_ctx (uint32_t revision)
@@ -107,6 +112,9 @@ static void init_keys(void) keys.prop_content_length =pool_intern ("Prop-content-length" ); keys.content_length =pool_intern ("Content-length" ); keys.svn_fs_dump_format_version =pool_intern ("SVN-fs-dump-format-version" ); +/* version 3 format (Subversion 1.1.0) */ + keys.text_delta =pool_intern ("Text-delta" ); + keys.prop_delta =pool_intern ("Prop-delta" ); }static void read_props (void )
@@ -144,6 +152,9 @@ static void read_props(void)static void handle_node (void ) { +if (node_ctx.text_delta || node_ctx.prop_delta) +die ("text and property deltas not supported" ); +if (node_ctx.propLength !=LENGTH_UNKNOWN && node_ctx.propLength)read_props ();
@@ -210,8 +221,8 @@ void svndump_read(const char *url)if (key == keys.svn_fs_dump_format_version) { dump_ctx.version =atoi (val); -if (dump_ctx.version >2 ) -die ("expected svn dump format version <= 2, found %d" , +if (dump_ctx.version >3 ) +die ("expected svn dump format version <= 3, found %d" , dump_ctx.version); }else if (key == keys.uuid) { dump_ctx.uuid =pool_intern (val);
@@ -255,6 +266,10 @@ void svndump_read(const char *url) node_ctx.textLength =atoi (val); }else if (key == keys.prop_content_length) { node_ctx.propLength =atoi (val); + }else if (key == keys.text_delta) { + node_ctx.text_delta = !strcmp (val,"true" ); + }else if (key == keys.prop_delta) { + node_ctx.prop_delta = !strcmp (val,"true" ); }else if (key == keys.content_length) { len =atoi (val);buffer_read_line ();
Signature · 1 line
1.7.2.3.551.g13682.dirty
cover svn-fe: support for property deltas (but not text deltas yet)
In reply to Jonathan NiederHi,
Quoted 2 lines · Jonathan Nieder
This mini-series is part of an effort to get David and Ram's svn import work integrated into mainline git[1].
Another chapter. This one is mostly David's work. One can test it (I haven't tried) by taking out the safety
die("text deltas not supported");and letting it import from some real-world deltified dump file, treating deltas as the full text. Then one can validate as usual, by checking the modes of files in each revision of the imported tree.
I've done a little refactoring to more easily understand the patch, but the heart of the work is still David's. Any bugs and infelicities are probably mine (especially the evil hack to support switching between executables and symlinks).
Especially useful would be a nicer set of tests. A tool to create dump files based on a more concise description would make this and some future tasks a lot easier (hint, hint).
Thoughts? Improvements? Any of these ready to go? I can rearrange to put the uncontroversial patches at the beginning once it is clear what those are.
David Barr (1):
vcs-svn: Implement Prop-delta handling
Jonathan Nieder (14):
vcs-svn: Check for errors from open()
vcs-svn: Eliminate node_ctx.srcRev global
vcs-svn: Eliminate node_ctx.mark global
vcs-svn: Unclutter handle_node by introducing have_props var
vcs-svn: Use mark to indicate nodes with text
vcs-svn: handle_node: Handle deletion case early
vcs-svn: Replace = Delete + Add
vcs-svn: Merge repo_replace and repo_modify functions
vcs-svn: Delay read of per-path properties
vcs-svn: Reject path nodes without Node-action
vcs-svn: More dump format sanity checks
vcs-svn: Make source easier to read on small screens
vcs-svn: Split off function for handling of individual properties
vcs-svn: Sharpen parsing of property lines
contrib/svn-fe/svn-fe.c | 3 +- t/t9010-svn-fe.sh | 301 ++++++++++++++++++++++++++++++++++++++++++++++- test-svn-fe.c | 3 +- vcs-svn/repo_tree.c | 21 +-- vcs-svn/repo_tree.h | 3 +- vcs-svn/svndump.c | 191 +++++++++++++++++++----------- vcs-svn/svndump.h | 2 +- 7 files changed, 436 insertions(+), 88 deletions(-)
Signature · 1 line
1.7.2.3
PATCH 1/15 vcs-svn: Check for errors from open()
test-svn-fe segfaults when passed a bogus path. Simplify debugging by exiting with a meaningful error message instead.
---
Doesn't belong in this series, just something I noticed while debugging.
contrib/svn-fe/svn-fe.c | 3 ++- test-svn-fe.c | 3 ++- vcs-svn/svndump.c | 6 ++++-- vcs-svn/svndump.h | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-)
contrib/svn-fe/svn-fe.c +2 -1
@@ -8,7 +8,8 @@int main (int argc,char **argv) { -svndump_init (NULL ); +if (svndump_init (NULL )) +return 1 ;svndump_read ((argc >1 ) ? argv[1 ] :NULL );svndump_deinit ();svndump_reset ();
test-svn-fe.c +2 -1
@@ -9,7 +9,8 @@ int main(int argc, char *argv[]) {if (argc !=2 )usage ("test-svn-fe <file>" ); -svndump_init (argv[1 ]); +if (svndump_init (argv[1 ])) +return 1 ;svndump_read (NULL );svndump_deinit ();svndump_reset ();
vcs-svn/svndump.c +4 -2
@@ -290,14 +290,16 @@ void svndump_read(const char *url)handle_revision (); } -void svndump_init (const char *filename) +int svndump_init (const char *filename) { -buffer_init (filename); +if (buffer_init (filename)) +return error ("cannot open %s: %s" , filename,strerror (errno));repo_init ();reset_dump_ctx (~0 );reset_rev_ctx (0 );reset_node_ctx (NULL );init_keys (); +return 0 ; }void svndump_deinit (void )
vcs-svn/svndump.h +1 -1
@@ -1,7 +1,7 @@#ifndef SVNDUMP_H_ #define SVNDUMP_H_ -void svndump_init (const char *filename); +int svndump_init (const char *filename);void svndump_read (const char *url);void svndump_deinit (void );void svndump_reset (void );
Signature · 1 line
1.7.2.3
PATCH 2/15 vcs-svn: Eliminate node_ctx.srcRev global
In reply to Jonathan NiederThe srcRev variable is only used in handle_node(); its purpose is to hold the old mode for a path, to only be used if properties are not being changed. Narrow its scope to make its meaningful lifetime more obvious.
No functional change intended. Add some tests as a sanity-check for the simplest case (no renames).
--- t/t9010-svn-fe.sh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.c | 15 +++-- 2 files changed, 166 insertions(+), 7 deletions(-)
t/t9010-svn-fe.sh +158 -0
@@ -252,6 +252,164 @@ test_expect_success 'directory with files' ' test_cmp hi directory/file2 ' +test_expect_failure 'change file mode but keep old content' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T greeting + OBJID + :100644 120000 OBJID OBJID T greeting + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + echo "link hello" >expect.blob && + echo hello >hello && + cat >filemode.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 33 + Content-length: 33 + + K 11 + svn:special + V 1 + * + PROPS-END + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test-svn-fe filemode.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + git show HEAD:greeting >actual.blob && + git show HEAD^:greeting >actual.target && + test_cmp expect actual && + test_cmp expect.blob actual.blob && + test_cmp hello actual.target +' + +test_expect_success 'change file mode and reiterate content' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T greeting + OBJID + :100644 120000 OBJID OBJID T greeting + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + echo "link hello" >expect.blob && + echo hello >hello && + cat >filemode.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 33 + Text-content-length: 11 + Content-length: 44 + + K 11 + svn:special + V 1 + * + PROPS-END + link hello + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + EOF + test-svn-fe filemode.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + git show HEAD:greeting >actual.blob && + git show HEAD^:greeting >actual.target && + test_cmp expect actual && + test_cmp expect.blob actual.blob && + test_cmp hello actual.target +' + test_expect_success 'deltas not supported' ' { # (old) h + (inline) ello + (old) \n
vcs-svn/svndump.c +8 -7
@@ -40,7 +40,7 @@ static char* log_copy(uint32_t length, char *log) }static struct { -uint32_t action, propLength, textLength, srcRev, srcMode, mark, type; +uint32_t action, propLength, textLength, srcRev, mark, type;uint32_t src[REPO_MAX_PATH_DEPTH ], dst[REPO_MAX_PATH_DEPTH ];uint32_t text_delta, prop_delta; } node_ctx;
@@ -72,7 +72,6 @@ static void reset_node_ctx(char *fname) node_ctx.textLength =LENGTH_UNKNOWN ; node_ctx.src[0 ] = ~0 ; node_ctx.srcRev =0 ; - node_ctx.srcMode =0 ;pool_tok_seq (REPO_MAX_PATH_DEPTH , node_ctx.dst,"/" , fname); node_ctx.mark =0 ; node_ctx.text_delta =0 ;
@@ -152,6 +151,8 @@ static void read_props(void)static void handle_node (void ) { +uint32_t old_mode =0 ; +if (node_ctx.text_delta || node_ctx.prop_delta)die ("text and property deltas not supported" );
@@ -159,7 +160,7 @@ static void handle_node(void)read_props ();if (node_ctx.srcRev) - node_ctx.srcMode =repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); + old_mode =repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst);if (node_ctx.textLength !=LENGTH_UNKNOWN && node_ctx.type !=REPO_MODE_DIR )
@@ -175,19 +176,19 @@ static void handle_node(void)else if (node_ctx.propLength !=LENGTH_UNKNOWN )repo_modify (node_ctx.dst, node_ctx.type, node_ctx.mark);else if (node_ctx.textLength !=LENGTH_UNKNOWN ) - node_ctx.srcMode =repo_replace (node_ctx.dst, node_ctx.mark); + old_mode =repo_replace (node_ctx.dst, node_ctx.mark); }else if (node_ctx.action ==NODEACT_ADD ) {if (node_ctx.srcRev && node_ctx.propLength !=LENGTH_UNKNOWN )repo_modify (node_ctx.dst, node_ctx.type, node_ctx.mark);else if (node_ctx.srcRev && node_ctx.textLength !=LENGTH_UNKNOWN ) - node_ctx.srcMode =repo_replace (node_ctx.dst, node_ctx.mark); + old_mode =repo_replace (node_ctx.dst, node_ctx.mark);else if ((node_ctx.type ==REPO_MODE_DIR && !node_ctx.srcRev) || node_ctx.textLength !=LENGTH_UNKNOWN )repo_add (node_ctx.dst, node_ctx.type, node_ctx.mark); } -if (node_ctx.propLength ==LENGTH_UNKNOWN && node_ctx.srcMode) - node_ctx.type = node_ctx.srcMode; +if (node_ctx.propLength ==LENGTH_UNKNOWN && old_mode) + node_ctx.type = old_mode;if (node_ctx.mark)fast_export_blob (node_ctx.type, node_ctx.mark, node_ctx.textLength);
Signature · 1 line
1.7.2.3
PATCH 3/15 vcs-svn: Eliminate node_ctx.mark global
In reply to Jonathan NiederThe mark variable is only used in handle_node(). Its life is very short and simple: first, a new mark number is allocated if this node has text attached, then that mark is recorded in the in-core tree being built up, and lastly the mark is communicated to fast-import in the stream along with the associated text.
A new reader may worry about interaction with other code, especially since mark is not initialized to zero in handle_node() itself. Disperse such worries by making it local. No functional change intended.
--- vcs-svn/svndump.c | 23 +++++++++++------------ 1 files changed, 11 insertions(+), 12 deletions(-)
vcs-svn/svndump.c +11 -12
@@ -40,7 +40,7 @@ static char* log_copy(uint32_t length, char *log) }static struct { -uint32_t action, propLength, textLength, srcRev, mark, type; +uint32_t action, propLength, textLength, srcRev, type;uint32_t src[REPO_MAX_PATH_DEPTH ], dst[REPO_MAX_PATH_DEPTH ];uint32_t text_delta, prop_delta; } node_ctx;
@@ -73,7 +73,6 @@ static void reset_node_ctx(char *fname) node_ctx.src[0 ] = ~0 ; node_ctx.srcRev =0 ;pool_tok_seq (REPO_MAX_PATH_DEPTH , node_ctx.dst,"/" , fname); - node_ctx.mark =0 ; node_ctx.text_delta =0 ; node_ctx.prop_delta =0 ; }
@@ -151,7 +150,7 @@ static void read_props(void)static void handle_node (void ) { -uint32_t old_mode =0 ; +uint32_t old_mode =0 , mark =0 ;if (node_ctx.text_delta || node_ctx.prop_delta)die ("text and property deltas not supported" );
@@ -164,7 +163,7 @@ static void handle_node(void)if (node_ctx.textLength !=LENGTH_UNKNOWN && node_ctx.type !=REPO_MODE_DIR ) - node_ctx.mark =next_blob_mark (); + mark =next_blob_mark ();if (node_ctx.action ==NODEACT_DELETE ) {repo_delete (node_ctx.dst);
@@ -172,26 +171,26 @@ static void handle_node(void) node_ctx.action == NODEACT_REPLACE) {if (node_ctx.action ==NODEACT_REPLACE && node_ctx.type ==REPO_MODE_DIR ) -repo_replace (node_ctx.dst, node_ctx.mark); +repo_replace (node_ctx.dst, mark);else if (node_ctx.propLength !=LENGTH_UNKNOWN ) -repo_modify (node_ctx.dst, node_ctx.type, node_ctx.mark); +repo_modify (node_ctx.dst, node_ctx.type, mark);else if (node_ctx.textLength !=LENGTH_UNKNOWN ) - old_mode =repo_replace (node_ctx.dst, node_ctx.mark); + old_mode =repo_replace (node_ctx.dst, mark); } else if (node_ctx.action == NODEACT_ADD) {if (node_ctx.srcRev && node_ctx.propLength !=LENGTH_UNKNOWN ) -repo_modify (node_ctx.dst, node_ctx.type, node_ctx.mark); +repo_modify (node_ctx.dst, node_ctx.type, mark);else if (node_ctx.srcRev && node_ctx.textLength !=LENGTH_UNKNOWN ) - old_mode =repo_replace (node_ctx.dst, node_ctx.mark); + old_mode =repo_replace (node_ctx.dst, mark);else if ((node_ctx.type ==REPO_MODE_DIR && !node_ctx.srcRev) || node_ctx.textLength !=LENGTH_UNKNOWN ) -repo_add (node_ctx.dst, node_ctx.type, node_ctx.mark); +repo_add (node_ctx.dst, node_ctx.type, mark); }if (node_ctx.propLength ==LENGTH_UNKNOWN && old_mode) node_ctx.type = old_mode; -if (node_ctx.mark) -fast_export_blob (node_ctx.type, node_ctx.mark, node_ctx.textLength); +if (mark) +fast_export_blob (node_ctx.type, mark, node_ctx.textLength);else if (node_ctx.textLength !=LENGTH_UNKNOWN )buffer_skip_bytes (node_ctx.textLength); }
Signature · 1 line
1.7.2.3
PATCH 4/15 vcs-svn: Unclutter handle_node by introducing have_props var
In reply to Jonathan NiederIt is possible for a path node in an SVN-format dump file to leave out the properties section. svn-fe handles this by carrying over the properties (in particular, file type) from the old version of that node.
To support this, handle_node tests several times whether a Prop-content-length field is present. Ancient Subversion actually leaves out the Prop-content-length field even for nodes with properties, so that's not quite the right check. Besides, this detail of mechanism is distracting when the question at hand is instead what content the new node should have.
So introduce a local have_props variable. The semantics are the same as before; the adaptations to support ancient streams that leave out the prop-content-length can wait until someone needs them.
--- vcs-svn/svndump.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
vcs-svn/svndump.c +5 -4
@@ -151,11 +151,12 @@ static void read_props(void)static void handle_node (void ) {uint32_t old_mode =0 , mark =0 ; +const int have_props = node_ctx.propLength !=LENGTH_UNKNOWN ;if (node_ctx.text_delta || node_ctx.prop_delta)die ("text and property deltas not supported" ); -if (node_ctx.propLength !=LENGTH_UNKNOWN && node_ctx.propLength) +if (have_props && node_ctx.propLength)read_props ();if (node_ctx.srcRev)
@@ -172,12 +173,12 @@ static void handle_node(void)if (node_ctx.action ==NODEACT_REPLACE && node_ctx.type ==REPO_MODE_DIR )repo_replace (node_ctx.dst, mark); -else if (node_ctx.propLength !=LENGTH_UNKNOWN ) +else if (have_props)repo_modify (node_ctx.dst, node_ctx.type, mark);else if (node_ctx.textLength !=LENGTH_UNKNOWN ) old_mode =repo_replace (node_ctx.dst, mark); }else if (node_ctx.action ==NODEACT_ADD ) { -if (node_ctx.srcRev && node_ctx.propLength !=LENGTH_UNKNOWN ) +if (node_ctx.srcRev && have_props)repo_modify (node_ctx.dst, node_ctx.type, mark);else if (node_ctx.srcRev && node_ctx.textLength !=LENGTH_UNKNOWN ) old_mode =repo_replace (node_ctx.dst, mark);
@@ -186,7 +187,7 @@ static void handle_node(void)repo_add (node_ctx.dst, node_ctx.type, mark); } -if (node_ctx.propLength ==LENGTH_UNKNOWN && old_mode) +if (!have_props && old_mode) node_ctx.type = old_mode;if (mark)
Signature · 1 line
1.7.2.3
PATCH 5/15 vcs-svn: Use mark to indicate nodes with included text
In reply to Jonathan NiederAllocate a mark if needed as soon as possible so later code can use "if (mark)" to check if this node has text attached rather than explicitly checking for Text-content-length.
While at it, reject directory nodes with text attached; the presence of such a node would indicate a bug in the dump generator or svn-fe's understanding. In the long term, it would be nice to be able to continue parsing and save the error for later, but for now it is simpler to error out right away.
--- vcs-svn/svndump.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
vcs-svn/svndump.c +8 -8
@@ -156,15 +156,17 @@ static void handle_node(void)if (node_ctx.text_delta || node_ctx.prop_delta)die ("text and property deltas not supported" ); +if (node_ctx.textLength !=LENGTH_UNKNOWN ) + mark =next_blob_mark (); +if (have_props && node_ctx.propLength)read_props ();if (node_ctx.srcRev) old_mode =repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); -if (node_ctx.textLength !=LENGTH_UNKNOWN && - node_ctx.type !=REPO_MODE_DIR ) - mark =next_blob_mark (); +if (mark && node_ctx.type ==REPO_MODE_DIR ) +die ("invalid dump: directories cannot have text attached" );if (node_ctx.action ==NODEACT_DELETE ) {repo_delete (node_ctx.dst);
@@ -175,15 +177,15 @@ static void handle_node(void)repo_replace (node_ctx.dst, mark); else if (have_props) repo_modify(node_ctx.dst, node_ctx.type, mark); - else if (node_ctx.textLength != LENGTH_UNKNOWN) + else if (mark) old_mode =repo_replace (node_ctx.dst, mark); } else if (node_ctx.action == NODEACT_ADD) {if (node_ctx.srcRev && have_props)repo_modify (node_ctx.dst, node_ctx.type, mark); -else if (node_ctx.srcRev && node_ctx.textLength !=LENGTH_UNKNOWN ) +else if (node_ctx.srcRev && mark) old_mode =repo_replace (node_ctx.dst, mark);else if ((node_ctx.type ==REPO_MODE_DIR && !node_ctx.srcRev) || - node_ctx.textLength !=LENGTH_UNKNOWN ) + mark)repo_add (node_ctx.dst, node_ctx.type, mark); }
@@ -192,8 +194,6 @@ static void handle_node(void)if (mark)fast_export_blob (node_ctx.type, mark, node_ctx.textLength); -else if (node_ctx.textLength !=LENGTH_UNKNOWN ) -buffer_skip_bytes (node_ctx.textLength); }static void handle_revision (void )
Signature · 1 line
1.7.2.3
PATCH 6/15 vcs-svn: handle_node: Handle deletion case early
In reply to Jonathan NiederTake care of "Node-action: delete" as soon as possible, so we can stop worrying about that case in the rest of the function.
Functional change: catch deletion nodes with features that would not apply to them (text, properties, or origin data) and error out for those cases.
--- vcs-svn/svndump.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
vcs-svn/svndump.c +8 -3
@@ -159,6 +159,13 @@ static void handle_node(void)if (node_ctx.textLength !=LENGTH_UNKNOWN ) mark =next_blob_mark (); +if (node_ctx.action ==NODEACT_DELETE ) { +if (mark || have_props || node_ctx.srcRev) +die ("invalid dump: deletion node has " +"copyfrom info, text, or properties" ); +return repo_delete (node_ctx.dst); + } +if (have_props && node_ctx.propLength)read_props ();
@@ -168,9 +175,7 @@ static void handle_node(void)if (mark && node_ctx.type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_DELETE ) { -repo_delete (node_ctx.dst); - }else if (node_ctx.action ==NODEACT_CHANGE || +if (node_ctx.action ==NODEACT_CHANGE || node_ctx.action ==NODEACT_REPLACE ) {if (node_ctx.action ==NODEACT_REPLACE && node_ctx.type ==REPO_MODE_DIR )
Signature · 1 line
1.7.2.3
PATCH 7/15 vcs-svn: Replace = Delete + Add
In reply to Jonathan NiederSimplify by reducing the "Node-action: replace" case to "Node-action:
add". This way, the main part of handle_node() only has to deal with "add" and "change" nodes.
Functional change: replacing a symlink or executable without setting properties will reset the mode.
---
I was happy to discover this.
vcs-svn/svndump.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
vcs-svn/svndump.c +7 -6
@@ -166,6 +166,11 @@ static void handle_node(void)return repo_delete (node_ctx.dst); } +if (node_ctx.action ==NODEACT_REPLACE ) { +repo_delete (node_ctx.dst); + node_ctx.action =NODEACT_ADD ; + } +if (have_props && node_ctx.propLength)read_props ();
@@ -175,12 +180,8 @@ static void handle_node(void)if (mark && node_ctx.type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_CHANGE || - node_ctx.action ==NODEACT_REPLACE ) { -if (node_ctx.action ==NODEACT_REPLACE && - node_ctx.type ==REPO_MODE_DIR ) -repo_replace (node_ctx.dst, mark); -else if (have_props) +if (node_ctx.action ==NODEACT_CHANGE ) { +if (have_props)repo_modify (node_ctx.dst, node_ctx.type, mark);else if (mark) old_mode =repo_replace (node_ctx.dst, mark);
Signature · 1 line
1.7.2.3
PATCH 8/15 vcs-svn: Combine repo_replace and repo_modify functions
In reply to Jonathan NiederThere are two functions to change the staged content for a path in the svn importer's active commit: repo_replace, which changes the text and returns the mode, and repo_modify, which changes the text and mode and returns nothing.
Worse, there are more subtle differences:
- A mark of 0 passed to repo_modify means "use the existing content". repo_replace uses it as mark :0 and produces a corrupt stream.
- When passed a path that is not part of the active commit, repo_replace returns without doing anything. repo_modify transparently adds a new directory entry.
Get rid of both and introduce a new function with the best features of
both: repo_modify_path modifies the mode, content, or both for a path, depending on which arguments are zero. If no such dirent already exists, it does nothing and reports the error by returning 0. Otherwise, the return value is the resulting mode.
---
David, I think we discussed doing something like this a few months ago. It seems appropriate because Subversion's Replace FS operation is not similar to repo_replace after all.
vcs-svn/repo_tree.c | 21 +++++++-------------- vcs-svn/repo_tree.h | 3 +-- vcs-svn/svndump.c | 8 ++++---- 3 files changed, 12 insertions(+), 20 deletions(-)
vcs-svn/repo_tree.c +7 -14
@@ -175,25 +175,18 @@ void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark)repo_write_dirent (path, mode, blob_mark,0 ); } -uint32_t repo_replace (uint32_t *path,uint32_t blob_mark) +uint32_t repo_modify_path (uint32_t *path,uint32_t mode,uint32_t blob_mark) { -uint32_t mode =0 ;struct repo_dirent *src_dent; src_dent =repo_read_dirent (active_commit, path); -if (src_dent !=NULL ) { - mode = src_dent->mode; -repo_write_dirent (path, mode, blob_mark,0 ); - } -return mode; -} - -void repo_modify (uint32_t *path,uint32_t mode,uint32_t blob_mark) -{ -struct repo_dirent *src_dent; - src_dent =repo_read_dirent (active_commit, path); -if (src_dent !=NULL && blob_mark ==0 ) +if (!src_dent) +return 0 ; +if (!blob_mark) blob_mark = src_dent->content_offset; +if (!mode) + mode = src_dent->mode;repo_write_dirent (path, mode, blob_mark,0 ); +return mode; }void repo_delete (uint32_t *path)
vcs-svn/repo_tree.h +1 -2
@@ -14,8 +14,7 @@uint32_t next_blob_mark (void );uint32_t repo_copy (uint32_t revision,uint32_t *src,uint32_t *dst);void repo_add (uint32_t *path,uint32_t mode,uint32_t blob_mark); -uint32_t repo_replace (uint32_t *path,uint32_t blob_mark); -void repo_modify (uint32_t *path,uint32_t mode,uint32_t blob_mark); +uint32_t repo_modify_path (uint32_t *path,uint32_t mode,uint32_t blob_mark);void repo_delete (uint32_t *path);void repo_commit (uint32_t revision,uint32_t author,char *log,uint32_t uuid,uint32_t url,long unsigned timestamp);
vcs-svn/svndump.c +4 -4
@@ -182,14 +182,14 @@ static void handle_node(void)if (node_ctx.action ==NODEACT_CHANGE ) {if (have_props) -repo_modify (node_ctx.dst, node_ctx.type, mark); +repo_modify_path (node_ctx.dst, node_ctx.type, mark);else if (mark) - old_mode =repo_replace (node_ctx.dst, mark); + old_mode =repo_modify_path (node_ctx.dst,0 , mark); }else if (node_ctx.action ==NODEACT_ADD ) {if (node_ctx.srcRev && have_props) -repo_modify (node_ctx.dst, node_ctx.type, mark); +repo_modify_path (node_ctx.dst, node_ctx.type, mark);else if (node_ctx.srcRev && mark) - old_mode =repo_replace (node_ctx.dst, mark); + old_mode =repo_modify_path (node_ctx.dst,0 , mark);else if ((node_ctx.type ==REPO_MODE_DIR && !node_ctx.srcRev) || mark)repo_add (node_ctx.dst, node_ctx.type, mark);
Signature · 1 line
1.7.2.3
PATCH 9/15 vcs-svn: Delay read of per-path properties
In reply to Jonathan NiederThe mode for each file in an svn-format dump is kept in the properties section. The properties section is read as soon as possible to allow the correct mode to be filled in when registering the file with the repo_tree lib.
To support nodes with a missing properties section, svn-fe determines the mode in three stages:
- The kind (directory or file) of the node is read from the dump and used to make an initial estimate (040000 or 100644).
- Properties are read in and allowed to override this for symlinks and executables.
- If there is no properties section, the mode from the previous content of the path is left alone, overriding the above considerations.
This is a bit of a mess, and worse, it would get even more complicated once we start to support property deltas. If we could only register the file with a provisional value for mode and then change it later when properties say so, the procedure would be much simpler.
... oh, right, we can.
--- vcs-svn/svndump.c | 42 +++++++++++++++++++----------------------- 1 files changed, 19 insertions(+), 23 deletions(-)
vcs-svn/svndump.c +19 -23
@@ -150,7 +150,8 @@ static void read_props(void)static void handle_node (void ) { -uint32_t old_mode =0 , mark =0 ; +uint32_t mark =0 ; +const uint32_t type = node_ctx.type;const int have_props = node_ctx.propLength !=LENGTH_UNKNOWN ;if (node_ctx.text_delta || node_ctx.prop_delta)
@@ -171,32 +172,27 @@ static void handle_node(void) node_ctx.action =NODEACT_ADD ; } -if (have_props && node_ctx.propLength) -read_props (); +if (node_ctx.srcRev) { +repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); + node_ctx.action =NODEACT_CHANGE ; + } -if (node_ctx.srcRev) - old_mode =repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); - -if (mark && node_ctx.type ==REPO_MODE_DIR ) +if (mark && type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_CHANGE ) { -if (have_props) -repo_modify_path (node_ctx.dst, node_ctx.type, mark); -else if (mark) - old_mode =repo_modify_path (node_ctx.dst,0 , mark); - }else if (node_ctx.action ==NODEACT_ADD ) { -if (node_ctx.srcRev && have_props) -repo_modify_path (node_ctx.dst, node_ctx.type, mark); -else if (node_ctx.srcRev && mark) - old_mode =repo_modify_path (node_ctx.dst,0 , mark); -else if ((node_ctx.type ==REPO_MODE_DIR && !node_ctx.srcRev) || - mark) -repo_add (node_ctx.dst, node_ctx.type, mark); - } +if (node_ctx.action ==NODEACT_CHANGE ) + node_ctx.type =repo_modify_path (node_ctx.dst,0 , mark); +else /* Node-action: add */ +repo_add (node_ctx.dst, type, mark); -if (!have_props && old_mode) - node_ctx.type = old_mode; +if (have_props) { +const uint32_t old_mode = node_ctx.type; + node_ctx.type = type; +if (node_ctx.propLength) +read_props (); +if (node_ctx.type != old_mode) +repo_modify_path (node_ctx.dst, node_ctx.type, mark); + }if (mark)fast_export_blob (node_ctx.type, mark, node_ctx.textLength);
Signature · 1 line
1.7.2.3
PATCH 10/15 vcs-svn: Reject path nodes without Node-action
In reply to Jonathan NiederIt would be better to flag such errors and let the import proceed anyway, but for now it is simpler not to worry about recovery from such weird cases.
--- t/t9010-svn-fe.sh | 20 ++++++++++++++++++++ vcs-svn/svndump.c | 7 +++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
t/t9010-svn-fe.sh +20 -0
@@ -252,6 +252,26 @@ test_expect_success 'directory with files' ' test_cmp hi directory/file2 ' +test_expect_success 'node without action' ' + cat >inaction.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: directory + Node-kind: dir + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test_must_fail test-svn-fe inaction.dump +' + test_expect_failure 'change file mode but keep old content' ' reinit_git && cat >expect <<-\EOF &&
vcs-svn/svndump.c +5 -2
@@ -174,7 +174,8 @@ static void handle_node(void)if (node_ctx.srcRev) {repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); - node_ctx.action =NODEACT_CHANGE ; +if (node_ctx.action ==NODEACT_ADD ) + node_ctx.action =NODEACT_CHANGE ; }if (mark && type ==REPO_MODE_DIR )
@@ -182,8 +183,10 @@ static void handle_node(void)if (node_ctx.action ==NODEACT_CHANGE ) node_ctx.type =repo_modify_path (node_ctx.dst,0 , mark); -else /* Node-action: add */ +else if (node_ctx.action ==NODEACT_ADD )repo_add (node_ctx.dst, type, mark); +else +die ("invalid dump: Node-path block lacks Node-action" );if (have_props) {const uint32_t old_mode = node_ctx.type;
Signature · 1 line
1.7.2.3
Re: [PATCH 10/15] vcs-svn: Reject path nodes without Node-action
vcs-svn/svndump.c static void handle_node(void) · line 178
Quoted 9 lines · Jonathan Nieder
vcs-svn/svndump.c +2
-1@@ -174,7 +174,8 @@ static void handle_node(void)if (node_ctx.srcRev) {repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst); - node_ctx.action =NODEACT_CHANGE ; +if (node_ctx.action ==NODEACT_ADD ) + node_ctx.action =NODEACT_CHANGE ;
Whitespace damage. Here's a fixup.
---
vcs-svn/svndump.c +1 -1
@@ -175,7 +175,7 @@ static void handle_node(void)if (node_ctx.srcRev) {repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst);if (node_ctx.action ==NODEACT_ADD ) - node_ctx.action =NODEACT_CHANGE ; + node_ctx.action =NODEACT_CHANGE ; }if (mark && type ==REPO_MODE_DIR )
PATCH 11/15 vcs-svn: More dump format sanity checks
In reply to Jonathan NiederNode-action: change is not appropriate when switching between file and directory or adding a new file. Current svn-fe silently accepts such nodes and the resulting tree has missing files in the "changed when meant to add" case.
Node-action: add requires some content (text or directory); there is no such thing as an "intent to add" node in svn dumps. Current svn-fe accepts such contentless adds but produces an invalid fast-import stream that refers to nonexistent mark :0 in response.
--- t/t9010-svn-fe.sh | 21 +++++++++++++++++++++ vcs-svn/svndump.c | 18 ++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-)
t/t9010-svn-fe.sh +21 -0
@@ -272,6 +272,27 @@ test_expect_success 'node without action' ' test_must_fail test-svn-fe inaction.dump ' +test_expect_success 'action: add node without text' ' + cat >textless.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: textless + Node-kind: file + Node-action: add + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test_must_fail test-svn-fe textless.dump +' + test_expect_failure 'change file mode but keep old content' ' reinit_git && cat >expect <<-\EOF &&
vcs-svn/svndump.c +14 -4
@@ -181,12 +181,22 @@ static void handle_node(void)if (mark && type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_CHANGE ) - node_ctx.type =repo_modify_path (node_ctx.dst,0 , mark); -else if (node_ctx.action ==NODEACT_ADD ) +if (node_ctx.action ==NODEACT_CHANGE ) { +uint32_t mode =repo_modify_path (node_ctx.dst,0 , mark); +if (!mode) +die ("invalid dump: path to be modified is missing" ); +if (mode ==REPO_MODE_DIR && type !=REPO_MODE_DIR ) +die ("invalid dump: cannot modify a directory into a file" ); +if (mode !=REPO_MODE_DIR && type ==REPO_MODE_DIR ) +die ("invalid dump: cannot modify a file into a directory" ); + node_ctx.type = mode; + }else if (node_ctx.action ==NODEACT_ADD ) { +if (!mark && type !=REPO_MODE_DIR ) +die ("invalid dump: adds node without text" );repo_add (node_ctx.dst, type, mark); -else + }else {die ("invalid dump: Node-path block lacks Node-action" ); + }if (have_props) {const uint32_t old_mode = node_ctx.type;
Signature · 1 line
1.7.2.3
PATCH 12/15 vcs-svn: Make source easier to read on small screens
In reply to Jonathan NiederRemove some newlines from handle_node() that are not needed for clarity.
--- vcs-svn/svndump.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-)
vcs-svn/svndump.c +0 -8
@@ -156,31 +156,25 @@ static void handle_node(void)if (node_ctx.text_delta || node_ctx.prop_delta)die ("text and property deltas not supported" ); -if (node_ctx.textLength !=LENGTH_UNKNOWN ) mark =next_blob_mark (); -if (node_ctx.action ==NODEACT_DELETE ) {if (mark || have_props || node_ctx.srcRev)die ("invalid dump: deletion node has " "copyfrom info, text, or properties" );return repo_delete (node_ctx.dst); } -if (node_ctx.action ==NODEACT_REPLACE ) {repo_delete (node_ctx.dst); node_ctx.action =NODEACT_ADD ; } -if (node_ctx.srcRev) {repo_copy (node_ctx.srcRev, node_ctx.src, node_ctx.dst);if (node_ctx.action ==NODEACT_ADD ) node_ctx.action =NODEACT_CHANGE ; } -if (mark && type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_CHANGE ) {uint32_t mode =repo_modify_path (node_ctx.dst,0 , mark);if (!mode)
@@ -197,7 +191,6 @@ static void handle_node(void) }else {die ("invalid dump: Node-path block lacks Node-action" ); } -if (have_props) {const uint32_t old_mode = node_ctx.type; node_ctx.type = type;
@@ -206,7 +199,6 @@ static void handle_node(void)if (node_ctx.type != old_mode)repo_modify_path (node_ctx.dst, node_ctx.type, mark); } -if (mark)fast_export_blob (node_ctx.type, mark, node_ctx.textLength); }
Signature · 1 line
1.7.2.3
PATCH 13/15 vcs-svn: Split off function for handling of individual properties
In reply to Jonathan NiederThe handle_property function is the part of read_props that would be interesting for most people: semantics of properties rather than the algorithm for parsing them.
--- vcs-svn/svndump.c | 33 +++++++++++++++++++-------------- 1 files changed, 19 insertions(+), 14 deletions(-)
vcs-svn/svndump.c +19 -14
@@ -30,7 +30,7 @@/* Create memory pool for log messages */ obj_pool_gen(log, char, 4096) -static char *log_copy (uint32_t length,char *log) +static char *log_copy (uint32_t length,const char *log) {char *buffer;log_free (log_pool.size);
@@ -115,6 +115,23 @@ static void init_keys(void) keys.prop_delta =pool_intern ("Prop-delta" ); } +static void handle_property (uint32_t key,const char *val,uint32_t len) +{ +if (key == keys.svn_log) { +/* Value length excludes terminating nul. */ + rev_ctx.log =log_copy (len +1 , val); + }else if (key == keys.svn_author) { + rev_ctx.author =pool_intern (val); + }else if (key == keys.svn_date) { +if (parse_date_basic (val, &rev_ctx.timestamp,NULL )) +fprintf (stderr,"Invalid timestamp: %s\n" , val); + }else if (key == keys.svn_executable) { + node_ctx.type =REPO_MODE_EXE ; + }else if (key == keys.svn_special) { + node_ctx.type =REPO_MODE_LNK ; + } +} +static void read_props (void ) {uint32_t len;
@@ -129,19 +146,7 @@ static void read_props(void) }else if (!strncmp (t,"V " ,2 )) { len =atoi (&t[2 ]); val =buffer_read_string (len); -if (key == keys.svn_log) { -/* Value length excludes terminating nul. */ - rev_ctx.log =log_copy (len +1 , val); - }else if (key == keys.svn_author) { - rev_ctx.author =pool_intern (val); - }else if (key == keys.svn_date) { -if (parse_date_basic (val, &rev_ctx.timestamp,NULL )) -fprintf (stderr,"Invalid timestamp: %s\n" , val); - }else if (key == keys.svn_executable) { - node_ctx.type =REPO_MODE_EXE ; - }else if (key == keys.svn_special) { - node_ctx.type =REPO_MODE_LNK ; - } +handle_property (key, val, len); key = ~0 ;buffer_read_line (); }
Signature · 1 line
1.7.2.3
PATCH 14/15 vcs-svn: Sharpen parsing of property lines
In reply to Jonathan NiederPrepare to add a new type of property line (the 'D' line) to handle property deltas.
--- vcs-svn/svndump.c | 30 +++++++++++++++++++----------- 1 files changed, 19 insertions(+), 11 deletions(-)
vcs-svn/svndump.c +19 -11
@@ -134,21 +134,29 @@ static void handle_property(uint32_t key, const char *val, uint32_t len)static void read_props (void ) { -uint32_t len;uint32_t key = ~0 ; -char *val =NULL ; -char *t; +const char *t;while ((t =buffer_read_line ()) &&strcmp (t,"PROPS-END" )) { -if (!strncmp (t,"K " ,2 )) { - len =atoi (&t[2 ]); - key =pool_intern (buffer_read_string (len)); -buffer_read_line (); - }else if (!strncmp (t,"V " ,2 )) { - len =atoi (&t[2 ]); - val =buffer_read_string (len); +uint32_t len; +const char *val; +const char type = t[0 ]; + +if (!type || t[1 ] !=' ' ) +die ("invalid property line: %s\n" , t); + len =atoi (&t[2 ]); + val =buffer_read_string (len); +buffer_skip_bytes (1 );/* Discard trailing newline. */ + +switch (type) { +case 'K' : + key =pool_intern (val); +continue ; +case 'V' :handle_property (key, val, len); key = ~0 ; -buffer_read_line (); +continue ; +default : +die ("invalid property line: %s\n" , t); } } }
Signature · 1 line
1.7.2.3
PATCH 15/15 vcs-svn: Implement Prop-delta handling
In reply to Jonathan NiederFrom: David Barr <[email protected]>
The rules for what file is used as delta source for each file are not documented in dump-load-format.txt. Luckily, the Apache Software Foundation repository has rich enough examples to figure out most of the rules:
Node-action: replace implies the empty property set and empty text as preimage for deltas. Otherwise, if a copyfrom source is given, that node is the preimage for deltas. Lastly, if none of the above applies and the node path exists in the current revision, then that version forms the basis.
[jn: refactored, with tests]
---
That's the end of this chapter. Thanks for reading.
In the next chapter, the line_buffer lib will gain the ability to read from multiple files (based on some patches seen on the list before) and use this ability to manage the cat-blob-fd and some temporary files for applying deltas.
Reading from the cat-blob-fd with stdio functions carries a great risk of deadlock, so we need to find a way to do this without fdopen() (some routines for doing this are already written and usable, but they haven't been made into a nice library yet).
t/t9010-svn-fe.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++- vcs-svn/svndump.c | 54 +++++++++++++++++++++++----- 2 files changed, 144 insertions(+), 12 deletions(-)
t/t9010-svn-fe.sh +100 -2
@@ -514,7 +514,12 @@ test_expect_success 'deltas not supported' ' test_must_fail test-svn-fe delta.dump ' -test_expect_success 'property deltas not supported' ' +test_expect_success 'property deltas supported' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :100755 100644 OBJID OBJID M script.sh + EOF { properties \ svn:author [email protected] \
@@ -565,7 +570,100 @@ test_expect_success 'property deltas not supported' ' PROPS-END EOF } >propdelta.dump && - test_must_fail test-svn-fe propdelta.dump + test-svn-fe propdelta.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + +test_expect_success 'deltas for typechange' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T test-file + OBJID + :100755 120000 OBJID OBJID T test-file + OBJID + :000000 100755 OBJID OBJID A test-file + EOF + cat >deleteprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: add + Prop-delta: true + Prop-content-length: 35 + Text-content-length: 17 + Content-length: 52 + + K 14 + svn:executable + V 0 + + PROPS-END + link testing 123 + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 53 + Text-content-length: 17 + Content-length: 70 + + K 11 + svn:special + V 1 + * + D 14 + svn:executable + PROPS-END + link testing 231 + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 27 + Text-content-length: 17 + Content-length: 44 + + D 11 + svn:special + PROPS-END + link testing 321 + EOF + test-svn-fe deleteprop.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual ' test_expect_success 't9135/svn.dump' '
vcs-svn/svndump.c +44 -10
93 lines not on this page · raw message
Signature · 1 line
1.7.2.3
cover svn-fe: support for text deltas
In reply to Jonathan NiederQuoted 4 lines · Jonathan Nieder
Quoted 2 lines · Jonathan Nieder
This mini-series is part of an effort to get David and Ram's svn import work integrated into mainline git[1].
The next chapter. This adds handling of text deltas. I broke it in the process, though, as you can see with the attached test script:
$ testme.sh http://svn.apache.org/repos/asf 100 asf.git [...] * Dumped revision 35. error: Preimage ends early fatal: cannot apply delta
Perhaps you can take this as a puzzle. Where does the patch series go wrong?
I like to think some of the cleanup will make this more maintainable in the future, even if it is broken now.
Builds on the db/fast-import-cat-blob[1] and jn/svndiff0[2] topics.
Thoughts, improvements, complaints welcome.
David Barr (2):
vcs-svn: Let caller set up sliding window for delta preimage
vcs-svn: Implement text-delta handling
Jonathan Nieder (6):
svn-fe: Prepare for strbuf use
vcs-svn: Internal fast_export_save_blob helper
vcs-svn: Introduce repo_read_path to check the content at a path
vcs-svn: Introduce fd_buffer library
vcs-svn: Read delta preimage from file descriptor
vcs-svn: Teach line_buffer about temporary files
[1] Doesn't seem to be available on gmane.
The important part (patch 3) is, though:
http://thread.gmane.org/gmane.comp.version-control.git/161730
Should I re-send?
[2] http://thread.gmane.org/gmane.comp.version-control.git/151086/focus=158913
PATCH 1/8 svn-fe: Prepare for strbuf use
Linking svn-fe strbuf.o will require sha1_name.o and wrapper.o, hence sha1_file.o, hence libz, pthreads, and most of libgit. Luckily there is a separate patch series in flight that would trim down those dependencies again.
--- contrib/svn-fe/Makefile | 15 +++++++-------- 1 files changed, 7 insertions(+), 8 deletions(-)
contrib/svn-fe/Makefile +7 -8
@@ -8,11 +8,13 @@ CFLAGS = -g -O2 -Wall LDFLAGS = ALL_CFLAGS = $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS) -EXTLIBS = +PTHREAD_LIBS = -lpthread +EXTLIBS = -lz $(PTHREAD_LIBS) GIT_LIB = ../../libgit.a VCSSVN_LIB = ../../vcs-svn/lib.a -LIBS = $(VCSSVN_LIB) $(GIT_LIB) $(EXTLIBS) +XDIFF_LIB = ../../xdiff/lib.a +LIBS = $(VCSSVN_LIB) $(GIT_LIB) $(XDIFF_LIB) $(EXTLIBS) QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir QUIET_SUBDIR1 =
@@ -33,7 +35,7 @@ ifndef V endif endif -svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(GIT_LIB) +svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(GIT_LIB) $(XDIFF_LIB) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ svn-fe.o \ $(ALL_LDFLAGS) $(LIBS)
@@ -51,11 +53,8 @@ svn-fe.1: svn-fe.txt ../contrib/svn-fe/$@ $(MV) ../../Documentation/svn-fe.1 . -../../vcs-svn/lib.a: FORCE - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) vcs-svn/lib.a - -../../libgit.a: FORCE - $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) libgit.a +../../%.a: FORCE + $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $*.a clean: $(RM) svn-fe$X svn-fe.o svn-fe.html svn-fe.xml svn-fe.1
Signature · 1 line
1.7.2.3
PATCH 2/8 vcs-svn: Internal fast_export_save_blob helper
In reply to Jonathan NiederIntroduce fast_export_save_blob, meant to be used after printing
cat-blob :n
to the fast-import stream. It reads a response from fd 3 in cat-file --batch format. To avoid deadlock, it uses file descriptor-level calls (no stdio) and reads only one character at a time (though the latter restriction could and should be relaxed somehow --- O_NONBLOCK, perhaps).
---
The effect of this one is almost completely undone by a later patch. :)
Probably it would be better to use stdio with O_NONBLOCK, after all (David, sorry I forgot about our conversations on this before). This series uses file descriptors to be conservative, because I do not have much of a desire to test for proper O_NONBLOCK support on the relevant platforms yet.
vcs-svn/fast_export.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-)
vcs-svn/fast_export.c +87 -0
@@ -8,8 +8,10 @@#include "line_buffer.h" #include "repo_tree.h" #include "string_pool.h" +#include "strbuf.h" #define MAX_GITSVN_LINE_LEN 4096 +#define REPORT_FILENO 3static uint32_t first_commit_done;
@@ -63,6 +65,91 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log,printf ("progress Imported commit %" PRIu32".\n\n" , revision); } +static int ends_with (const char *s,size_t len,const char *suffix) +{ +const size_t suffixlen =strlen (suffix); +if (len < suffixlen) +return 0 ; +return !memcmp (s + len - suffixlen, suffix, suffixlen); +} + +static int parse_cat_response_line (const char *header,size_t *len) +{ +size_t headerlen =strlen (header); +const char *type; +const char *end; + +if (ends_with (header, headerlen," missing" )) +return error ("cat-blob reports missing blob: %s" , header); + type =memmem (header, headerlen," blob " ,strlen (" blob " )); +if (!type) +return error ("cat-blob header has wrong object type: %s" , header); + *len =strtoumax (type +strlen (" blob " ), (char **) &end,10 ); +if (end == type +strlen (" blob " )) +return error ("cat-blob header does not contain length: %s" , header); +if (*end) +return error ("cat-blob header contains garbage after length: %s" , header); +return 0 ; +} + +static struct strbuf response_line =STRBUF_INIT ; +static const char *get_response_line (void ) +{ +/* +* NEEDSWORK: Does not actually need to read one byte at a time. +* Some platforms have O_NONBLOCK. On others we could read 8 chars +* at a time until a potential appearance of " blob ". +*/ +strbuf_reset (&response_line); +for (;;) { +char buf[1 ]; +if (xread (REPORT_FILENO , buf,1 ) <0 ) { +error ("cannot read cat-blob result: %s" ,strerror (errno)); +return NULL ; + } +if (*buf =='\n' ) +return response_line.buf; +strbuf_addch (&response_line, *buf); + } +} + +static int copy_bytes (FILE *out,size_t len) +{ +char buf[4096 ]; +ssize_t nread; +for (; len; len -= nread) { + nread =xread (REPORT_FILENO , buf, + len <sizeof (buf) ? len :sizeof (buf)); +if (nread <0 ) +return error ("cannot copy cat-blob result: %s" , +strerror (errno)); +if (!nread) +return error ("0-length read..." ); +if (fwrite (buf,1 , nread, out) != nread) +return error ("cannot write cat-blob results: %s" , +strerror (errno)); + } +} + +static int fast_export_save_blob (FILE *out) +{ +size_t len = len; +const char *header, *tail; + + header =get_response_line (); +if (!header ||parse_cat_response_line (header, &len)) +return -1 ; +copy_bytes (out, len); + +/* Discard trailing newline. */ + tail =get_response_line (); +if (!tail) +return -1 ; +if (*tail) +return error ("line following cat-blob response contains garbage: %s" , tail); +return 0 ; +} +void fast_export_blob (uint32_t mode,uint32_t mark,uint32_t len) {if (mode ==REPO_MODE_LNK ) {
Signature · 1 line
1.7.2.3
PATCH 3/8 vcs-svn: Introduce repo_read_path to check the content at a path
In reply to Jonathan Niederrepo_modify_path returns the mode.
--- vcs-svn/repo_tree.c | 9 +++++++++ vcs-svn/repo_tree.h | 1 + 2 files changed, 10 insertions(+), 0 deletions(-)
vcs-svn/repo_tree.c +9 -0
@@ -157,6 +157,15 @@ static void repo_write_dirent(uint32_t *path, uint32_t mode,dent_remove (&dir_pointer (parent_dir_o)->entries, dent); } +uint32_t repo_read_path (uint32_t *path) +{ +uint32_t content_offset =0 ; +struct repo_dirent *dent =repo_read_dirent (active_commit, path); +if (dent !=NULL ) + content_offset = dent->content_offset; +return content_offset; +} +uint32_t repo_copy (uint32_t revision,uint32_t *src,uint32_t *dst) {uint32_t mode =0 , content_offset =0 ;
vcs-svn/repo_tree.h +1 -0
@@ -15,6 +15,7 @@ uint32_t next_blob_mark(void);uint32_t repo_copy (uint32_t revision,uint32_t *src,uint32_t *dst);void repo_add (uint32_t *path,uint32_t mode,uint32_t blob_mark);uint32_t repo_modify_path (uint32_t *path,uint32_t mode,uint32_t blob_mark); +uint32_t repo_read_path (uint32_t *path);void repo_delete (uint32_t *path);void repo_commit (uint32_t revision,uint32_t author,char *log,uint32_t uuid,uint32_t url,long unsigned timestamp);
Signature · 1 line
1.7.2.3
PATCH 4/8 vcs-svn: Introduce fd_buffer routines
In reply to Jonathan NiederThe fd_buffer library is perhaps poorly named, because it does not manage its own buffer. These functions provide the relevant functionality from line_buffer for low-level, unbuffered (file descriptor) I/O.
The purpose is to preserve convenience while avoiding deadlock that could occur from too greedily reading ahead in the cat-blob-fd pipe. (An alternative approach to achieve the same effect would be to set the O_NONBLOCK flag on the pipe fd.)
--- Makefile | 5 ++- vcs-svn/fast_export.c | 45 ++++++++++------------------------ vcs-svn/fd_buffer.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/fd_buffer.h | 19 ++++++++++++++ 4 files changed, 100 insertions(+), 34 deletions(-) create mode 100644 vcs-svn/fd_buffer.c create mode 100644 vcs-svn/fd_buffer.h
Makefile +3 -2
@@ -1760,7 +1760,7 @@ ifndef NO_CURL endif XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o -VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o \ +VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o vcs-svn/fd_buffer.o \ vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o \ vcs-svn/sliding_window.o vcs-svn/svndiff.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS)
@@ -1889,7 +1889,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ $(VCSSVN_OBJS): \ vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h \ vcs-svn/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \ - vcs-svn/sliding_window.h vcs-svn/svndump.h vcs-svn/svndiff.h + vcs-svn/sliding_window.h vcs-svn/svndump.h vcs-svn/svndiff.h \ + vcs-svn/fd_buffer.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/fast_export.c +13 -32
71 lines not on this page · raw message
vcs-svn/fd_buffer.c new file +65 -0
65 lines not on this page · raw message
vcs-svn/fd_buffer.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef FD_BUFFER_H +#define FD_BUFFER_H + +#include "strbuf.h" + +/* Low-level input helpers. Usually line_buffer is a better choice. */ + +extern int fd_read_line (struct strbuf *line,int fd); +extern int fd_read_binary (struct strbuf *buf,size_t len,int fd); + +/* returns 0 for end of file */ +extern off_t fd_copy_bytes (FILE *out,int fd,off_t len); + +static inline off_t fd_skip_bytes (int fd,off_t len) +{ +return fd_copy_bytes (NULL , fd, len); +} + +#endif
Signature · 1 line
1.7.2.3
PATCH 5/8 vcs-svn: Read delta preimage from file descriptor
In reply to Jonathan NiederTeach 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.
--- 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(-)
test-svn-fe.c +5 -5
@@ -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 ; }
vcs-svn/sliding_window.c +9 -12
@@ -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 ; }
vcs-svn/sliding_window.h +1 -1
@@ -4,7 +4,7 @@#include "strbuf.h" struct view { -struct line_buffer *file; +int fd;off_t off;struct strbuf buf; };
vcs-svn/svndiff.c +3 -3
@@ -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;
vcs-svn/svndiff.h +1 -1
@@ -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
Signature · 1 line
1.7.2.3
PATCH 6/8 vcs-svn: Let caller set up sliding window for delta preimage
In reply to Jonathan NiederThe 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"]
---
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(-)
test-svn-fe.c +5 -3
@@ -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 ; }
vcs-svn/svndiff.c +8 -15
@@ -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 ; }
vcs-svn/svndiff.h +2 -1
@@ -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
Signature · 1 line
1.7.2.3
Re: [PATCH 6/8] vcs-svn: Let caller set up sliding window for delta preimage
Quoted 10 lines · Jonathan Nieder
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_applyto 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 <[email protected]>Signed-off-by Jonathan Nieder <[email protected]>
This one is
From: David Barr <[email protected]>
Sorry, I keep on forgetting to preserve pseudo-header (is there a format-patch option to move it to the body?).
PATCH 7/8 vcs-svn: Teach line_buffer about temporary files
In reply to Jonathan NiederIt can sometimes be useful to write information temporarily to file, to read back later. These functions allow you to do so.
The dump file importer would use this to save a postimage from delta application until the length is known and fast-import is ready to read it.
--- vcs-svn/line_buffer.c | 24 ++++++++++++++++++++++++ vcs-svn/line_buffer.h | 7 ++++++- vcs-svn/line_buffer.txt | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletions(-)
vcs-svn/line_buffer.c +24 -0
@@ -42,6 +42,30 @@ int buffer_at_eof(struct line_buffer *buf)return 0 ; } +int buffer_tmpfile_init (struct line_buffer *buf) +{ + buf->infile =tmpfile (); +if (!buf->infile) +return error ("cannot open temporary file: %s" ,strerror (errno)); +return 0 ; +} + +FILE *buffer_tmpfile_rewind (struct line_buffer *buf) +{ +rewind (buf->infile); +return buf->infile; +} + +long buffer_tmpfile_prepare_to_read (struct line_buffer *buf) +{ +long pos =ftell (buf->infile); +if (pos <0 ) +return error ("ftell error: %s" ,strerror (errno)); +if (fseek (buf->infile,0 ,SEEK_SET )) +return error ("seek error: %s" ,strerror (errno)); +return pos; +} +int buffer_read_char (struct line_buffer *buf) {return fgetc (buf->infile);
vcs-svn/line_buffer.h +6 -1
@@ -16,12 +16,17 @@ int buffer_init(struct line_buffer *buf, const char *filename);int buffer_deinit (struct line_buffer *buf);int buffer_ferror (struct line_buffer *buf);int buffer_at_eof (struct line_buffer *buf); +void buffer_reset (struct line_buffer *buf); + +int buffer_tmpfile_init (struct line_buffer *buf); +FILE *buffer_tmpfile_rewind (struct line_buffer *buf);/* prepare to write. */ +long buffer_tmpfile_prepare_to_read (struct line_buffer *buf); +char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len);int buffer_read_char (struct line_buffer *buf);void buffer_read_binary (struct strbuf *sb,uint32_t len,struct line_buffer *f);void buffer_copy_bytes (struct line_buffer *buf,off_t len);off_t buffer_skip_bytes (struct line_buffer *buf,off_t len); -void buffer_reset (struct line_buffer *buf);#endif
vcs-svn/line_buffer.txt +22 -0
@@ -24,6 +24,28 @@ The calling program: When finished, the caller can use `buffer_reset` to deallocate resources. +Using temporary files +--------------------- + +Sometimes a file is just a convenient place to stash data for +later. A program + + - initializes a `struct line_buffer` to LINE_BUFFER_INIT + - allocates a temporary file with `buffer_tmpfile_init` + - acquires an output handle by calling `buffer_tmpfile_rewind` + - uses standard I/O functions like `fprintf` and `fwrite` to fill + the temporary file + - declares writing is over with `buffer_tmpfile_prepare_to_read` + - can re-read what was written with `buffer_read_line`, + `buffer_read_string`, and so on + - can reuse the temporary file by calling `buffer_tmpfile_rewind` + again + - cleans up the temporary file with `buffer_deinit`, perhaps to + reuse the line_buffer for some other file. + +When finished, the program should use `buffer_reset` to deallocate +resources. + Functions ---------
Signature · 1 line
1.7.2.3
PATCH 8/8 vcs-svn: Implement text-delta handling
In reply to Jonathan NiederFrom: David Barr <[email protected]>
Handle input in Subversion's dumpfile format, version 3. This is the format produced by "svnrdump dump" and "svnadmin dump --deltas", and the main difference between v3 dumpfiles and the dumpfiles already handled is that these can include nodes whose properties and text are expressed relative to some other node.
To handle such nodes, we find which node the text and properties are based on, handle its property changes, use the cat-blob command to request the basis blob from the fast-import backend, use the svndiff0_apply() helper to apply the text delta on the fly, writing output to a temporary file, and then measure that postimage file's length and write its content to the fast-import stream.
The temporary postimage file is shared between delta-using nodes to avoid some file system overhead.
The svn-fe interface needs to be more complicated to accomodate the backward flow of information from the fast-import backend to svn-fe. The interface for parsing streams without deltas is unchanged, though.
NEEDSWORK: generalize interface so caller sets the backflow fd, close temporary file before exiting
--- contrib/svn-fe/svn-fe.txt | 11 ++++-- t/t9010-svn-fe.sh | 16 +++++++- vcs-svn/fast_export.c | 88 +++++++++++++++++++++++++++++++------------- vcs-svn/fast_export.h | 3 ++ vcs-svn/svndump.c | 19 +++++++--- 5 files changed, 99 insertions(+), 38 deletions(-)
contrib/svn-fe/svn-fe.txt +7 -4
@@ -7,7 +7,13 @@ svn-fe - convert an SVN "dumpfile" to a fast-import stream SYNOPSIS -------- -svnadmin dump --incremental REPO | svn-fe [url] | git fast-import +svnadmin dump REPO | svn-fe [url] | git fast-import + +[verse] +mkfifo backchannel && +svnadmin dump --deltas REPO | + svn-fe [url] 3<backchannel | + git fast-import --cat-blob-fd=3 3>backchannel DESCRIPTION -----------
@@ -25,9 +31,6 @@ Subversion's repository dump format is documented in full in Files in this format can be generated using the 'svnadmin dump' or 'svk admin dump' command. -Dumps produced with 'svnadmin dump --deltas' (dumpfile format v3) -are not supported. - OUTPUT FORMAT ------------- The fast-import format is documented by the git-fast-import(1)
t/t9010-svn-fe.sh +14 -2
@@ -35,6 +35,14 @@ text_no_props () { >empty +test_expect_success 'setup: have pipes?' ' + rm -f frob && + if mkfifo frob + then + test_set_prereq PIPE + fi +' + test_expect_success 'empty dump' ' reinit_git && echo "SVN-fs-dump-format-version: 2" >input &&
@@ -451,7 +459,9 @@ test_expect_success 'change file mode and reiterate content' ' test_cmp hello actual.target ' -test_expect_success 'deltas not supported' ' +test_expect_success PIPE 'deltas supported' ' + reinit_git && + rm -f backflow && { # (old) h + (inline) ello + (old) \n printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" |
@@ -511,7 +521,9 @@ test_expect_success 'deltas not supported' ' echo PROPS-END && cat delta } >delta.dump && - test_must_fail test-svn-fe delta.dump + mkfifo backflow && + test_must_fail test-svn-fe delta.dump 3<backflow | + git fast-import --cat-blob-fd=3 3>backflow ' test_expect_success 'property deltas supported' '
vcs-svn/fast_export.c +62 -26
113 lines not on this page · raw message
vcs-svn/fast_export.h +3 -0
@@ -10,5 +10,8 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid, uint32_t url, unsigned long timestamp);void fast_export_blob (uint32_t mode,uint32_t mark,uint32_t len,struct line_buffer *input); +void fast_export_blob_delta (uint32_t mode,uint32_t mark, +uint32_t old_mode,uint32_t old_mark, +uint32_t len,struct line_buffer *input);#endif
vcs-svn/svndump.c +13 -6
@@ -198,12 +198,10 @@ static void read_props(void)static void handle_node (void ) { -uint32_t mark =0 ; +uint32_t mark =0 , old_mode, old_mark;const uint32_t type = node_ctx.type;const int have_props = node_ctx.propLength !=LENGTH_UNKNOWN ; -if (node_ctx.text_delta) -die ("text deltas not supported" );if (node_ctx.textLength !=LENGTH_UNKNOWN ) mark =next_blob_mark ();if (node_ctx.action ==NODEACT_DELETE ) {
@@ -224,7 +222,9 @@ static void handle_node(void)if (mark && type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" );if (node_ctx.action ==NODEACT_CHANGE ) { -uint32_t mode =repo_modify_path (node_ctx.dst,0 , mark); +uint32_t mode; + old_mark =repo_read_path (node_ctx.dst); + mode =repo_modify_path (node_ctx.dst,0 , mark);if (!mode)die ("invalid dump: path to be modified is missing" );if (mode ==REPO_MODE_DIR && type !=REPO_MODE_DIR )
@@ -236,11 +236,12 @@ static void handle_node(void)if (!mark && type !=REPO_MODE_DIR )die ("invalid dump: adds node without text" );repo_add (node_ctx.dst, type, mark); + old_mark =0 ; }else {die ("invalid dump: Node-path block lacks Node-action" ); } + old_mode = node_ctx.type;if (have_props) { -const uint32_t old_mode = node_ctx.type;if (!node_ctx.prop_delta) node_ctx.type = type;if (node_ctx.propLength)
@@ -248,8 +249,14 @@ static void handle_node(void)if (node_ctx.type != old_mode)repo_modify_path (node_ctx.dst, node_ctx.type, mark); } -if (mark) +if (!mark) +return ; +if (!node_ctx.text_delta) {fast_export_blob (node_ctx.type, mark, node_ctx.textLength, &input); +return ; + } +fast_export_blob_delta (node_ctx.type, mark, old_mode, old_mark, + node_ctx.textLength, &input); }static void handle_revision (void )
Signature · 1 line
1.7.2.3
[PATCH 9/8] svn-fe: Test script for handling of dumps with --deltas
In reply to Jonathan Nieder--- contrib/svn-fe/testme.sh | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) create mode 100755 contrib/svn-fe/testme.sh
contrib/svn-fe/testme.sh new file +16 -0
@@ -0,0 +1,16 @@ +#!/bin/sh +# Usage: +# PATH=${git_src}/contrib/svn-fe:${git_src}/bin-wrappers:$PATH +# testme.sh http://cvs2svn.tigris.org/svn/cvs2svn 10 test.git +set -e +: ${1?"URL?"} +: ${2?"How many revisions?"} +: ${3?"Git directory?"} + +git init --bare "$3" +rm -f "$3/backflow" +mkfifo "$3/backflow" + +svnrdump dump -r1:"$2" "$1" | +svn-fe 3<backflow | +GIT_DIR=$3 git fast-import --cat-blob-fd=3 3>backflow
Signature · 1 line
1.7.2.3
Re: [PATCH 11/15] vcs-svn: More dump format sanity checks
In reply to Jonathan NiederQuoted 3 lines · Jonathan Nieder
vcs-svn/svndump.c +0
-0@@ -181,12 +181,22 @@ static void handle_node(void)
[...]
vcs-svn/svndump.c
Quoted 2 lines
vcs-svn/svndump.c +2
-0+if (mode ==REPO_MODE_DIR && type !=REPO_MODE_DIR ) +die ("invalid dump: cannot modify a directory into a file" );
This is tripping for me in a revision like so:
Revision-number: 692
Prop-content-length: 110
Content-length: 110
[revprops snipped]
Node-path: lxanew/DCNsnetwork.cpp
Node-kind: file
Node-action: add
Node-copyfrom-rev: 691
Node-copyfrom-path: DCNsnetwork.cpp
Node-path: DCNsnetwork.cpp
Node-action: delete
The import up to and including rev 691 works fine. Rev 691:
Revision-number: 691
Prop-content-length: 110
Content-length: 110
[props snipped]
Node-path: lxanew/CorpusWordCollection.cpp
Node-kind: file
Node-action: add
Node-copyfrom-rev: 690
Node-copyfrom-path: CorpusWordCollection.cpp
Node-path: CorpusWordCollection.cpp
Node-action: delete
Pretty similar, right? In the target repository:
$ git ls-tree HEAD -- DCNsnetwork.cpp 100644 blob f92d77cc88cc50e9ca333604d22db83f0668828a DCNsnetwork.cpp
DCNsnetwork.cpp was added in r688, which looks like so:
Revision-number: 688
Prop-content-length: 186
Content-length: 186
[props and many new files snipped]
Node-path: DCNsnetwork.cpp
Node-kind: file
Node-action: add
Prop-delta: true
Prop-content-length: 10
Text-delta: true
Text-content-length: 2999
Text-content-md5: 48fd4d31d16f90ab449b4d223fc3d7f8
Content-length: 3009
PROPS-END
SVN^@^@^@<97>)^C<97>)<80><97>)// snetwork.cpp: implementation of the snetwork class. [...]
So apparently repo_add failed. Hints?
Here's an unrelated simplification, noticed while debugging.
---
vcs-svn/svndump.c +1 -0
@@ -219,6 +219,7 @@ static void handle_node(void)die ("invalid dump: adds node without text" );repo_add (node_ctx.dst, type, mark); old_mark =0 ; + node_ctx.type = type; }else {die ("invalid dump: Node-path block lacks Node-action" ); }
PATCH 2/2 vcs-svn: fix intermittent repo_tree corruption
In reply to a message not in the archivePointers to directory entries do not remain valid after a call to dent_insert.
Noticed in the course of importing a small Subversion repository (~1000 revs); after setting up a dirent for a certain path as a placeholder, by luck dent_insert would trigger a realloc that shifted around addresses, resulting in an import with that file replaced by a directory.
---
Tested using the aforementioned small svn repository. Any ideas for a more reliable test to include in the test suite? Maybe some hack to force realloc to always move the memory it controls, like
in git-compat-util.h:
#ifdef WANT_SKITTISH_REALLOC
#define realloc skittish_realloc
#endif
in compat/realloc.c:
#undef realloc
void *skittish_realloc(void *ptr, size_t size)
{
void *result, *tmp;
dest = malloc(size);
ptr = realloc(ptr, size);
if (!ptr || !dest);
return NULL;
memcpy(dest, ptr, size);
return dest;
}?
vcs-svn/repo_tree.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
vcs-svn/repo_tree.c +2 -2
@@ -131,7 +131,7 @@ static void repo_write_dirent(uint32_t *path, uint32_t mode,if (dent == key) { dent->mode =REPO_MODE_DIR ; dent->content_offset =0 ; -dent_insert (&dir->entries, dent); + dent =dent_insert (&dir->entries, dent); }if (dent_offset (dent) < dent_pool.committed) {
@@ -142,7 +142,7 @@ static void repo_write_dirent(uint32_t *path, uint32_t mode, dent->name_offset = name; dent->mode =REPO_MODE_DIR ; dent->content_offset = dir_o; -dent_insert (&dir->entries, dent); + dent =dent_insert (&dir->entries, dent); } dir =repo_dir_from_dirent (dent);
Signature · 1 line
1.7.2.4
cover intermittent repo_tree corruption
In reply to Jonathan Nieder[mailer usage fail. resending to git@vger; sorry for the noise]
Hi David,
Quoted 9 lines · Jonathan Nieder
Quoted 2 lines · Jonathan Nieder
+++
b/vcs-svn/svndump.c(quoted diff) +0
-0@@ -181,12 +181,22 @@ static void handle_node(void)[...]
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (mode == REPO_MODE_DIR && type != REPO_MODE_DIR) + die("invalid dump: cannot modify a directory into a file");This is tripping for me in a revision like so:
[...]
Quoted 3 lines
Node-path: lxanew/DCNsnetwork.cpp
Node-kind: file
Node-action: add
[...]
Quoted 1 line
DCNsnetwork.cpp was added in r688, which looks like so:
[...]
Quoted 3 lines
Node-path: DCNsnetwork.cpp
Node-kind: file
Node-action: add
This is a bad one. Currently, repo_copy builds new nodes for all directories containing the destination directory, like so:
for each path component:
find that node, creating if missing
make sure it is in the active commit (cloning if not) set mode to MODE_DIR and set up the next iteration to look there.
set mode and content based on source path
Unfortunately the "create if missing" and "make sure it is the active commit" steps call realloc without updating the corresponding pointers.
svn-fe2 (as contained in git 1.7.3) and svn-fe3 are both affected, presumably. Probably existing testing missed this because the repo_tree pool quickly grows large enough that glibc allocates with mmap(), with little need to change addresses within a huge 64-bit address space.
Jonathan Nieder (2):
treap: make treap_insert return inserted node
vcs-svn: fix intermittent repo_tree corruption
test-treap.c | 11 ++++++++--- vcs-svn/repo_tree.c | 4 ++-- vcs-svn/trp.h | 3 ++- vcs-svn/trp.txt | 10 ++++++++-- 4 files changed, 20 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.2.4
PATCH 1/2 treap: make treap_insert return inserted node
Suppose I try the following:
struct int_node *node = node_pointer(node_alloc(1));
node->n = 5;
treap_insert(&root, node);
printf("%d\n", node->n);Usually the result will be 5. But since treap_insert draws memory from the node pool, if the caller is unlucky then (1) the node pool will be full and (2) realloc will be forced to move the node pool to find room, so the node address becomes invalid and the result of dereferencing it is undefined.
So we ought to use offsets in preference to pointers for references that would remain valid after a call to treap_insert. Tweak the signature to hint at a certain special case: since the inserted node can change address (though not offset), as a convenience teach treap_insert to return its new address.
So the motivational example could be fixed by adding "node =".
struct int_node *node = node_pointer(node_alloc(1));
node->n = 5;
node = treap_insert(&root, node);
printf("%d\n", node->n);Based on a true story.
---
[resending to list --- sorry for the mess.]
test-treap.c | 11 ++++++++--- vcs-svn/trp.h | 3 ++- vcs-svn/trp.txt | 10 ++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-)
test-treap.c +8 -3
@@ -38,9 +38,14 @@ int main(int argc, char *argv[])usage ("test-treap < ints" );while (strbuf_getline (&sb, stdin,'\n' ) !=EOF ) { - item =node_alloc (1 ); -strtonode (node_pointer (item), sb.buf); -treap_insert (&root,node_pointer (item)); +struct int_node *node =node_pointer (node_alloc (1 )); + + item =node_offset (node); +strtonode (node, sb.buf); + node =treap_insert (&root,node_pointer (item)); +if (node_offset (node) != item) +die ("inserted %" PRIu32" in place of %" PRIu32"" , +node_offset (node), item); } item =node_offset (treap_first (&root));
vcs-svn/trp.h +2 -1
@@ -188,11 +188,12 @@ a_attr uint32_t MAYBE_UNUSED a_pre##insert_recurse(uint32_t cur_node, uint32_t ireturn ret; \ } \ } \ -a_attr void MAYBE_UNUSED a_pre##insert(struct trp_root *treap, a_type *node) \ +a_attr a_type *MAYBE_UNUSED a_pre##insert(struct trp_root *treap, a_type *node) \ { \ uint32_t offset = trpn_offset(a_base, node); \ trp_node_new(a_base, a_field, offset); \ treap->trp_root = a_pre##insert_recurse(treap->trp_root, offset); \ + return trpn_pointer(a_base, offset); \ } \ a_attr uint32_t MAYBE_UNUSED a_pre##remove_recurse(uint32_t cur_node, uint32_t rem_node) \ { \
vcs-svn/trp.txt +8 -2
@@ -21,7 +21,9 @@ The caller: . Allocates a `struct trp_root` variable and sets it to {~0}. -. Adds new nodes to the set using `foo_insert`. +. Adds new nodes to the set using `foo_insert`. Any pointers + to existing nodes cannot be relied upon any more, so the caller + might retrieve them anew with `foo_pointer`. . Can find a specific item in the set using `foo_search`.
@@ -73,10 +75,14 @@ int (*cmp)(node_type \*a, node_type \*b) and returning a value less than, equal to, or greater than zero according to the result of comparison. -void foo_insert(struct trp_root *treap, node_type \*node):: +node_type {asterisk}foo_insert(struct trp_root *treap, node_type \*node):: Insert node into treap. If inserted multiple times, a node will appear in the treap multiple times. ++ +The return value is the address of the node within the treap, +which might differ from `node` if `pool_alloc` had to call +`realloc` to expand the pool. void foo_remove(struct trp_root *treap, node_type \*node)::
Signature · 1 line
1.7.2.4
[PATCH 10/8] vcs-svn: Consume whole preimage when applying deltas
In reply to Jonathan NiederDate: Sun Nov 21 20:24:12 2010 -0600
Some deltas do not consume the entire preimage, so we have to consume it explicitly.
Noticed during imports from the ASF repo.
---
Quoted 2 lines · Jonathan Nieder
+++
b/vcs-svn/fast_export.c(quoted diff) +0
-0@@ -102,33 +115,39 @@ static const char *get_response_line(void)
[...]
Review
Quoted 7 lines
(quoted diff) +7
-0+ if (svndiff0_apply(input, len, &preimage, out)) + die("cannot apply delta"); + if (old_mark) { + /* Discard trailing newline from cat-blob-fd. */ + const char *tail = get_response_line(); + if (!tail || *tail) + die("missing newline after cat-blob response");
As mentioned before, this error
fatal: missing newline after cat-blob response
and
error: Preimage ends early
were sometimes triggering. Here's a fix for squashing. Sorry for the nonsensical code.
t/t9010-svn-fe.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/fast_export.c | 16 ++++--- 2 files changed, 117 insertions(+), 7 deletions(-)
t/t9010-svn-fe.sh +108 -0
@@ -678,6 +678,114 @@ test_expect_success 'deltas for typechange' ' test_cmp expect actual ' +test_expect_success PIPE 'deltas need not consume the whole preimage' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T postimage + OBJID + :100644 120000 OBJID OBJID T postimage + OBJID + :000000 100644 OBJID OBJID A postimage + EOF + echo "first preimage" >expect.1 && + printf target >expect.2 && + printf lnk >expect.3 && + rm -f backflow && + { + printf "SVNQ%b%b%b" "QQ\017\001\017" "\0217" "first preimage\n" | + q_to_nul + } >delta.1 && + { + properties svn:special "*" && + echo PROPS-END + } >symlink.props && + { + printf "SVNQ%b%b%b" "Q\002\013\004\012" "\0201\001\001\0211" "lnk target" | + q_to_nul + } >delta.2 && + { + printf "SVNQ%b%b" "Q\004\003\004Q" "\001Q\002\002" | + q_to_nul + } >delta.3 && + { + cat <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: postimage + Node-kind: file + Node-action: add + Text-delta: true + Prop-content-length: 10 + EOF + echo Text-content-length: $(wc -c <delta.1) && + echo Content-length: $((10 + $(wc -c <delta.1))) && + echo && + echo PROPS-END && + cat delta.1 && + cat <<-\EOF && + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: postimage + Node-kind: file + Node-action: change + Text-delta: true + EOF + echo Prop-content-length: $(wc -c <symlink.props) && + echo Text-content-length: $(wc -c <delta.2) && + echo Content-length: $(($(wc -c <symlink.props) + $(wc -c <delta.2))) && + echo && + cat symlink.props && + cat delta.2 && + cat <<-\EOF && + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: postimage + Node-kind: file + Node-action: change + Text-delta: true + Prop-content-length: 10 + EOF + echo Text-content-length: $(wc -c <delta.3) && + echo Content-length: $((10 + $(wc -c <delta.3))) && + echo && + echo PROPS-END && + cat delta.3 && + echo + } >deltapartial.dump && + mkfifo backflow && + test-svn-fe deltapartial.dump 3<backflow | + git fast-import --cat-blob-fd=3 3>backflow && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual && + git show HEAD:postimage >actual.3 && + git show HEAD^:postimage >actual.2 && + git show HEAD^^:postimage >actual.1 && + test_cmp expect.1 actual.1 && + test_cmp expect.2 actual.2 && + test_cmp expect.3 actual.3 +' + test_expect_success 't9135/svn.dump' ' svnadmin create simple-svn && svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" &&
vcs-svn/fast_export.c +9 -7
@@ -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;
@@ -126,22 +127,23 @@ static long apply_delta(uint32_t mark, off_t len, struct line_buffer *input,die ("cannot open temporary file for blob retrieval" );if (old_mark) {const char *response; -off_t dummy;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 ) +if (old_mode ==REPO_MODE_LNK ) {strbuf_addstr (&preimage.buf,"link " ); + preimage_len +=strlen ("link " ); + }if (svndiff0_apply (input, len, &preimage, out))die ("cannot apply delta" );if (old_mark) { -/* Discard trailing newline from cat-blob-fd. */ -const char *tail =get_response_line (); -if (!tail || *tail) +/* Read the remainder of preimage and trailing newline. */ +if (move_window (&preimage, preimage_len,1 )) +die ("cannot seek to end of input" ); +if (preimage.buf.buf[0 ] !='\n' )die ("missing newline after cat-blob response" ); } ret =buffer_tmpfile_prepare_to_read (&postimage);
Signature · 1 line
1.7.2.4
Re: [PATCH 9/8] svn-fe: Test script for handling of dumps with --deltas
In reply to Jonathan NiederQuoted 8 lines · Jonathan Nieder
+++
b/contrib/svn-fe/testme.shcontrib/svn-fe/testme.sh new file +6
-0@@ -0,0 +1,16 @@ +#!/bin/sh +# Usage: +# PATH=${git_src}/contrib/svn-fe:${git_src}/bin-wrappers:$PATH +# testme.sh http://cvs2svn.tigris.org/svn/cvs2svn 10 test.git +set -e +: ${1?"URL?"}
contrib/svn-fe/testme.sh line 16
Quoted 10 lines
contrib/svn-fe/testme.sh new file +10
-0+: ${2?"How many revisions?"} +: ${3?"Git directory?"} + +git init --bare "$3" +rm -f "$3/backflow" +mkfifo "$3/backflow" + +svnrdump dump -r1:"$2" "$1" | +svn-fe 3<backflow | +GIT_DIR=$3 git fast-import --cat-blob-fd=3 3>backflow
In case someone was puzzled: backflow should be "$3/backflow" on these last two lines.
I didn't notice at first because there was already a fifo available in the cwd during testing.
PATCH 1/1 vcs-svn: Allow change nodes for root of tree (/)
In reply to Jonathan NiederIt is not uncommon for a svn repository to include change records for properties at the top level of the tracked tree:
Node-path: Node-kind: dir Node-action: change Prop-delta: true Prop-content-length: 43 Content-length: 43 K 10 svn:ignore V 11 build-area PROPS-END
Unfortunately a recent svn-fe change (vcs-svn: More dump format sanity checks, 2010-11-19) causes such nodes to be rejected with the error message
fatal: invalid dump: path to be modified is missing
The repo_tree module does not keep a dirent for the root of the tree. Add a block to the dump parser to take care of this case.
--- t/t9010-svn-fe.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.c | 5 +++- 2 files changed, 77 insertions(+), 1 deletions(-)
t/t9010-svn-fe.sh +73 -0
@@ -580,6 +580,79 @@ test_expect_success 'property deltas supported' ' test_cmp expect actual ' +test_expect_success 'properties on /' ' + reinit_git && + cat <<-\EOF >expect && + OBJID + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + sed -e "s/X$//" <<-\EOF >changeroot.dump && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Text-content-length: 0 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: X + Node-kind: dir + Node-action: change + Prop-delta: true + Prop-content-length: 43 + Content-length: 43 + + K 10 + svn:ignore + V 11 + build-area + + PROPS-END + EOF + echo Revision-number: 2 && + echo Prop-content-length: $(wc -c <revprops) && + echo Content-length: $(wc -c <revprops) && + echo && + cat revprops && + echo && + cat <<-\EOF + Node-path: script.sh + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 30 + Content-length: 30 + + D 14 + svn:executable + PROPS-END + EOF + test-svn-fe changeroot.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --always --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + test_expect_success 'deltas for typechange' ' reinit_git && cat >expect <<-\EOF &&
vcs-svn/svndump.c +4 -1
@@ -203,7 +203,10 @@ static void handle_node(void) }if (mark && type ==REPO_MODE_DIR )die ("invalid dump: directories cannot have text attached" ); -if (node_ctx.action ==NODEACT_CHANGE ) { +if (node_ctx.action ==NODEACT_CHANGE && !~*node_ctx.dst) { +if (type !=REPO_MODE_DIR ) +die ("invalid dump: root of tree is not a regular file" ); + }else if (node_ctx.action ==NODEACT_CHANGE ) {uint32_t mode =repo_modify_path (node_ctx.dst,0 , mark);if (!mode)die ("invalid dump: path to be modified is missing" );
Signature · 1 line
1.7.2.4
Re: [PATCH jn/svn-fe] vcs-svn: Allow change nodes for root of tree (/)
Quoted 4 lines · Jonathan Nieder
--- t/t9010-svn-fe.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.c | 5 +++- 2 files changed, 77 insertions(+), 1 deletions(-)
Hmph, some extra (but harmless) text snuck into the test. :/
-- 8< --
Subject: fixup! vcs-svn: Allow change nodes for root of tree (/)
Some pointless, unrelated code stowed away while resolving conflicts during a cherry-pick. Remove it.
--- t/t9010-svn-fe.sh | 18 ------------------ 1 files changed, 0 insertions(+), 18 deletions(-)
t/t9010-svn-fe.sh +0 -18
@@ -625,24 +625,6 @@ test_expect_success 'properties on /' ' PROPS-END EOF - echo Revision-number: 2 && - echo Prop-content-length: $(wc -c <revprops) && - echo Content-length: $(wc -c <revprops) && - echo && - cat revprops && - echo && - cat <<-\EOF - Node-path: script.sh - Node-kind: file - Node-action: change - Prop-delta: true - Prop-content-length: 30 - Content-length: 30 - - D 14 - svn:executable - PROPS-END - EOF test-svn-fe changeroot.dump >stream && git fast-import <stream && {
Signature · 1 line
1.7.2.4
Re: [PATCH 3/8] vcs-svn: Introduce repo_read_path to check the content at a path
In reply to Jonathan NiederHi,
Quoted 3 lines · Jonathan Nieder
repo_modify_pathreturns the mode.Signed-off-by Jonathan Nieder <[email protected]>
Another cryptic commit message.
A long-winded explanation follows. Please feel free to ignore it, or even better, come up with a summary to use as change description that people can refer to for this patch in the future. :)
It is currently possible to _modify_ both the mode and the text at a path but there is only public functionality to retrieve the mode. In its original context, this patch added analogous functionality to retrieve the text (indexed by a blob name) as preparation for applying a delta to it.
In the vcs-svn-incremental series, it will allow us to restructure handle_node() a little: instead of making little modifications to an in-memory cache managed by the repo-tree library (saying, "change the mode this way but keep the content; now keep the mode but change the content"), handle_node can take responsibility for figuring out what will be the final mode and content for the path in question.
In other words, a later patch will change handle_node (in the
Node-action: change case) from looking like
/* Change text at path. */
mode = repo_modify_path(path, 0, have_text ? text : 0);
/* Change mode at path. */
if (have_props) {
read_props(&new_mode);
if (new_mode != mode)
repo_modify_path(path, new_mode, have_text ? text : 0);
}to
/* Determine desired text and mode at path. */ old_text = repo_read_path(path); old_mode = repo_modify_path(path, 0, 0); if (have_props) read_props(old_mode, &mode); if (!have_text) text = old_text; /* Make it so. */ repo_add(path, mode, text);
It is also just nice to have a function like this, to make the API less surprising.