Resurrect rr/svn-export
cover Resurrect rr/svn-export
Hi,
I've decided to get this series merged now instead of waiting for the ternary treap refactor. It's in excellent shape, thanks to Jonathan's constant reviews/ fixes and David's constant refactoring. Since Jonathan's last send, I've incoporated some suggestions from my own review of Jonathan's series and split it into two series as I proposed earlier; I'll send the second series (rr/contrib-svn-fe) shortly after this.
Once this series is merged, I estimate that the following will come in as incremental patches when the work is finished:
rr/ternary-trp-refactor
rr/zero-tree-refactor
rr/dumpfilev3-parser
Thanks.
-- Ram
David Barr (5):
Add memory pool library
Add string-specific memory pool
Add stream helper library
Add infrastructure to write revisions in fast-export format Add SVN dump parser
Jason Evans (1):
Add treap implementation
Jonathan Nieder (2):
Export parse_date_basic() to convert a date string to timestamp Introduce vcs-svn lib
Makefile | 12 ++- cache.h | 1 + date.c | 14 +-- vcs-svn/LICENSE | 33 +++++ vcs-svn/fast_export.c | 75 +++++++++++ vcs-svn/fast_export.h | 14 ++ vcs-svn/line_buffer.c | 93 ++++++++++++++ vcs-svn/line_buffer.h | 14 ++ vcs-svn/obj_pool.h | 80 ++++++++++++ vcs-svn/repo_tree.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/repo_tree.h | 26 ++++ vcs-svn/string_pool.c | 114 +++++++++++++++++ vcs-svn/string_pool.h | 15 +++ vcs-svn/svndump.c | 289 ++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.h | 8 ++ vcs-svn/trp.h | 220 ++++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 102 +++++++++++++++ 17 files changed, 1436 insertions(+), 9 deletions(-) create mode 100644 vcs-svn/LICENSE create mode 100644 vcs-svn/fast_export.c create mode 100644 vcs-svn/fast_export.h create mode 100644 vcs-svn/line_buffer.c create mode 100644 vcs-svn/line_buffer.h create mode 100644 vcs-svn/obj_pool.h create mode 100644 vcs-svn/repo_tree.c create mode 100644 vcs-svn/repo_tree.h create mode 100644 vcs-svn/string_pool.c create mode 100644 vcs-svn/string_pool.h create mode 100644 vcs-svn/svndump.c create mode 100644 vcs-svn/svndump.h create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
PATCH 1/8 Export parse_date_basic() to convert a date string to timestamp
From: Jonathan Nieder <[email protected]>
approxidate() is not appropriate for reading machine-written dates because it guesses instead of erroring out on malformed dates. parse_date() is less convenient since it returns its output as a string. So export the underlying function that writes a timestamp.
While at it, change the return value to match the usual convention:
return 0 for success and -1 for failure.
--- cache.h | 1 + date.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-)
cache.h +1 -0
@@ -811,6 +811,7 @@ const char *show_date_relative(unsigned long time, int tz,char *timebuf, size_t timebuf_size);int parse_date (const char *date,char *buf,int bufsize); +int parse_date_basic (const char *date,unsigned long *timestamp,int *offset);void datestamp (char *buf,int bufsize);#define approxidate (s) approxidate_careful((s), NULL)unsigned long approxidate_careful (const char *,int *);
date.c +6 -8
@@ -586,7 +586,7 @@ static int date_string(unsigned long date, int offset, char *buf, int len)/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822 (i.e. English) day/month names, and it doesn't work correctly with %z. */ -int parse_date_toffset (const char *date,unsigned long *timestamp,int *offset) +int parse_date_basic (const char *date,unsigned long *timestamp,int *offset) {struct tm tm;int tm_gmt;
@@ -642,17 +642,16 @@ int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)if (!tm_gmt) *timestamp -= *offset *60 ; -return 1 ;/* success */ +return 0 ;/* success */ }int parse_date (const char *date,char *result,int maxlen) {unsigned long timestamp;int offset; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) -return date_string (timestamp, offset, result, maxlen); -else +if (parse_date_basic (date, ×tamp, &offset))return -1 ; +return date_string (timestamp, offset, result, maxlen); }enum date_mode parse_date_format (const char *format)
@@ -1004,9 +1003,8 @@ unsigned long approxidate_relative(const char *date, const struct timeval *tv)int offset;int errors =0 ; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) +if (!parse_date_basic (date, ×tamp, &offset))return timestamp; -return approxidate_str (date, tv, &errors); }
@@ -1019,7 +1017,7 @@ unsigned long approxidate_careful(const char *date, int *error_ret)if (!error_ret) error_ret = &dummy; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) { +if (!parse_date_basic (date, ×tamp, &offset)) { *error_ret =0 ;return timestamp; }
Signature · 1 line
1.7.1
Re: [PATCH 1/8] Export parse_date_basic() to convert a date string to timestamp
Quoted 7 lines · Ramkumar Ramachandra
approxidate()is not appropriate for reading machine-written dates because it guesses instead of erroring out on malformed dates.parse_date()is less convenient since it returns its output as a string. So export the underlying function that writes a timestamp.While at it, change the return value to match the usual convention:
return 0 for success and -1 for failure.
Junio: I think this should be ejected from the series as an independently useful cleanup.
Currently parse_date_toffset() is exported but not declared anywhere. This patch gives it a more predictable API and adds a declaration.
Ram: thanks for the reminder.
Re: [PATCH 1/8] Export parse_date_basic() to convert a date string to timestamp
Quoted 5 lines · Jonathan Nieder
Junio: I think this should be ejected from the series as an independently useful cleanup.
Currently
parse_date_toffset()is exported but not declared anywhere. This patch gives it a more predictable API and adds a declaration.
Yeah, that makes sense. What this patch does seems to be what c5043cc (Refactor parse_date for approxidate functions, 2010-06-03) should have done from the beginning.
Thanks.
PATCH 2/8 Introduce vcs-svn lib
In reply to Ramkumar RamachandraFrom: Jonathan Nieder <[email protected]>
Teach the build system to build a separate library for the upcoming subversion interop support.
The resulting vcs-svn/lib.a does not contain any code, nor is it built during a normal build. This is just scaffolding for later changes.
--- Makefile | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
Makefile +7 -1
@@ -468,6 +468,7 @@ export PYTHON_PATH LIB_FILE=libgit.a XDIFF_LIB=xdiff/lib.a +VCSSVN_LIB=vcs-svn/lib.a LIB_H += advice.h LIB_H += archive.h
@@ -1739,7 +1740,8 @@ ifndef NO_CURL endif XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o -OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) +VCSSVN_OBJS = +OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
@@ -1860,6 +1862,8 @@ http.o http-walker.o http-push.o remote-curl.o: http.h xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h + +$(VCSSVN_OBJS): endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@ -1908,6 +1912,8 @@ $(LIB_FILE): $(LIB_OBJS) $(XDIFF_LIB): $(XDIFF_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS) +$(VCSSVN_LIB): $(VCSSVN_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS) doc: $(MAKE) -C Documentation all
Signature · 1 line
1.7.1
Re: [PATCH 2/8] Introduce vcs-svn lib
Makefile $(LIB_FILE): $(LIB_OBJS) · line 1916
Quoted 6 lines · Ramkumar Ramachandra
Makefile +2
-0@@ -1908,6 +1912,8 @@ $(LIB_FILE): $(LIB_OBJS) $(XDIFF_LIB): $(XDIFF_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS) +$(VCSSVN_LIB): $(VCSSVN_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS)
$ make vcs-svn/lib.a V=1 rm -f vcs-svn/lib.a && ar rcs vcs-svn/lib.a ar: vcs-svn/lib.a: No such file or directory make: *** [vcs-svn/lib.a] Error 1
That is because the vcs-svn directory does not exist. So probably the LICENSE should be added with the same patch (and git should learn to track empty directories).
Jonathan
Re: [PATCH 2/8] Introduce vcs-svn lib
Hi Jonathan,
Quoted 14 lines · Jonathan Nieder
Review $(LIB_FILE): $(LIB_OBJS) · line 1916
Quoted 6 lines · Ramkumar Ramachandra
(quoted diff) +2
-0@@ -1908,6 +1912,8 @@ $(LIB_FILE): $(LIB_OBJS) $(XDIFF_LIB): $(XDIFF_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS) +$(VCSSVN_LIB): $(VCSSVN_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS)$ make vcs-svn/lib.a V=1 rm -f vcs-svn/lib.a && ar rcs vcs-svn/lib.a ar: vcs-svn/lib.a: No such file or directory make: *** [vcs-svn/lib.a] Error 1
Quoted 3 lines
That is because the vcs-svn directory does not exist. So probably the LICENSE should be added with the same patch (and git should learn to track empty directories).
Oops. Sorry about not checking this: it looked alright at a glance. Yes, we can add LICENSE with this patch.
Junio: Could you squash in this diff?
vcs-svn/LICENSE new file +26 -0
@@ -0,0 +1,26 @@ +Copyright (C) 2010 David Barr <[email protected]>. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice(s), this list of conditions and the following disclaimer + unmodified other than the allowable addition of one or more + copyright notices. +2. Redistributions in binary form must reproduce the above copyright + notice(s), this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-- Ram
PATCH 3/8 Add memory pool library
In reply to Ramkumar RamachandraFrom: David Barr <[email protected]>
Add a memory pool library implemented using C macros. The obj_pool_gen() macro creates a type-specific memory pool API.
The memory pool library is distinguished from the existing specialized allocators in alloc.c by using a contiguous block for all allocations. This means that on one hand, long-lived pointers have to be written as offsets, since the base address changes as the pool grows, but on the other hand, the entire pool can be easily written to the file system. This allows the memory pool to persist between runs of an application.
For the svn importer, such a facility is useful because each svn revision can copy trees and files from any previous revision. The relevant information for all revisions has to persist somehow to support incremental runs, and for now it is simplest to avoid relying on the target VCS for that.
obj_pool_gen(pre, obj_t, initial_capability)
pre: Prefix for generated functions (example: string).
obj_t: Type for treap data structure (example: char).
initial_capacity: Initial size of the memory pool (example: 4096).
void pre_init(void);
Read values from a previous run to initialize the pool. If this function is not called, the pool begins valid but empty.
uint32_t pre_alloc(uint32_t nmemb);
Reserve space for a few objects in the pool and return an offset to the first one.
uint32_t pre_free(uint32_t nmemb);
Unreserve the last few objects reserved.
uint32_t pre_offset(obj_t *pointer);obj_t *pre_pointer(uint32_t offset);
Convert between pointers into the in-memory pool and offsets from the beginning (or ~0 for the NULL pointer). Pointers are not guaranteed to remain valid after a pre_alloc() operation or pre_reset() followed by pre_init(), but offsets are.
void pre_commit(void);
Write the pool to file. A pre_reset() followed by pre_init() (pehaps with exit() in between) will return the pool to the last committed state.
void pre_reset(void);
Deinitialize the pool, freeing any associated memory and file handles.
--- Makefile | 3 +- vcs-svn/LICENSE | 26 +++++++++++++++++ vcs-svn/obj_pool.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletions(-) create mode 100644 vcs-svn/LICENSE create mode 100644 vcs-svn/obj_pool.h
Makefile +2 -1
@@ -1863,7 +1863,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h -$(VCSSVN_OBJS): +$(VCSSVN_OBJS): \ + vcs-svn/obj_pool.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/LICENSE new file +26 -0
@@ -0,0 +1,26 @@ +Copyright (C) 2010 David Barr <[email protected]>. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice(s), this list of conditions and the following disclaimer + unmodified other than the allowable addition of one or more + copyright notices. +2. Redistributions in binary form must reproduce the above copyright + notice(s), this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vcs-svn/obj_pool.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 3/8] Add memory pool library
Quoted 3 lines · Ramkumar Ramachandra
void
pre_commit(void);Write the pool to file.
Except as a proof of concept, this is the wrong API to have. The problem is that the caller cannot choose the filename, so it ends up being a .bin file in the current directory, wherever that is.
The log message leaves out a subtlety: this also increases the ‘committed’ value, and bookkeeping for that might be useful to some callers.
In other words:
Quoted 4 lines
(quoted diff) +4
-0+static MAYBE_UNUSED void pre##_init(void) \ +{ \ + struct stat st; \ + pre##_pool.file = fopen(#pre ".bin", "a+"); \
Review
Quoted 10 lines
(quoted diff) +10
-0+ rewind(pre##_pool.file); \ + fstat(fileno(pre##_pool.file), &st); \ + pre##_pool.size = st.st_size / sizeof(obj_t); \ + pre##_pool.committed = pre##_pool.size; \ + pre##_pool.capacity = pre##_pool.size * 2; \ + if (pre##_pool.capacity < initial_capacity) \ + pre##_pool.capacity = initial_capacity; \ + pre##_pool.base = malloc(pre##_pool.capacity * sizeof(obj_t)); \ + fread(pre##_pool.base, sizeof(obj_t), pre##_pool.size, pre##_pool.file); \ +} \
If you just want something working, I’d suggest stubbing this out:
static MAYBE_UNUSED void pre##_init(void) \
{ \
} \
It even almost makes sense as API: the _init function does all initialization tasks required, which is to say, none. (The {0, ...} initializer already has taken care of setting all fields to 0).
Review
Quoted 6 lines
(quoted diff) +6
-0+static MAYBE_UNUSED void pre##_commit(void) \ +{ \ + pre##_pool.committed += fwrite(pre##_pool.base + pre##_pool.committed, \ + sizeof(obj_t), pre##_pool.size - pre##_pool.committed, \ + pre##_pool.file); \ +} \
This can be simplified
static MAYBE_UNUSED void pre##_commit(void) \
{ \
pre##_pool.committed = pre##_pool.size; \} \
In other words, maybe something like this on top? This includes the vestigal _init() function which really should not be there (it is confusing that some callers use it and others don’t). I did not spend much time on it because in the end I suspect we might throw obj_pool away anyway.
---
Makefile +1 -0
@@ -409,6 +409,7 @@ TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-match-trees +TEST_PROGRAMS_NEED_X += test-obj-pool TEST_PROGRAMS_NEED_X += test-parse-options TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command
t/t0070-fundamental.sh +6 -0
@@ -12,4 +12,10 @@ test_expect_success 'character classes (isspace, isalpha etc.)' ' test-ctype ' +test_expect_success 'allocator for svn importer' ' + printf "%s\n" 0 0 0 0 0 2 2 2 2 2 -1 >expected && + test-obj-pool >actual && + test_cmp expected actual +' + test_done
test-obj-pool.c new file +55 -0
55 lines not on this page · raw message
vcs-svn/obj_pool.h +3 -19
@@ -16,21 +16,9 @@ static struct { \uint32_t size; \uint32_t capacity; \obj_t *base; \ -FILE *file; \ -} pre##_pool = { 0, 0, 0, NULL, NULL}; \ +} pre##_pool = {0, 0, 0, NULL}; \ static MAYBE_UNUSED void pre##_init(void) \ { \ -struct stat st; \ - pre##_pool.file = fopen(#pre ".bin", "a+"); \ - rewind(pre##_pool.file); \ - fstat(fileno(pre##_pool.file), &st); \ - pre##_pool.size = st.st_size / sizeof(obj_t); \ - pre##_pool.committed = pre##_pool.size; \ - pre##_pool.capacity = pre##_pool.size * 2; \ - if (pre##_pool.capacity < initial_capacity) \ - pre##_pool.capacity = initial_capacity; \ - pre##_pool.base = malloc(pre##_pool.capacity * sizeof(obj_t)); \ - fread(pre##_pool.base, sizeof(obj_t), pre##_pool.size, pre##_pool.file); \ } \ static MAYBE_UNUSED uint32_t pre##_alloc(uint32_t count) \ { \
@@ -62,19 +50,15 @@ static MAYBE_UNUSED obj_t *pre##_pointer(uint32_t offset) \ } \ static MAYBE_UNUSED void pre##_commit(void) \ { \ - pre##_pool.committed += fwrite(pre##_pool.base + pre##_pool.committed, \ - sizeof(obj_t), pre##_pool.size - pre##_pool.committed, \ - pre##_pool.file); \ + pre##_pool.committed = pre##_pool.size; \ } \ static MAYBE_UNUSED void pre##_reset(void) \ { \ free(pre##_pool.base); \ - if (pre##_pool.file) \ - fclose(pre##_pool.file); \ pre##_pool.base = NULL; \ pre##_pool.size = 0; \ pre##_pool.capacity = 0; \ - pre##_pool.file = NULL; \ + pre##_pool.committed = 0; \ }#endif
Re: [PATCH 3/8] Add memory pool library
Hi Jonathan,
Quoted 53 lines · Jonathan Nieder
Quoted 3 lines · Ramkumar Ramachandra
void
pre_commit(void);Write the pool to file.
Except as a proof of concept, this is the wrong API to have. The problem is that the caller cannot choose the filename, so it ends up being a .bin file in the current directory, wherever that is.
The log message leaves out a subtlety: this also increases the ‘committed’ value, and bookkeeping for that might be useful to some callers.
In other words:
Quoted 4 lines
(quoted diff) +4
-0+static MAYBE_UNUSED void pre##_init(void) \ +{ \ + struct stat st; \ + pre##_pool.file = fopen(#pre ".bin", "a+"); \Review
Quoted 10 lines
(quoted diff) +10
-0+ rewind(pre##_pool.file); \ + fstat(fileno(pre##_pool.file), &st); \ + pre##_pool.size = st.st_size / sizeof(obj_t); \ + pre##_pool.committed = pre##_pool.size; \ + pre##_pool.capacity = pre##_pool.size * 2; \ + if (pre##_pool.capacity < initial_capacity) \ + pre##_pool.capacity = initial_capacity; \ + pre##_pool.base = malloc(pre##_pool.capacity * sizeof(obj_t)); \ + fread(pre##_pool.base, sizeof(obj_t), pre##_pool.size, pre##_pool.file); \ +} \If you just want something working, I’d suggest stubbing this out:
static
MAYBE_UNUSEDvoid pre##_init(void) \
{ \
} \It even almost makes sense as API: the
_initfunction does all initialization tasks required, which is to say, none. (The {0, ...} initializer already has taken care of setting all fields to 0).Review
Quoted 6 lines
(quoted diff) +6
-0+static MAYBE_UNUSED void pre##_commit(void) \ +{ \ + pre##_pool.committed += fwrite(pre##_pool.base + pre##_pool.committed, \ + sizeof(obj_t), pre##_pool.size - pre##_pool.committed, \ + pre##_pool.file); \ +} \This can be simplified
static
MAYBE_UNUSEDvoid pre##_commit(void) \{ \ pre##_pool.committed = pre##_pool.size; \
Quoted 7 lines
} \
In other words, maybe something like this on top? This includes the vestigal
_init()function which really should not be there (it is confusing that some callers use it and others don’t). I did not spend much time on it because in the end I suspect we might throwobj_poolaway anyway.
Oh, right. I remember that you asked to turn off persistence for this merge. We can include persistence it in a later series.
Junio: Could you squash this diff into the commit?
vcs-svn/obj_pool.h +1 -14
@@ -20,17 +20,6 @@ static struct { \ } pre##_pool = { 0, 0, 0, NULL, NULL}; \ static MAYBE_UNUSED void pre##_init(void) \ { \ -struct stat st; \ - pre##_pool.file = fopen(#pre ".bin", "a+"); \ - rewind(pre##_pool.file); \ - fstat(fileno(pre##_pool.file), &st); \ - pre##_pool.size = st.st_size / sizeof(obj_t); \ - pre##_pool.committed = pre##_pool.size; \ - pre##_pool.capacity = pre##_pool.size * 2; \ - if (pre##_pool.capacity < initial_capacity) \ - pre##_pool.capacity = initial_capacity; \ - pre##_pool.base = malloc(pre##_pool.capacity * sizeof(obj_t)); \ - fread(pre##_pool.base, sizeof(obj_t), pre##_pool.size, pre##_pool.file); \ } \ static MAYBE_UNUSED uint32_t pre##_alloc(uint32_t count) \ { \
@@ -62,9 +51,7 @@ static MAYBE_UNUSED obj_t *pre##_pointer(uint32_t offset) \ } \ static MAYBE_UNUSED void pre##_commit(void) \ { \ - pre##_pool.committed += fwrite(pre##_pool.base + pre##_pool.committed, \ - sizeof(obj_t), pre##_pool.size - pre##_pool.committed, \ - pre##_pool.file); \ + pre##_pool.committed = pre##_pool.size; \ } \ static MAYBE_UNUSED void pre##_reset(void) \ { \
PATCH 4/8 Add treap implementation
In reply to Ramkumar RamachandraFrom: Jason Evans <[email protected]>
Provide macros to generate a type-specific treap implementation and various functions to operate on it. It uses obj_pool.h to store memory nodes in a treap. Previously committed nodes are never removed from the pool; after any *_commit operation, it is assumed (correctly, in the case of svn-fast-export) that someone else must care about them.
Treaps provide a memory-efficient binary search tree structure. Insertion/deletion/search are about as about as fast in the average case as red-black trees and the chances of worst-case behavior are vanishingly small, thanks to (pseudo-)randomness. The bad worst-case behavior is a small price to pay, given that treaps are much simpler to implement.
From http://www.canonware.com/download/trp/trp_hash/trp.h
[db: Altered to reference nodes by offset from a common base pointer] [db: Bob Jenkins' hashing implementation dropped for Knuth's] [db: Methods unnecessary for search and insert dropped]
--- Makefile | 2 +- vcs-svn/LICENSE | 3 + vcs-svn/trp.h | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 102 +++++++++++++++++++++++++ 4 files changed, 326 insertions(+), 1 deletions(-) create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
Makefile +1 -1
@@ -1864,7 +1864,7 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h + vcs-svn/obj_pool.h vcs-svn/trp.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/LICENSE +3 -0
@@ -1,6 +1,9 @@ Copyright (C) 2010 David Barr <[email protected]>. All rights reserved. +Copyright (C) 2008 Jason Evans <[email protected]>. +All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
vcs-svn/trp.h new file +220 -0
220 lines not on this page · raw message
vcs-svn/trp.txt new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [PATCH 4/8] Add treap implementation
Quoted 6 lines · Ramkumar Ramachandra
Treaps provide a memory-efficient binary search tree structure. Insertion/deletion/search are about as about as fast in the average case as red-black trees and the chances of worst-case behavior are vanishingly small, thanks to (pseudo-)randomness. The bad worst-case behavior is a small price to pay, given that treaps are much simpler to implement.
I still haven’t checked this implementation in detail, but it seemed to work in practice and is about to change anyway.
I like the documentation updates. What else changed from the previous round?
Re: [PATCH 4/8] Add treap implementation
Hi again,
Quoted 2 lines · Jonathan Nieder
I like the documentation updates. What else changed from the previous round?
Nothing else. I should have posted a diff from last time.
-- Ram
PATCH 5/8 Add string-specific memory pool
In reply to Ramkumar RamachandraFrom: David Barr <[email protected]>
Intern strings so they can be compared by address and stored without wasting space.
This library uses the macros in the obj_pool.h and trp.h to create a memory pool for strings and expose an API for handling them.
--- Makefile | 4 +- vcs-svn/string_pool.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/string_pool.h | 15 ++++++ 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/string_pool.c create mode 100644 vcs-svn/string_pool.h
Makefile +2 -2
@@ -1740,7 +1740,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 = +VCSSVN_OBJS = vcs-svn/string_pool.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1864,7 +1864,7 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h vcs-svn/trp.h + vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/string_pool.c new file +114 -0
114 lines not on this page · raw message
vcs-svn/string_pool.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef STRING_POOL_H_ +#define STRING_POOL_H_ + +#include "git-compat-util.h" + +uint32_t pool_intern (char *key); +char *pool_fetch (uint32_t entry); +uint32_t pool_tok_r (char *str,const char *delim,char **saveptr); +void pool_print_seq (uint32_t len,uint32_t *seq,char delim,FILE *stream); +uint32_t pool_tok_seq (uint32_t max,uint32_t *seq,char *delim,char *str); +void pool_init (void ); +void pool_commit (void ); +void pool_reset (void ); + +#endif
Signature · 1 line
1.7.1
PATCH 6/8 Add stream helper library
In reply to Ramkumar RamachandraFrom: David Barr <[email protected]>
This library provides thread-unsafe fgets()- and fread()-like functions where the caller does not have to supply a buffer. It maintains a couple of static buffers and provides an API to use them.
NEEDSWORK: what should buffer_copy_bytes do on error?
--- Makefile | 5 ++- vcs-svn/line_buffer.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/line_buffer.h | 14 +++++++ 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/line_buffer.c create mode 100644 vcs-svn/line_buffer.h
Makefile +3 -2
@@ -1740,7 +1740,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 +VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1864,7 +1864,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h + vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h \ + vcs-svn/line_buffer.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/line_buffer.c new file +93 -0
93 lines not on this page · raw message
vcs-svn/line_buffer.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef LINE_BUFFER_H_ +#define LINE_BUFFER_H_ + +#include "git-compat-util.h" + +int buffer_init (const char *filename); +int buffer_deinit (void ); +char *buffer_read_line (void ); +char *buffer_read_string (uint32_t len); +void buffer_copy_bytes (uint32_t len); +void buffer_skip_bytes (uint32_t len); +void buffer_reset (void ); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 6/8] Add stream helper library
Quoted 8 lines · Ramkumar Ramachandra
From: David Barr <[email protected]>
This library provides thread-unsafe fgets()- and fread()-like functions where the caller does not have to supply a buffer. It maintains a couple of static buffers and provides an API to use them.
NEEDSWORK: what should
buffer_copy_bytesdo on error?
For consistency with the rest of vcs-svn, it should do nothing. :)
I would love to see svn-fe diagnosing and recovering somehow from faulty input. For now it follows the easier route of just ignoring (and skipping) confusing input.
Probably this should be mentioned in the man page somewhere.
[...]
Quoted 2 lines
(quoted diff) +2
-0+void buffer_copy_bytes(uint32_t len) +{
[...]
vcs-svn/line_buffer.c line 75
Quoted 2 lines
vcs-svn/line_buffer.c new file +2
-0+if (ferror (infile) ||ferror (stdout)) +/* NEEDSWORK: handle error. */
The next input/output operation will fail, causing svn-fe to quit early, so it would not be easy for such an error to go unnoticed.
PATCH 7/8 Add infrastructure to write revisions in fast-export format
In reply to Ramkumar RamachandraFrom: David Barr <[email protected]>
repo_tree maintains the exporter's state and provides a facility to to call fast_export, which writes objects to stdout suitable for consumption by fast-import.
The exported functions roughly correspond to Subversion FS operations.
. repo_add, repo_modify, repo_copy, repo_replace, and repo_delete
update the current commit, based roughly on the corresponding Subversion FS operation.
. repo_commit calls out to fast_export to write the current commit to
the fast-import stream in stdout.
. repo_diff is used by the fast_export module to write the changes
for a commit.
. repo_reset erases the exporter's state, so valgrind can be happy.
--- Makefile | 5 +- vcs-svn/fast_export.c | 75 +++++++++++ vcs-svn/fast_export.h | 14 ++ vcs-svn/repo_tree.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/repo_tree.h | 26 ++++ 5 files changed, 453 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/fast_export.c create mode 100644 vcs-svn/fast_export.h create mode 100644 vcs-svn/repo_tree.c create mode 100644 vcs-svn/repo_tree.h
Makefile +3 -2
@@ -1740,7 +1740,8 @@ 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/repo_tree.o vcs-svn/fast_export.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1865,7 +1866,7 @@ 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/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/fast_export.c new file +75 -0
75 lines not on this page · raw message
vcs-svn/fast_export.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef FAST_EXPORT_H_ +#define FAST_EXPORT_H_ + +#include <stdint.h> +#include <time.h> + +void fast_export_delete (uint32_t depth,uint32_t *path); +void fast_export_modify (uint32_t depth,uint32_t *path,uint32_t mode, +uint32_t mark); +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); + +#endif
vcs-svn/repo_tree.c new file +335 -0
335 lines not on this page · raw message
vcs-svn/repo_tree.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef REPO_TREE_H_ +#define REPO_TREE_H_ + +#include "git-compat-util.h" + +#define REPO_MODE_DIR 0040000 +#define REPO_MODE_BLB 0100644 +#define REPO_MODE_EXE 0100755 +#define REPO_MODE_LNK 0120000 + +#define REPO_MAX_PATH_LEN 4096 +#define REPO_MAX_PATH_DEPTH 1000 + +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); +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); +void repo_diff (uint32_t r1,uint32_t r2); +void repo_init (void ); +void repo_reset (void ); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 7/8] Add infrastructure to write revisions in fast-export format
Quoted 6 lines · Ramkumar Ramachandra
vcs-svn/fast_export.c new file +0
-0@@ -0,0 +1,75 @@
[...]
vcs-svn/fast_export.c line 29
Quoted 5 lines
vcs-svn/fast_export.c new file +5
-0+void fast_export_modify (uint32_t depth,uint32_t *path,uint32_t mode, +uint32_t mark) +{ +/* Mode must be 100644, 100755, 120000, or 160000. */ +printf ("M %06o :%d " , mode, mark);
David tweaked the API nicely upstream to enforce this constraint. So nice things will come with the next pull from him.
vcs-svn/fast_export.h line 5
Quoted 11 lines
vcs-svn/fast_export.h new file +5
-0@@ -0,0 +1,14 @@ +#ifndef FAST_EXPORT_H_ +#define FAST_EXPORT_H_ + +#include <stdint.h> +#include <time.h>
The usual convention within git is to rely on .c files to include git-compat-util.h (indirectly through cache.h or directly).
vcs-svn/fast_export.h line 9
Quoted 4 lines
vcs-svn/fast_export.h new file +4
-0+/* Memory pools for commit, dir and dirent */ +obj_pool_gen(commit, struct repo_commit, 4096); +obj_pool_gen(dir, struct repo_dir, 4096); +obj_pool_gen(dirent, struct repo_dirent, 4096);
Are the semicolons necessary? (A nitpick, I know).
That said, this part is looking pretty good.
PATCH 8/8 Add SVN dump parser
In reply to Ramkumar RamachandraFrom: David Barr <[email protected]>
svndump parses data that is in SVN dumpfile format produced by svnadmin dump with the help of line_buffer and uses repo_tree and fast_export to emit a git fast-import stream.
Based roughly on com.hydrografix.svndump 0.92 from the SvnToCCase project at <http://svn2cc.sarovar.org/>, by Stefan Hegny and others.
--- Makefile | 5 +- vcs-svn/LICENSE | 4 + vcs-svn/svndump.c | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.h | 8 ++ 4 files changed, 304 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/svndump.c create mode 100644 vcs-svn/svndump.h
Makefile +3 -2
@@ -1741,7 +1741,7 @@ 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 \ - vcs-svn/repo_tree.o vcs-svn/fast_export.o + vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1866,7 +1866,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/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \ + vcs-svn/svndump.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/LICENSE +4 -0
@@ -4,6 +4,10 @@ All rights reserved. Copyright (C) 2008 Jason Evans <[email protected]>. All rights reserved. +Copyright (C) 2005 Stefan Hegny, hydrografix Consulting GmbH, +Frankfurt/Main, Germany +and others, see http://svn2cc.sarovar.org + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
vcs-svn/svndump.c new file +289 -0
289 lines not on this page · raw message
vcs-svn/svndump.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef SVNDUMP_H_ +#define SVNDUMP_H_ + +void svndump_init (const char *filename); +void svndump_read (char *url); +void svndump_reset (void ); + +#endif
Signature · 1 line
1.7.1
Re: [PATCH 8/8] Add SVN dump parser
Quoted 3 lines · Ramkumar Ramachandra
svndump parses data that is in SVN dumpfile format produced by
svnadmin dumpwith the help ofline_bufferand usesrepo_treeandfast_exportto emit a git fast-import stream.
Probably worth mentioning the this requires a dumpfile v2 (i.e., it does not understand the svndiff0 delta format yet).
vcs-svn/svndump.c line 40
Quoted 11 lines
vcs-svn/svndump.c new file +11
-0+/* Create memory pool for log messages */ +obj_pool_gen (log, char,4096 ); + +static char *log_copy (uint32_t length,char *log) +{ +char *buffer; +log_free (log_pool.size); + buffer =log_pointer (log_alloc (length)); +strncpy (buffer, log, length); +return buffer; +}
A strbuf would do just as well. But using obj_pool looks like a fine way to avoid depending on another piece of git code.
vcs-svn/svndump.c line 62
Quoted 6 lines
vcs-svn/svndump.c new file +6
-0+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; +} keys;
Neat. This is a textbook example of where to use a perfect hash, but comparing interned strings is simpler and fast enough (and the bottlenecks are elsewhere).
Quoted 1 line
+static void
read_props(void)
[...]
Quoted 4 lines
vcs-svn/svndump.c new file +4
-0+if (key == keys.svn_log) { +/* Value length excludes terminating nul. */ + rev_ctx.log =log_copy (len +1 , val); + }else if (key == keys.svn_author) {
vcs-svn/svndump.c line 137
Quoted 10 lines
vcs-svn/svndump.c new file +10
-0+ 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 ; + } + key = ~0 ;
Unknown properties are ignored. Adding stream comments to allow recovering them is left as an exercise for the interested reader.
Review
Quoted 2 lines
(quoted diff) +2
-0+static void handle_node(void) +{
A simple reader does not cope well with this kind of function. It is hard to know if it exhaustively deals with all cases.
But: with real-world repos (e.g. ASF) it works well enough.
vcs-svn/svndump.c line 193
Quoted 2 lines
vcs-svn/svndump.c new file +2
-0+void svndump_read (char *url) +{
Too long. I realize that writing a state machine can be hard in C; maybe it would be easiest to package up the state in a struct and have a separate function for the main loop body.
The patches I didn’t comment on all look good. I don’t think anything I did comment on should prevent this reaching a wider audience.
Thanks for the pleasant read,
Jonathan
Re: [PATCH 8/8] Add SVN dump parser
Quoted 2 lines · Jonathan Nieder
I don’t think anything I did
comment on should prevent this reaching a wider audience.
Except for the obj_pool persistence bit, but you already commented on that.
Happy travels,
Jonathan
Hi,
While Ram travels halfway across the globe, I have rerolled at his request. You can find the result at
git://repo.or.cz/git/jrn.git rr/svn-fe
The main difference from the version sent already is the addition of tests and a small tweak to the treap implementation to make them pass. I will send the two patches with new tests as replies to this message. Thoughts welcome, as always.
David Barr (5):
Add memory pool library
vcs-svn: Add string-specific memory pool
Add stream helper library
Add infrastructure to write revisions in fast-export format Add SVN dump parser
Jason Evans (1):
Add treap implementation
Jonathan Nieder (3):
Export parse_date_basic() to convert a date string to timestamp Introduce vcs-svn lib
Add a sample user for the svndump library
.gitignore | 2 + Makefile | 14 ++- cache.h | 1 + contrib/svn-fe/.gitignore | 4 + contrib/svn-fe/Makefile | 64 +++++++++ contrib/svn-fe/svn-fe.c | 15 ++ contrib/svn-fe/svn-fe.txt | 68 +++++++++ date.c | 14 +- t/t0080-vcs-svn.sh | 101 ++++++++++++++ test-obj-pool.c | 116 ++++++++++++++++ test-treap.c | 65 +++++++++ vcs-svn/LICENSE | 33 +++++ vcs-svn/fast_export.c | 75 ++++++++++ vcs-svn/fast_export.h | 14 ++ vcs-svn/line_buffer.c | 91 +++++++++++++ vcs-svn/line_buffer.h | 12 ++ vcs-svn/obj_pool.h | 61 +++++++++ vcs-svn/repo_tree.c | 331 +++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/repo_tree.h | 26 ++++ vcs-svn/string_pool.c | 101 ++++++++++++++ vcs-svn/string_pool.h | 12 ++ vcs-svn/svndump.c | 289 +++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.h | 8 + vcs-svn/trp.h | 223 ++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 98 +++++++++++++ 25 files changed, 1829 insertions(+), 9 deletions(-) create mode 100644 contrib/svn-fe/.gitignore create mode 100644 contrib/svn-fe/Makefile create mode 100644 contrib/svn-fe/svn-fe.c create mode 100644 contrib/svn-fe/svn-fe.txt create mode 100755 t/t0080-vcs-svn.sh create mode 100644 test-obj-pool.c create mode 100644 test-treap.c create mode 100644 vcs-svn/LICENSE create mode 100644 vcs-svn/fast_export.c create mode 100644 vcs-svn/fast_export.h create mode 100644 vcs-svn/line_buffer.c create mode 100644 vcs-svn/line_buffer.h create mode 100644 vcs-svn/obj_pool.h create mode 100644 vcs-svn/repo_tree.c create mode 100644 vcs-svn/repo_tree.h create mode 100644 vcs-svn/string_pool.c create mode 100644 vcs-svn/string_pool.h create mode 100644 vcs-svn/svndump.c create mode 100644 vcs-svn/svndump.h create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
Signature · 1 line
1.7.2.rc2
PATCH 3/9 Add memory pool library
From: David Barr <[email protected]>
Add a memory pool library implemented using C macros. The obj_pool_gen() macro creates a type-specific memory pool.
The memory pool library is distinguished from the existing specialized allocators in alloc.c by using a contiguous block for all allocations. This means that on one hand, long-lived pointers have to be written as offsets, since the base address changes as the pool grows, but on the other hand, the entire pool can be easily written to the file system. This could allow the memory pool to persist between runs of an application.
For the svn importer, such a facility is useful because each svn revision can copy trees and files from any previous revision. The relevant information for all revisions has to persist somehow to support incremental runs.
---
Stripped out pool_init. And added tests! There is not really much an allocator can do, so it is fun to play around with.
.gitignore | 1 + Makefile | 4 +- t/t0080-vcs-svn.sh | 79 +++++++++++++++++++++++++++++++++++ test-obj-pool.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/obj_pool.h | 61 +++++++++++++++++++++++++++ 5 files changed, 260 insertions(+), 1 deletions(-) create mode 100755 t/t0080-vcs-svn.sh create mode 100644 test-obj-pool.c create mode 100644 vcs-svn/obj_pool.h
.gitignore +1 -0
@@ -167,6 +167,7 @@ /test-genrandom /test-index-version /test-match-trees +/test-obj-pool /test-parse-options /test-path-utils /test-run-command
Makefile +3 -1
@@ -409,6 +409,7 @@ TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-match-trees +TEST_PROGRAMS_NEED_X += test-obj-pool TEST_PROGRAMS_NEED_X += test-parse-options TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command
@@ -1863,7 +1864,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h -$(VCSSVN_OBJS): +$(VCSSVN_OBJS): \ + vcs-svn/obj_pool.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t0080-vcs-svn.sh new file +79 -0
79 lines not on this page · raw message
test-obj-pool.c new file +116 -0
116 lines not on this page · raw message
vcs-svn/obj_pool.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.7.2.rc2
PATCH 4/9 Add treap implementation
In reply to Jonathan NiederFrom: Jason Evans <[email protected]>
Provide macros to generate a type-specific treap implementation and various functions to operate on it. It uses obj_pool.h to store memory nodes in a treap. Previously committed nodes are never removed from the pool; after any *_commit operation, it is assumed (correctly, in the case of svn-fast-export) that someone else must care about them.
Treaps provide a memory-efficient binary search tree structure. Insertion/deletion/search are about as about as fast in the average case as red-black trees and the chances of worst-case behavior are vanishingly small, thanks to (pseudo-)randomness. The bad worst-case behavior is a small price to pay, given that treaps are much simpler to implement.
From http://www.canonware.com/download/trp/trp_hash/trp.h
[db: Altered to reference nodes by offset from a common base pointer] [db: Bob Jenkins' hashing implementation dropped for Knuth's] [db: Methods unnecessary for search and insert dropped]
---
Tweaked treap_search() to always return the node after a missing node, like it is documented to. For vcs-svn this doesn’t matter but the predictable semantics should make debugging easier.
The rest of the patches are almost identical to the versions Ram sent; see the aforementioned git tree if you are interested in trying them out. Testing would be quite welcome.
.gitignore | 1 + Makefile | 3 +- t/t0080-vcs-svn.sh | 22 +++++ test-treap.c | 65 +++++++++++++++ vcs-svn/LICENSE | 3 + vcs-svn/trp.h | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 98 +++++++++++++++++++++++ 7 files changed, 414 insertions(+), 1 deletions(-) create mode 100644 test-treap.c create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
.gitignore +1 -0
@@ -173,6 +173,7 @@ /test-run-command /test-sha1 /test-sigchain +/test-treap /common-cmds.h *.tar.gz *.dsc
Makefile +2 -1
@@ -415,6 +415,7 @@ TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain +TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-version TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
@@ -1865,7 +1866,7 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h + vcs-svn/obj_pool.h vcs-svn/trp.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t0080-vcs-svn.sh +22 -0
@@ -76,4 +76,26 @@ test_expect_success 'obj pool: high-water mark' ' test_cmp expected actual ' +test_expect_success 'treap sort' ' + cat <<-\EOF >unsorted && + 58 + 2 + 3 + 3 + 58 + 3 + 3 + 11 + 0 + 1 + 2 + 3 + 3 + EOF + sort -n unsorted >expected && + + test-treap <unsorted >actual && + test_cmp expected actual +' + test_done
test-treap.c new file +65 -0
65 lines not on this page · raw message
vcs-svn/LICENSE +3 -0
@@ -1,6 +1,9 @@ Copyright (C) 2010 David Barr <[email protected]>. All rights reserved. +Copyright (C) 2008 Jason Evans <[email protected]>. +All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
vcs-svn/trp.h new file +223 -0
223 lines not on this page · raw message
vcs-svn/trp.txt new file +98 -0
98 lines not on this page · raw message
Signature · 1 line
1.7.2.rc2
Re: [PATCH 4/9] Add treap implementation
Quoted 2 lines · Jonathan Nieder
Tweaked
treap_search()to always return the node after a missing node, like it is documented to.
In this case, the documentation was wrong.
Quoted 1 line
For vcs-svn this doesn’t matter
Or rather, it does. Sorry about that.
-- 8< --
Subject: vcs-svn: treap_search should return NULL for missing items
In a misguided attempt to make the code match the documentation, commit 4692f8e7d (Add treap implementation, 2010-07-15) changed the semantics of treap_search to return the /next/ node when a node is missing.
That is great in some circumstances (and the new tests even rely on it), but the rest of vcs-svn relies on treap_search to return NULL in that case instead. The documentation only suggested otherwise because of a typo.
So fix it: now treap_search can do what it was always supposed to (return NULL on failure) and Jason Evans’s treap_nsearch function can be used to keep the test suite working.
--- test-treap.c | 2 +- vcs-svn/trp.h | 13 +++++++++++++ vcs-svn/trp.txt | 9 +++++++-- 3 files changed, 21 insertions(+), 3 deletions(-)
test-treap.c +1 -1
@@ -52,7 +52,7 @@ int main(int argc, char *argv[]) next =node_offset (treap_next (&root,node_pointer (item)));treap_remove (&root,node_pointer (item)); - item =node_offset (treap_search (&root, tmp)); + item =node_offset (treap_nsearch (&root, tmp));if (item != next && (!~item ||node_pointer (item)->n != tmp->n)) die("found %"PRIuMAX" in place of %"PRIuMAX"",
vcs-svn/trp.h +13 -0
@@ -138,6 +138,19 @@ a_attr a_type MAYBE_UNUSED *a_pre##search(struct trp_root *treap, a_type *key) \uint32_t ret = treap->trp_root; \while (~ret && (cmp = (a_cmp)(key,trpn_pointer (a_base,ret)))) { \if (cmp <0 ) { \ + ret =trp_left_get (a_base, a_field, ret); \ + }else { \ + ret =trp_right_get (a_base, a_field, ret); \ + } \ + } \ +return trpn_pointer (a_base, ret); \ +} \ +a_attr a_type MAYBE_UNUSED *a_pre##nsearch(struct trp_root *treap, a_type *key) \ +{ \ + int cmp; \ + uint32_t ret = treap->trp_root; \ + while (~ret && (cmp = (a_cmp)(key, trpn_pointer(a_base,ret)))) { \ + if (cmp < 0) { \ if (!~trp_left_get(a_base, a_field, ret)) \ break; \ ret = trp_left_get(a_base, a_field, ret); \
vcs-svn/trp.txt +7 -2
@@ -86,8 +86,13 @@ void foo_remove(struct trp_root *treap, node_type \*node):: node_type *foo_search(struct trp_root \*treap, node_type \*key):: Search for a node that matches key. If no match is found, - return what would be key's successor, were key in treap - (NULL if no successor). + result is NULL. + +node_type *foo_nsearch(struct trp_root \*treap, node_type \*key):: + + Like `foo_search`, but if if the key is missing return what + would be key's successor, were key in treap (NULL if no + successor). node_type *foo_first(struct trp_root \*treap)::
Signature · 1 line
1.7.2.rc2
cover rr/svn-export reroll
In reply to Jonathan NiederHi!
svn-fe has some serious changes on the horizon. As a preparation, let’s round up what we have now.
The most controversial change is probably the new svn-fe test, which takes about 15 seconds (for the “svnadmin load”, not the svn-fe step :)). It is in the t9* series, so hopefully that will not dissuade people from running the earlier tests.
The main highlight in the changes is a new
Input error
to stderr if a system call failed in reading in the dump file. It still returns status 0 in this and other error situations, though.
Based on maint (for no good reason; that’s just where I tried it). Intended to replace rr/svn-export in pu (only if Ram likes it, of course).
Thoughts welcome.
David Barr (5):
Add memory pool library
Add string-specific memory pool
Add stream helper library
Infrastructure to write revisions in fast-export format SVN dump parser
Jason Evans (1):
Add treap implementation
Jonathan Nieder (4):
Export parse_date_basic() to convert a date string to timestamp Introduce vcs-svn lib
Update svn-fe manual
svn-fe manual: Clarify warning about deltas in dumpfiles
.gitignore | 5 + Makefile | 25 +++- cache.h | 1 + contrib/svn-fe/svn-fe.c | 1 + contrib/svn-fe/svn-fe.txt | 19 ++-- date.c | 14 +- t/t0080-vcs-svn.sh | 171 +++++++++++++++++++++++ t/t9010-svn-fe.sh | 32 +++++ test-line-buffer.c | 46 +++++++ test-obj-pool.c | 116 ++++++++++++++++ test-string-pool.c | 31 +++++ test-svn-fe.c | 18 +++ test-treap.c | 65 +++++++++ vcs-svn/LICENSE | 33 +++++ vcs-svn/fast_export.c | 74 ++++++++++ vcs-svn/fast_export.h | 11 ++ vcs-svn/line_buffer.c | 102 ++++++++++++++ vcs-svn/line_buffer.h | 12 ++ vcs-svn/line_buffer.txt | 62 +++++++++ vcs-svn/obj_pool.h | 61 +++++++++ vcs-svn/repo_tree.c | 328 +++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/repo_tree.h | 26 ++++ vcs-svn/string_pool.c | 102 ++++++++++++++ vcs-svn/string_pool.h | 11 ++ vcs-svn/string_pool.txt | 43 ++++++ vcs-svn/svndump.c | 302 +++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.h | 9 ++ vcs-svn/trp.h | 236 ++++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 103 ++++++++++++++ 29 files changed, 2040 insertions(+), 19 deletions(-) create mode 100755 t/t0080-vcs-svn.sh create mode 100644 t/t9010-svn-fe.sh create mode 100644 test-line-buffer.c create mode 100644 test-obj-pool.c create mode 100644 test-string-pool.c create mode 100644 test-svn-fe.c create mode 100644 test-treap.c create mode 100644 vcs-svn/LICENSE create mode 100644 vcs-svn/fast_export.c create mode 100644 vcs-svn/fast_export.h create mode 100644 vcs-svn/line_buffer.c create mode 100644 vcs-svn/line_buffer.h create mode 100644 vcs-svn/line_buffer.txt create mode 100644 vcs-svn/obj_pool.h create mode 100644 vcs-svn/repo_tree.c create mode 100644 vcs-svn/repo_tree.h create mode 100644 vcs-svn/string_pool.c create mode 100644 vcs-svn/string_pool.h create mode 100644 vcs-svn/string_pool.txt create mode 100644 vcs-svn/svndump.c create mode 100644 vcs-svn/svndump.h create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
PATCH 1/10 Export parse_date_basic() to convert a date string to timestamp
approxidate() is not appropriate for reading machine-written dates because it guesses instead of erroring out on malformed dates. parse_date() is less convenient since it returns its output as a string. So export the underlying function that writes a timestamp.
While at it, change the return value to match the usual convention:
return 0 for success and -1 for failure.
---
As before, I think this improves code clarity, independently of its use for svn-fe. So I would not be unhappy if it is applied as a separate topic.
No change from last round.
cache.h | 1 + date.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-)
cache.h +1 -0
@@ -811,6 +811,7 @@ const char *show_date_relative(unsigned long time, int tz,char *timebuf, size_t timebuf_size);int parse_date (const char *date,char *buf,int bufsize); +int parse_date_basic (const char *date,unsigned long *timestamp,int *offset);void datestamp (char *buf,int bufsize);#define approxidate (s) approxidate_careful((s), NULL)unsigned long approxidate_careful (const char *,int *);
date.c +6 -8
@@ -586,7 +586,7 @@ static int date_string(unsigned long date, int offset, char *buf, int len)/* Gr. strptime is crap for this; it doesn't have a way to require RFC2822 (i.e. English) day/month names, and it doesn't work correctly with %z. */ -int parse_date_toffset (const char *date,unsigned long *timestamp,int *offset) +int parse_date_basic (const char *date,unsigned long *timestamp,int *offset) {struct tm tm;int tm_gmt;
@@ -642,17 +642,16 @@ int parse_date_toffset(const char *date, unsigned long *timestamp, int *offset)if (!tm_gmt) *timestamp -= *offset *60 ; -return 1 ;/* success */ +return 0 ;/* success */ }int parse_date (const char *date,char *result,int maxlen) {unsigned long timestamp;int offset; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) -return date_string (timestamp, offset, result, maxlen); -else +if (parse_date_basic (date, ×tamp, &offset))return -1 ; +return date_string (timestamp, offset, result, maxlen); }enum date_mode parse_date_format (const char *format)
@@ -1004,9 +1003,8 @@ unsigned long approxidate_relative(const char *date, const struct timeval *tv)int offset;int errors =0 ; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) +if (!parse_date_basic (date, ×tamp, &offset))return timestamp; -return approxidate_str (date, tv, &errors); }
@@ -1019,7 +1017,7 @@ unsigned long approxidate_careful(const char *date, int *error_ret)if (!error_ret) error_ret = &dummy; -if (parse_date_toffset (date, ×tamp, &offset) >0 ) { +if (!parse_date_basic (date, ×tamp, &offset)) { *error_ret =0 ;return timestamp; }
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 2/10 Introduce vcs-svn lib
In reply to Jonathan NiederTeach the build system to build a separate library for the upcoming subversion interop support.
The resulting vcs-svn/lib.a does not contain any code, nor is it built during a normal build. This is just scaffolding for later changes.
---
This is just for reference; no change from last round.
Makefile | 8 +++++++- vcs-svn/LICENSE | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletions(-) create mode 100644 vcs-svn/LICENSE
Makefile +7 -1
@@ -468,6 +468,7 @@ export PYTHON_PATH LIB_FILE=libgit.a XDIFF_LIB=xdiff/lib.a +VCSSVN_LIB=vcs-svn/lib.a LIB_H += advice.h LIB_H += archive.h
@@ -1739,7 +1740,8 @@ ifndef NO_CURL endif XDIFF_OBJS = xdiff/xdiffi.o xdiff/xprepare.o xdiff/xutils.o xdiff/xemit.o \ xdiff/xmerge.o xdiff/xpatience.o -OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) +VCSSVN_OBJS = +OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d) dep_dirs := $(addsuffix .depend,$(sort $(dir $(OBJECTS))))
@@ -1860,6 +1862,8 @@ http.o http-walker.o http-push.o remote-curl.o: http.h xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h + +$(VCSSVN_OBJS): endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@ -1908,6 +1912,8 @@ $(LIB_FILE): $(LIB_OBJS) $(XDIFF_LIB): $(XDIFF_OBJS) $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(XDIFF_OBJS) +$(VCSSVN_LIB): $(VCSSVN_OBJS) + $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(VCSSVN_OBJS) doc: $(MAKE) -C Documentation all
vcs-svn/LICENSE new file +26 -0
@@ -0,0 +1,26 @@ +Copyright (C) 2010 David Barr <[email protected]>. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice(s), this list of conditions and the following disclaimer + unmodified other than the allowable addition of one or more + copyright notices. +2. Redistributions in binary form must reproduce the above copyright + notice(s), this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 3/10 Add memory pool library
In reply to Jonathan NiederFrom: David Barr <[email protected]>
Add a memory pool library implemented using C macros. The obj_pool_gen() macro creates a type-specific memory pool.
The memory pool library is distinguished from the existing specialized allocators in alloc.c by using a contiguous block for all allocations. This means that on one hand, long-lived pointers have to be written as offsets, since the base address changes as the pool grows, but on the other hand, the entire pool can be easily written to the file system. This could allow the memory pool to persist between runs of an application.
For the svn importer, such a facility is useful because each svn revision can copy trees and files from any previous revision. The relevant information for all revisions has to persist somehow to support incremental runs.
[rr: minor cleanups]
[jn: added tests; removed file system backing for now]
---
The only change from last round is the notes at the end of the commit message. Hopefully David is less likely to be blamed for bugs I introduced this way. :)
.gitignore | 1 + Makefile | 4 +- t/t0080-vcs-svn.sh | 79 +++++++++++++++++++++++++++++++++++ test-obj-pool.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/obj_pool.h | 61 +++++++++++++++++++++++++++ 5 files changed, 260 insertions(+), 1 deletions(-) create mode 100755 t/t0080-vcs-svn.sh create mode 100644 test-obj-pool.c create mode 100644 vcs-svn/obj_pool.h
.gitignore +1 -0
@@ -167,6 +167,7 @@ /test-genrandom /test-index-version /test-match-trees +/test-obj-pool /test-parse-options /test-path-utils /test-run-command
Makefile +3 -1
@@ -409,6 +409,7 @@ TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-match-trees +TEST_PROGRAMS_NEED_X += test-obj-pool TEST_PROGRAMS_NEED_X += test-parse-options TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command
@@ -1863,7 +1864,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xinclude.h xdiff/xmacros.h xdiff/xdiff.h xdiff/xtypes.h \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h -$(VCSSVN_OBJS): +$(VCSSVN_OBJS): \ + vcs-svn/obj_pool.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t0080-vcs-svn.sh new file +79 -0
79 lines not on this page · raw message
test-obj-pool.c new file +116 -0
116 lines not on this page · raw message
vcs-svn/obj_pool.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 4/10 Add treap implementation
In reply to Jonathan NiederFrom: Jason Evans <[email protected]>
Provide macros to generate a type-specific treap implementation and various functions to operate on it. It uses obj_pool.h to store memory nodes in a treap. Previously committed nodes are never removed from the pool; after any *_commit operation, it is assumed (correctly, in the case of svn-fast-export) that someone else must care about them.
Treaps provide a memory-efficient binary search tree structure. Insertion/deletion/search are about as about as fast in the average case as red-black trees and the chances of worst-case behavior are vanishingly small, thanks to (pseudo-)randomness. The bad worst-case behavior is a small price to pay, given that treaps are much simpler to implement.
From http://www.canonware.com/download/trp/trp_hash/trp.h
[db: Altered to reference nodes by offset from a common base pointer] [db: Bob Jenkins' hashing implementation dropped for Knuth's] [db: Methods unnecessary for search and insert dropped] [rr: Squelched compiler warnings]
[db: Added support for immutable treap nodes]
[jn: Reintroduced treap_nsearch(); with tests]
---
With the treap_nsearch() fixup from last time squashed in and some more history in the log message.
.gitignore | 1 + Makefile | 3 +- t/t0080-vcs-svn.sh | 22 +++++ test-treap.c | 65 ++++++++++++++ vcs-svn/LICENSE | 3 + vcs-svn/trp.h | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/trp.txt | 103 +++++++++++++++++++++++ 7 files changed, 432 insertions(+), 1 deletions(-) create mode 100644 test-treap.c create mode 100644 vcs-svn/trp.h create mode 100644 vcs-svn/trp.txt
.gitignore +1 -0
@@ -173,6 +173,7 @@ /test-run-command /test-sha1 /test-sigchain +/test-treap /common-cmds.h *.tar.gz *.dsc
Makefile +2 -1
@@ -415,6 +415,7 @@ TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain +TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-version TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
@@ -1865,7 +1866,7 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h + vcs-svn/obj_pool.h vcs-svn/trp.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t0080-vcs-svn.sh +22 -0
@@ -76,4 +76,26 @@ test_expect_success 'obj pool: high-water mark' ' test_cmp expected actual ' +test_expect_success 'treap sort' ' + cat <<-\EOF >unsorted && + 68 + 12 + 13 + 13 + 68 + 13 + 13 + 21 + 10 + 11 + 12 + 13 + 13 + EOF + sort unsorted >expected && + + test-treap <unsorted >actual && + test_cmp expected actual +' + test_done
test-treap.c new file +65 -0
65 lines not on this page · raw message
vcs-svn/LICENSE +3 -0
@@ -1,6 +1,9 @@ Copyright (C) 2010 David Barr <[email protected]>. All rights reserved. +Copyright (C) 2008 Jason Evans <[email protected]>. +All rights reserved. + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
vcs-svn/trp.h new file +236 -0
236 lines not on this page · raw message
vcs-svn/trp.txt new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 04/10] Add treap implementation
vcs-svn/trp.h line 49
Quoted 8 lines · Jonathan Nieder
vcs-svn/trp.h new file +8
-0+/* Left accessors. */ +#define trp_left_get (a_base, a_field, a_node) \ + (trpn_pointer(a_base, a_node)->a_field.trpn_left) +#define trp_left_set (a_base, a_field, a_node, a_left) \ + do { \ + trpn_modify(a_base, a_node); \ + trp_left_get(a_base, a_field, a_node) = (a_left); \ + } while(0)
Need SP after "while" (there are other occurrences).
vcs-svn/trp.h line 139
Quoted 5 lines
vcs-svn/trp.h new file +5
-0+a_attr a_type MAYBE_UNUSED *a_pre##search(struct trp_root *treap, a_type *key) \ +{ \ + int cmp; \ + uint32_t ret = treap->trp_root; \ + while (~ret && (cmp = (a_cmp)(key, trpn_pointer(a_base,ret)))) { \
SP after "," (same for nsearch)
Re: [PATCH 04/10] Add treap implementation
Quoted 1 line · Junio C Hamano
Need SP after "while" (there are other occurrences).
Good catch. checkpatch also notices some long lines, but I think that’s worth ignoring.
-- 8< --
Subject: treap: style fix
Missing spaces in while (0) and trpn_pointer(a, b).
Remove parentheses around return value.
--- vcs-svn/trp.h | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-)
vcs-svn/trp.h +15 -15
@@ -37,7 +37,7 @@ struct trp_root { *trpn_pointer (a_base, a_offset) = \ *trpn_pointer (a_base, old_offset); \ } \ - }while (0 ); + }while (0 )/* Left accessors. */ #define trp_left_get(a_base, a_field, a_node) \
@@ -46,7 +46,7 @@ struct trp_root {do { \trpn_modify (a_base, a_node); \trp_left_get (a_base, a_field, a_node) = (a_left); \ - }while (0 ) + }while (0 ) /* Right accessors. */#define trp_right_get (a_base, a_field, a_node) \
@@ -55,7 +55,7 @@ struct trp_root {do { \trpn_modify (a_base, a_node); \trp_right_get (a_base, a_field, a_node) = (a_right); \ - }while (0 ) + }while (0 )/* * Fibonacci hash function.
@@ -72,7 +72,7 @@ struct trp_root {do { \trp_left_set (a_base, a_field, (a_node), ~0 ); \trp_right_set (a_base, a_field, (a_node), ~0 ); \ - }while (0 ) + }while (0 ) /* Internal utility macros. */#define trpn_first (a_base, a_field, a_root, r_node) \
@@ -90,7 +90,7 @@ struct trp_root {trp_right_set (a_base, a_field, (a_node), \trp_left_get (a_base, a_field, (r_node))); \trp_left_set (a_base, a_field, (r_node), (a_node)); \ - } while(0) + } while (0)#define trpn_rotate_right (a_base, a_field, a_node, r_node) \ do { \
@@ -98,7 +98,7 @@ struct trp_root {trp_left_set (a_base, a_field, (a_node), \trp_right_get (a_base, a_field, (r_node))); \trp_right_set (a_base, a_field, (r_node), (a_node)); \ - } while(0) + } while (0)#define trp_gen (a_attr, a_pre, a_type, a_field, a_base, a_cmp) \ a_attr a_type MAYBE_UNUSED *a_pre##first(struct trp_root *treap) \
@@ -136,7 +136,7 @@ a_attr a_type MAYBE_UNUSED *a_pre##search(struct trp_root *treap, a_type *key) \ { \int cmp; \uint32_t ret = treap->trp_root; \ -while (~ret && (cmp = (a_cmp)(key,trpn_pointer (a_base,ret)))) { \ +while (~ret && (cmp = (a_cmp)(key,trpn_pointer (a_base, ret)))) { \if (cmp <0 ) { \ ret =trp_left_get (a_base, a_field, ret); \ }else { \
@@ -149,7 +149,7 @@ a_attr a_type MAYBE_UNUSED *a_pre##nsearch(struct trp_root *treap, a_type *key) { \int cmp; \uint32_t ret = treap->trp_root; \ -while (~ret && (cmp = (a_cmp)(key,trpn_pointer (a_base,ret)))) { \ +while (~ret && (cmp = (a_cmp)(key,trpn_pointer (a_base, ret)))) { \if (cmp <0 ) { \if (!~trp_left_get (a_base, a_field, ret)) \break ; \
@@ -163,7 +163,7 @@ a_attr a_type MAYBE_UNUSED *a_pre##nsearch(struct trp_root *treap, a_type *key) a_attr uint32_t MAYBE_UNUSED a_pre##insert_recurse(uint32_t cur_node, uint32_t ins_node) \ { \ if (cur_node == ~0) { \ - return (ins_node); \ + return ins_node; \ } else { \ uint32_t ret; \ int cmp = (a_cmp)(trpn_pointer(a_base, ins_node), \
@@ -185,7 +185,7 @@ a_attr uint32_t MAYBE_UNUSED a_pre##insert_recurse(uint32_t cur_node, uint32_t ielse \ ret = cur_node; \ } \ -return (ret); \ +return ret; \ } \ } \ a_attr void MAYBE_UNUSED a_pre##insert(struct trp_root *treap, a_type *node) \
@@ -204,27 +204,27 @@ a_attr uint32_t MAYBE_UNUSED a_pre##remove_recurse(uint32_t cur_node, uint32_t ruint32_t right =trp_right_get (a_base, a_field, cur_node); \if (left == ~0 ) { \if (right == ~0 ) \ -return (~0 ); \ +return ~0 ; \ }else if (right == ~0 ||trp_prio_get (left) <trp_prio_get (right)) { \trpn_rotate_right (a_base, a_field, cur_node, ret); \ right = a_pre##remove_recurse(cur_node, rem_node); \ trp_right_set(a_base, a_field, ret, right); \ - return (ret); \ + return ret; \ } \ trpn_rotate_left(a_base, a_field, cur_node, ret); \ left = a_pre##remove_recurse(cur_node, rem_node); \ trp_left_set(a_base, a_field, ret, left); \ - return (ret); \ + return ret; \ } else if (cmp < 0) { \ uint32_t left = a_pre##remove_recurse( \ trp_left_get(a_base, a_field, cur_node), rem_node); \ trp_left_set(a_base, a_field, cur_node, left); \ - return (cur_node); \ + return cur_node; \ } else { \ uint32_t right = a_pre##remove_recurse( \ trp_right_get(a_base, a_field, cur_node), rem_node); \ trp_right_set(a_base, a_field, cur_node, right); \ - return (cur_node); \ + return cur_node; \ } \ } \ a_attr void MAYBE_UNUSED a_pre##remove(struct trp_root *treap, a_type *node) \
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 04/10] Add treap implementation
In reply to Junio C HamanoQuoted 9 lines · Junio C Hamano
Review
Quoted 5 lines · Jonathan Nieder
(quoted diff) +5
-0+#define trp_left_set(a_base, a_field, a_node, a_left) \ + do { \ + trpn_modify(a_base, a_node); \ + trp_left_get(a_base, a_field, a_node) = (a_left); \ + } while(0)Need SP after "while" (there are other occurrences).
Here are a few more (but feel free to ignore them).
-- 8< --
Subject: Standardize do { ... } while (0) style
--- base85.c | 6 +++--- cache.h | 2 +- diffcore.h | 8 ++++---- http.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-)
base85.c +3 -3
@@ -7,9 +7,9 @@#define say1 (a,b) fprintf(stderr, a, b)#define say2 (a,b,c) fprintf(stderr, a, b, c)#else -#define say (a) do {} while(0) -#define say1 (a,b) do {} while(0) -#define say2 (a,b,c) do {} while(0) +#define say(a) do { /* nothing */ } while (0) +#define say1(a,b) do { /* nothing */ } while (0) +#define say2(a,b,c) do { /* nothing */ } while (0)#endif static const char en85[] = {
cache.h +1 -1
@@ -449,7 +449,7 @@ extern int init_db(const char *template_dir, unsigned int flags); alloc =alloc_nr (alloc); \ x =xrealloc ((x), alloc *sizeof (*(x))); \ } \ - }while (0 ) + }while (0 )/* Initialize and use the cache information */ extern int read_index(struct index_state *);
diffcore.h +4 -4
@@ -98,7 +98,7 @@ struct diff_queue_struct { (q)->queue =NULL ; \ (q)->nr = (q)->alloc =0 ; \ (q)->run =0 ; \ - }while (0 ); + }while (0 ) extern struct diff_queue_struct diff_queued_diff; extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
@@ -118,9 +118,9 @@ void diff_debug_filespec(struct diff_filespec *, int, const char *);void diff_debug_filepair (const struct diff_filepair *,int );void diff_debug_queue (const char *,struct diff_queue_struct *);#else -#define diff_debug_filespec (a,b,c) do {} while(0) -#define diff_debug_filepair (a,b) do {} while(0) -#define diff_debug_queue (a,b) do {} while(0) +#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0) +#define diff_debug_filepair(a,b) do { /* nothing */ } while (0) +#define diff_debug_queue(a,b) do { /* nothing */ } while (0)#endif extern int diffcore_count_changes(struct diff_filespec *src,
http.h +2 -2
@@ -23,10 +23,10 @@#endif #if LIBCURL_VERSION_NUM <0x070704 -#define curl_global_cleanup() do { /* nothing */ } while(0) +#define curl_global_cleanup() do { /* nothing */ } while (0)#endif #if LIBCURL_VERSION_NUM <0x070800 -#define curl_global_init(a) do { /* nothing */ } while(0) +#define curl_global_init(a) do { /* nothing */ } while (0)#endif #if (LIBCURL_VERSION_NUM <0x070c04 ) || (LIBCURL_VERSION_NUM ==0x071000 )
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 04/10] Add treap implementation
diffcore.h struct diff_queue_struct { · line 101
Quoted 10 lines · Jonathan Nieder
diffcore.h +1
-1@@ -98,7 +98,7 @@ struct diff_queue_struct { (q)->queue =NULL ; \ (q)->nr = (q)->alloc =0 ; \ (q)->run =0 ; \ - }while (0 ); + }while (0 )
This is a _bad_ one. Thanks.
PATCH 5/10 Add string-specific memory pool
In reply to Jonathan NiederFrom: David Barr <[email protected]>
Intern strings so they can be compared by address and stored without wasting space.
This library uses the macros in the obj_pool.h and trp.h to create a memory pool for strings and expose an API for handling them.
[rr: added API docs]
[jn: with some API simplifications, new documentation and tests]
---
New test. The return value from pool_tok_seq is not checked by the vcs-svn lib but trying to use it in tests revealed it was not so intuitive. pool_tok_seq() was behaving strangely when passed an array of size 0; I think there is nothing sane to do in that case --- maybe it should abort(). The API was passing around char * that cannot be modified; changed to const char *.
Another set of eyes on this would be welcome.
.gitignore | 1 + Makefile | 9 +++- t/t0080-vcs-svn.sh | 16 +++++++ test-string-pool.c | 31 ++++++++++++++ vcs-svn/string_pool.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/string_pool.h | 11 +++++ vcs-svn/string_pool.txt | 43 ++++++++++++++++++++ 7 files changed, 210 insertions(+), 3 deletions(-) create mode 100644 test-string-pool.c create mode 100644 vcs-svn/string_pool.c create mode 100644 vcs-svn/string_pool.h create mode 100644 vcs-svn/string_pool.txt
.gitignore +1 -0
@@ -173,6 +173,7 @@ /test-run-command /test-sha1 /test-sigchain +/test-string-pool /test-treap /common-cmds.h *.tar.gz
Makefile +6 -3
@@ -415,6 +415,7 @@ TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain +TEST_PROGRAMS_NEED_X += test-string-pool TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-version
@@ -1742,7 +1743,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 = +VCSSVN_OBJS = vcs-svn/string_pool.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1866,7 +1867,7 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h vcs-svn/trp.h + vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@ -2017,10 +2018,12 @@ test-delta$X: diff-delta.o patch-delta.o test-parse-options$X: parse-options.o +test-string-pool$X: vcs-svn/lib.a + .PRECIOUS: $(TEST_OBJS) test-%$X: test-%.o $(GITLIBS) - $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) + $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(filter %.a,$^) $(LIBS) check-sha1:: test-sha1$X ./test-sha1.sh
t/t0080-vcs-svn.sh +16 -0
@@ -76,6 +76,22 @@ test_expect_success 'obj pool: high-water mark' ' test_cmp expected actual ' +test_expect_success 'string pool' ' + echo a does not equal b >expected.differ && + echo a equals a >expected.match && + echo equals equals equals >expected.matchmore && + + test-string-pool "a,--b" >actual.differ && + test-string-pool "a,a" >actual.match && + test-string-pool "equals-equals" >actual.matchmore && + test_must_fail test-string-pool a,a,a && + test_must_fail test-string-pool a && + + test_cmp expected.differ actual.differ && + test_cmp expected.match actual.match && + test_cmp expected.matchmore actual.matchmore +' + test_expect_success 'treap sort' ' cat <<-\EOF >unsorted && 68
test-string-pool.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* test-string-pool.c: code to exercise the svn importer's string pool +*/ + +#include "git-compat-util.h" +#include "vcs-svn/string_pool.h" + +int main (int argc,char *argv[]) +{ +const uint32_t unequal =pool_intern ("does not equal" ); +const uint32_t equal =pool_intern ("equals" ); +uint32_t buf[3 ]; +uint32_t n; + +if (argc !=2 ) +usage ("test-string-pool <string>,<string>" ); + + n =pool_tok_seq (3 , buf,",-" , argv[1 ]); +if (n >=3 ) +die ("too many strings" ); +if (n <=1 ) +die ("too few strings" ); + + buf[2 ] = buf[1 ]; + buf[1 ] = (buf[0 ] == buf[2 ]) ? equal : unequal; +pool_print_seq (3 , buf,' ' , stdout); +fputc ('\n' , stdout); + +pool_reset (); +return 0 ; +}
vcs-svn/string_pool.c new file +102 -0
102 lines not on this page · raw message
vcs-svn/string_pool.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef STRING_POOL_H_ +#define STRING_POOL_H_ + +uint32_t pool_intern (const char *key); +const char *pool_fetch (uint32_t entry); +uint32_t pool_tok_r (char *str,const char *delim,char **saveptr); +void pool_print_seq (uint32_t len,uint32_t *seq,char delim,FILE *stream); +uint32_t pool_tok_seq (uint32_t sz,uint32_t *seq,const char *delim,char *str); +void pool_reset (void ); + +#endif
vcs-svn/string_pool.txt new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 05/10] Add string-specific memory pool
Makefile TEST_PROGRAMS_NEED_X += test-path-utils · line 420
Quoted 11 lines · Jonathan Nieder
Makefile +1
-0@@ -415,6 +415,7 @@ TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain +TEST_PROGRAMS_NEED_X += test-string-pool TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-version
Does your Makefile do the right thing to vcs-svn/*.[oa] upon "make clean"?
Quoted 6 lines
vcs-svn/string_pool.c new file +0
-0
vcs-svn/string_pool.c line 48
Quoted 10 lines
vcs-svn/string_pool.c new file +9
-0@@ -0,0 +1,102 @@ +uint32_t pool_intern (const char *key) +{ +/* Canonicalize key */ +struct node *match =NULL ; +uint32_t key_len; +if (key ==NULL ) +return ~0 ; + key_len =strlen (key) +1 ; +struct node *node =node_pointer (node_alloc (1 ));
Please fix decl-after-stmt here.
Re: [PATCH 05/10] Add string-specific memory pool
Quoted 15 lines · Junio C Hamano
Makefile TEST_PROGRAMS_NEED_X += test-path-utils · line 420
Quoted 11 lines · Jonathan Nieder
Makefile +1
-0@@ -415,6 +415,7 @@ TEST_PROGRAMS_NEED_X += test-path-utils TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain +TEST_PROGRAMS_NEED_X += test-string-pool TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-versionDoes your
Makefiledo the right thing to vcs-svn/*.[oa] upon "make clean"?
Good catch. Here’s a fixup for patch 2 (“Introduce vcs-svn lib”).
-- 8< --
Subject: vcs-svn: remove build artifacts on “make clean”
---
Makefile +2 -2
@@ -2184,8 +2184,8 @@ distclean: clean $(RM) configure clean: - $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \ - builtin/*.o $(LIB_FILE) $(XDIFF_LIB) + $(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \ + builtin/*.o $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB) $(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X $(RM) $(TEST_PROGRAMS) $(RM) -r bin-wrappers
PATCH 6/10 Add stream helper library
In reply to Jonathan NiederFrom: David Barr <[email protected]>
This library provides thread-unsafe fgets()- and fread()-like functions where the caller does not have to supply a buffer. It maintains a couple of static buffers and provides an API to use them.
[rr: allow input from files other than stdin]
[jn: with tests, documentation, and error handling improvements]
---
New tests and API docs. The return value from buffer_deinit can be used to check for errors now (I found this useful when writing tests).
.gitignore | 1 + Makefile | 8 +++- t/t0080-vcs-svn.sh | 54 ++++++++++++++++++++++++++ test-line-buffer.c | 46 ++++++++++++++++++++++ vcs-svn/line_buffer.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/line_buffer.h | 12 ++++++ vcs-svn/line_buffer.txt | 58 ++++++++++++++++++++++++++++ 7 files changed, 274 insertions(+), 2 deletions(-) create mode 100644 test-line-buffer.c create mode 100644 vcs-svn/line_buffer.c create mode 100644 vcs-svn/line_buffer.h create mode 100644 vcs-svn/line_buffer.txt
.gitignore +1 -0
@@ -166,6 +166,7 @@ /test-dump-cache-tree /test-genrandom /test-index-version +/test-line-buffer /test-match-trees /test-obj-pool /test-parse-options
Makefile +6 -2
@@ -408,6 +408,7 @@ TEST_PROGRAMS_NEED_X += test-date TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-genrandom +TEST_PROGRAMS_NEED_X += test-line-buffer TEST_PROGRAMS_NEED_X += test-match-trees TEST_PROGRAMS_NEED_X += test-obj-pool TEST_PROGRAMS_NEED_X += test-parse-options
@@ -1743,7 +1744,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 +VCSSVN_OBJS = vcs-svn/string_pool.o vcs-svn/line_buffer.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1867,7 +1868,8 @@ xdiff-interface.o $(XDIFF_OBJS): \ xdiff/xutils.h xdiff/xprepare.h xdiff/xdiffi.h xdiff/xemit.h $(VCSSVN_OBJS): \ - vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h + vcs-svn/obj_pool.h vcs-svn/trp.h vcs-svn/string_pool.h \ + vcs-svn/line_buffer.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@ -2016,6 +2018,8 @@ test-date$X: date.o ctype.o test-delta$X: diff-delta.o patch-delta.o +test-line-buffer$X: vcs-svn/lib.a + test-parse-options$X: parse-options.o test-string-pool$X: vcs-svn/lib.a
t/t0080-vcs-svn.sh +54 -0
60 lines not on this page · raw message
test-line-buffer.c new file +46 -0
46 lines not on this page · raw message
vcs-svn/line_buffer.c new file +97 -0
97 lines not on this page · raw message
vcs-svn/line_buffer.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef LINE_BUFFER_H_ +#define LINE_BUFFER_H_ + +int buffer_init (const char *filename); +int buffer_deinit (void ); +char *buffer_read_line (void ); +char *buffer_read_string (uint32_t len); +void buffer_copy_bytes (uint32_t len); +void buffer_skip_bytes (uint32_t len); +void buffer_reset (void ); + +#endif
vcs-svn/line_buffer.txt new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 7/10 Infrastructure to write revisions in fast-export format
In reply to Jonathan NiederFrom: David Barr <[email protected]>
repo_tree maintains the exporter's state and provides a facility to to call fast_export, which writes objects to stdout suitable for consumption by fast-import.
The exported functions roughly correspond to Subversion FS operations.
. repo_add, repo_modify, repo_copy, repo_replace, and repo_delete
update the current commit, based roughly on the corresponding Subversion FS operation.
. repo_commit calls out to fast_export to write the current commit to
the fast-import stream in stdout.
. repo_diff is used by the fast_export module to write the changes
for a commit.
. repo_reset erases the exporter's state, so valgrind can be happy.
[rr: squelched compiler warnings]
[jn: removed support for maintaining state on-disk, though we may want to add it back later]
---
No tests for this one, since the next few patches exercise it and this is not a general-purpose API. Relative to last round, the pool_commit and commit_commit calls have been eliminated; unlike the dir_commit et al calls, those were only meant for committing state to disk, and the changing high-water mark was not being used.
Makefile | 5 +- vcs-svn/fast_export.c | 74 +++++++++++ vcs-svn/fast_export.h | 11 ++ vcs-svn/repo_tree.c | 328 +++++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/repo_tree.h | 26 ++++ 5 files changed, 442 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/fast_export.c create mode 100644 vcs-svn/fast_export.h create mode 100644 vcs-svn/repo_tree.c create mode 100644 vcs-svn/repo_tree.h
Makefile +3 -2
@@ -1744,7 +1744,8 @@ 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/repo_tree.o vcs-svn/fast_export.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1869,7 +1870,7 @@ 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/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/fast_export.c new file +74 -0
74 lines not on this page · raw message
vcs-svn/fast_export.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef FAST_EXPORT_H_ +#define FAST_EXPORT_H_ + +void fast_export_delete (uint32_t depth,uint32_t *path); +void fast_export_modify (uint32_t depth,uint32_t *path,uint32_t mode, +uint32_t mark); +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); + +#endif
vcs-svn/repo_tree.c new file +328 -0
328 lines not on this page · raw message
vcs-svn/repo_tree.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef REPO_TREE_H_ +#define REPO_TREE_H_ + +#include "git-compat-util.h" + +#define REPO_MODE_DIR 0040000 +#define REPO_MODE_BLB 0100644 +#define REPO_MODE_EXE 0100755 +#define REPO_MODE_LNK 0120000 + +#define REPO_MAX_PATH_LEN 4096 +#define REPO_MAX_PATH_DEPTH 1000 + +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); +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); +void repo_diff (uint32_t r1,uint32_t r2); +void repo_init (void ); +void repo_reset (void ); + +#endif
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 8/10 SVN dump parser
In reply to Jonathan NiederFrom: David Barr <[email protected]>
svndump parses data that is in SVN dumpfile format produced by svnadmin dump with the help of line_buffer and uses repo_tree and fast_export to emit a git fast-import stream.
Based roughly on com.hydrografix.svndump 0.92 from the SvnToCCase project at <http://svn2cc.sarovar.org/>, by Stefan Hegny and others.
[rr: allow input from files other than stdin]
[jn: with test, more error reporting]
---
New test. It is slow; work by svn gurus to speed this up would be nice. The test program is very similar to svn-fe from contrib, except it exercises Ram’s change to read from a file other than stdin.
.gitignore | 1 + Makefile | 8 +- contrib/svn-fe/svn-fe.c | 1 + t/t9010-svn-fe.sh | 32 +++++ test-svn-fe.c | 18 +++ vcs-svn/LICENSE | 4 + vcs-svn/svndump.c | 302 +++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndump.h | 9 ++ 8 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 t/t9010-svn-fe.sh create mode 100644 test-svn-fe.c create mode 100644 vcs-svn/svndump.c create mode 100644 vcs-svn/svndump.h
.gitignore +1 -0
@@ -175,6 +175,7 @@ /test-sha1 /test-sigchain /test-string-pool +/test-svn-fe /test-treap /common-cmds.h *.tar.gz
Makefile +6 -2
@@ -417,6 +417,7 @@ TEST_PROGRAMS_NEED_X += test-run-command TEST_PROGRAMS_NEED_X += test-sha1 TEST_PROGRAMS_NEED_X += test-sigchain TEST_PROGRAMS_NEED_X += test-string-pool +TEST_PROGRAMS_NEED_X += test-svn-fe TEST_PROGRAMS_NEED_X += test-treap TEST_PROGRAMS_NEED_X += test-index-version
@@ -1745,7 +1746,7 @@ 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 \ - vcs-svn/repo_tree.o vcs-svn/fast_export.o + vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1870,7 +1871,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/line_buffer.h vcs-svn/repo_tree.h vcs-svn/fast_export.h \ + vcs-svn/svndump.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
@@ -2025,6 +2027,8 @@ test-parse-options$X: parse-options.o test-string-pool$X: vcs-svn/lib.a +test-svn-fe$X: vcs-svn/lib.a + .PRECIOUS: $(TEST_OBJS) test-%$X: test-%.o $(GITLIBS)
contrib/svn-fe/svn-fe.c +1 -0
@@ -10,6 +10,7 @@ int main(int argc, char **argv) {svndump_init (NULL );svndump_read ((argc >1 ) ? argv[1 ] :NULL ); +svndump_deinit ();svndump_reset ();return 0 ; }
t/t9010-svn-fe.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh + +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 + ) + ' +} + +test_dump simple t9111/svnsync.dump + +test_done
test-svn-fe.c new file +18 -0
@@ -0,0 +1,18 @@ +/* +* test-svn-fe: Code to exercise the svn import lib +*/ + +#include "git-compat-util.h" +#include "vcs-svn/svndump.h" + +int main (int argc,char *argv[]) +{ +if (argc !=2 ) +usage ("test-svn-fe <file>" ); +svndump_init (argv[1 ]); +svndump_read (NULL ); +svndump_deinit (); +svndump_reset (); +return 0 ; +} +
vcs-svn/LICENSE +4 -0
@@ -4,6 +4,10 @@ All rights reserved. Copyright (C) 2008 Jason Evans <[email protected]>. All rights reserved. +Copyright (C) 2005 Stefan Hegny, hydrografix Consulting GmbH, +Frankfurt/Main, Germany +and others, see http://svn2cc.sarovar.org + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
vcs-svn/svndump.c new file +302 -0
302 lines not on this page · raw message
vcs-svn/svndump.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef SVNDUMP_H_ +#define SVNDUMP_H_ + +void svndump_init (const char *filename); +void svndump_read (const char *url); +void svndump_deinit (void ); +void svndump_reset (void ); + +#endif
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 08/10] SVN dump parser
vcs-svn/svndump.c line 33
Quoted 8 lines · Jonathan Nieder
vcs-svn/svndump.c new file +1
-0@@ -0,0 +1,302 @@ +static char *log_copy (uint32_t length,char *log)
Style: static char *log_copy(...)
PATCH 09/10] Update svn-fe manual
In reply to Jonathan NiederThe svn-fe example does not litter the working directory with .bin files any more (hoorah!).
The permissive error handling implies a known bug. We should be flagging iffy input and, even if we continue, reporting it on exit.
--- contrib/svn-fe/svn-fe.txt | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
contrib/svn-fe/svn-fe.txt +6 -8
@@ -43,11 +43,9 @@ user <user@UUID> as committer, where 'user' is the value of the `svn:author` property and 'UUID' the repository's identifier. -To support incremental imports, 'svn-fe' will put a `git-svn-id` -line at the end of each commit log message if passed an url on the -command line. This line has the form `git-svn-id: URL@REVNO UUID`. - -Empty directories and unknown properties are silently discarded. +To support incremental imports, 'svn-fe' puts a `git-svn-id` line at +the end of each commit log message if passed an url on the command +line. This line has the form `git-svn-id: URL@REVNO UUID`. The resulting repository will generally require further processing to put each project in its own repository and to separate the history
@@ -56,9 +54,9 @@ may be useful for this purpose. BUGS ---- -Litters the current working directory with .bin files for -persistence. Will be fixed when the svn-fe infrastructure is aware of -a Git working directory. +Empty directories and unknown properties are silently discarded. + +The exit status does not reflect whether an error was detected. SEE ALSO --------
Signature · 1 line
1.7.2.1.544.ga752d.dirty
PATCH 10/10 svn-fe manual: Clarify warning about deltas in dump files
In reply to Jonathan NiederThose in the know would notice that dump file format version 2 means "svnadmin dump --no-deltas", but for the rest of us, an explicit reminder is useful.
---
That’s the end of the series. Thanks for reading.
On the horizon, as you may have guessed, are changes to use dumpfile format v3. Doing so sanely requires two-way communication with fast-import, I think (as discussed). Ram has already put together a prototype delta applier, so it seems to be mostly a matter of plumbing now.
contrib/svn-fe/svn-fe.txt | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
contrib/svn-fe/svn-fe.txt +4 -1
@@ -12,7 +12,7 @@ svnadmin dump --incremental REPO | svn-fe [url] | git fast-import DESCRIPTION ----------- -Converts a Subversion dumpfile (version: 2) into input suitable for +Converts a Subversion dumpfile into input suitable for git-fast-import(1) and similar importers. REPO is a path to a Subversion repository mirrored on the local disk. Remote Subversion repositories can be mirrored on local disk using the `svnsync`
@@ -25,6 +25,9 @@ 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)
Signature · 1 line
1.7.2.1.544.ga752d.dirty
Re: [PATCH 0/10] rr/svn-export reroll
In reply to Jonathan NiederHi Jonathan,
Quoted 7 lines · Jonathan Nieder
svn-fe has some serious changes on the horizon. As a preparation, let’s round up what we have now.
The most controversial change is probably the new svn-fe test, which takes about 15 seconds (for the “svnadmin load”, not the svn-fe step :)). It is in the t9* series, so hopefully that will not dissuade people from running the earlier tests.
I'll comment on this separately.
Quoted 7 lines
The main highlight in the changes is a new
Input error
to stderr if a system call failed in reading in the dump file. It still returns status 0 in this and other error situations, though.
I'll comment on this separately.
Quoted 3 lines
Based on maint (for no good reason; that’s just where I tried it). Intended to replace rr/svn-export in pu (only if Ram likes it, of course).
Thanks for re-rolling (again)! You've also added a note to the commit messages briefly explaining what each contributor has done. I'd expected some incremental patches instead of a full re-roll, but whatever works is good :)
Quoted 7 lines
David Barr (5):
Add memory pool library
Add string-specific memory pool
Add stream helper library
Infrastructure to write revisions in fast-export format SVN dump parser
Quoted 5 lines
Jason Evans (1):
Add treap implementationJonathan Nieder (4):
Introduce vcs-svn lib
All these are good :)
Quoted 1 line
Export
parse_date_basic()to convert a date string to timestamp
Wasn't this ejected from this series and made a separate patch?
Quoted 1 line
Update svn-fe manual
Removed the BUG since we've turned off persistence.
Quoted 1 line
svn-fe manual: Clarify warning about deltas in dumpfiles
We have to fix this real soon- I'm waiting for the weekend so I get some solid chunks of hacking time.
-- Ram
Re: [PATCH 0/10] rr/svn-export reroll
Quoted 3 lines · Ramkumar Ramachandra
I'dexpected some incremental patches instead of a full re-roll, but whatever works is good :)
Yeah, I think after this series the topic has stabilized enough to build on. :)
Quoted 1 line
All these are good :)
Thanks for checking.
cover svn delta applier
In reply to Ramkumar RamachandraHi,
The svndiff format has proved more difficult to parse than expected. This series documents the current state of things, and though it is not complete, it should be ready for nitpicking by the masses.
Patches 1-4 modify the line_buffer API by introducing a struct line_buffer to collect state that was previously held in global variables. Callers can use multiple line_buffers to manage input from multiple files at a time.
Patches 5-10 add various utility functions to the line_buffer API (wrapping strbuf_fread(), fgetc(), etc). Putting the helpers there instead of having callers work with the FILE* directly means one could easily
- tweak the input stream (to insert "link: " at the beginning for symlinks?);
- trace reads, for debugging; or
- use read() directly in place of stdio and limit the number of bytes buffered
if one wants to.
Patch 11 adds a data structure and function to manage a "sliding window" without using mmap() or fseek(). See the svndiff0 spec[1] for how this would be used.
Patches 12 and 13 are some basic components for reading an svndiff0
file: reading variable-length integers and the opening magic bytes.
Patch 15 makes the svn-fe test usable on systems (like Ram's) without libsvn-perl installed. It also should make the test easier to read for people unfamiliar with lib-git-svn.sh.
Patch 16 is the delta parser/applier. This patch does _not_ add it to contrib/svn-fe, even though that would be useful, since the command-line interface is not set in stone yet. If you want to try it out, use the test-svn-fe command:
test-svn-fe -d <preimage> <delta> <delta length>
The preimage or delta arg can be /dev/stdin for use in a pipeline. Both are only read sequentially; they do not need to be regular files.
One of the test cases is enormous. The svn delta lib doesn't use multiple windows except when dealing with relatively big files, but probably the test case should be replaced with a smaller, artificial example.
One of the test cases does not pass. I also don't know how to apply the delta by hand --- it seems to have some extra bytes at the end. :( Unfortunately the svndiff0 spec is not as clear about when to stop reading as one might like
The code separately maintains nominal and actual lengths for a few buffers, since truncated input is permitted (and even required) in the deltas svn produces, though the svndiff0 spec does not document the semantics of that.
For svn-fe changes to take advantage of this code to handle the dumpfilev3 format, see <git://github.com/barrbrain/git.git>[2]. So now the full svnrdump | svn-fe | fast-import pipeline can be experienced. It still chokes on some deltas in the wild.
Thoughts, cleanups, test cases, bug reports, improvements welcome. :)
Enjoy,
Jonathan Nieder (15):
vcs-svn: Eliminate global byte_buffer[] array
vcs-svn: Replace buffer_read_string()'s memory pool with a strbuf
vcs-svn: Collect line_buffer data in a struct
vcs-svn: Teach line_buffer to handle multiple input files
vcs-svn: Make buffer_skip_bytes() report partial reads
vcs-svn: Better support for reading large files
vcs-svn: Add binary-safe read() function
vcs-svn: Let callers peek ahead to find stream end
vcs-svn: Allow input errors to be detected early
vcs-svn: Allow character-oriented input
vcs-svn: Add code to maintain a sliding view of a file
vcs-svn: Learn to parse variable-length integers
vcs-svn: Learn to check for SVN\0 magic
compat: helper for detecting unsigned overflow
vcs-svn: Add svn delta parser
Ramkumar Ramachandra (1):
t9010 (svn-fe): Eliminate dependency on svn perl bindings
Makefile | 5 +- vcs-svn/line_buffer.txt | 8 +- vcs-svn/fast_export.c | 6 +- vcs-svn/fast_export.h | 5 +- vcs-svn/line_buffer.c | 99 +- vcs-svn/line_buffer.h | 29 +- vcs-svn/sliding_window.c | 65 + vcs-svn/sliding_window.h | 14 + vcs-svn/svndiff.c | 344 + vcs-svn/svndiff.h | 9 + vcs-svn/svndump.c | 29 +- vcs-svn/LICENSE | 2 + git-compat-util.h | 6 + test-line-buffer.c | 17 +- test-svn-fe.c | 37 +- t/t9010-svn-fe.sh | 29 +- t/t9010/Xerces.cpp.diff0 | Bin 0 -> 12185 bytes t/t9010/Xerces.cpp.done |54963 +++++++++++++++++++++++++++++++++++++++++++++ t/t9010/Xerces.cpp.src |55052 ++++++++++++++++++++++++++++++++++++++++++++++ t/t9010/newdata.diff0 | Bin 0 -> 19392 bytes t/t9010/newdata.done | 522 + t/t9010/src.diff0 | Bin 0 -> 74 bytes t/t9010/src.done | 522 + 23 files changed, 111677 insertions(+), 86 deletions(-) create mode 100644 vcs-svn/sliding_window.c create mode 100644 vcs-svn/sliding_window.h create mode 100644 vcs-svn/svndiff.c create mode 100644 vcs-svn/svndiff.h create mode 100644 t/t9010/Xerces.cpp.diff0 create mode 100644 t/t9010/Xerces.cpp.done create mode 100644 t/t9010/Xerces.cpp.src create mode 100644 t/t9010/blank.done create mode 100644 t/t9010/newdata.diff0 create mode 100644 t/t9010/newdata.done create mode 100644 t/t9010/src.diff0 create mode 100644 t/t9010/src.done
[1] http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff
[2] And some design notes:
http://thread.gmane.org/gmane.comp.version-control.git/150005/focus=157119
PATCH 1/16 vcs-svn: Eliminate global byte_buffer[] array
The data stored in byte_buffer[] is always either discarded or written to stdout immediately. No need for it to persist between function calls.
--- vcs-svn/line_buffer.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
vcs-svn/line_buffer.c +2 -1
@@ -14,7 +14,6 @@ obj_pool_gen(blob, char, 4096)static char line_buffer[LINE_BUFFER_LEN ]; -static char byte_buffer[COPY_BUFFER_LEN ];static FILE *infile;int buffer_init (const char *filename)
@@ -68,6 +67,7 @@ char *buffer_read_string(uint32_t len)void buffer_copy_bytes (uint32_t len) { +char byte_buffer[COPY_BUFFER_LEN ];uint32_t in;while (len >0 && !feof (infile) && !ferror (infile)) { in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ;
@@ -83,6 +83,7 @@ void buffer_copy_bytes(uint32_t len)void buffer_skip_bytes (uint32_t len) { +char byte_buffer[COPY_BUFFER_LEN ];uint32_t in;while (len >0 && !feof (infile) && !ferror (infile)) { in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ;
Signature · 1 line
1.7.2.3
PATCH 2/16 vcs-svn: Replace buffer_read_string() memory pool with a strbuf
In reply to Jonathan NiederThe buffer_read_string() function returns a temporary string of size specified by the caller. It currently uses an obj_pool to store the return value, but that is overkill: all we need is a buffer that can grow between requests to accomodate larger strings.
Use a strbuf instead.
---
[Resent after messing up the message header; sorry for the noise.]
vcs-svn/line_buffer.c | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
vcs-svn/line_buffer.c +6 -10
@@ -5,15 +5,13 @@#include "git-compat-util.h" #include "line_buffer.h" -#include "obj_pool.h" +#include "strbuf.h" #define LINE_BUFFER_LEN 10000#define COPY_BUFFER_LEN 4096 -/* Create memory pool for char sequence of known length */ -obj_pool_gen(blob, char, 4096) -static char line_buffer[LINE_BUFFER_LEN ]; +static struct strbuf blob_buffer =STRBUF_INIT ;static FILE *infile;int buffer_init (const char *filename)
@@ -58,11 +56,9 @@ char *buffer_read_line(void)char *buffer_read_string (uint32_t len) { -char *s; -blob_free (blob_pool.size); - s =blob_pointer (blob_alloc (len +1 )); - s[fread (s,1 , len, infile)] ='\0' ; -return ferror (infile) ?NULL : s; +strbuf_reset (&blob_buffer); +strbuf_fread (&blob_buffer, len, infile); +return ferror (infile) ?NULL : blob_buffer.buf; }void buffer_copy_bytes (uint32_t len)
@@ -94,5 +90,5 @@ void buffer_skip_bytes(uint32_t len)void buffer_reset (void ) { -blob_reset (); +strbuf_release (&blob_buffer); }
Signature · 1 line
1.7.2.3
PATCH 3/16 vcs-svn: Collect line_buffer data in a struct
In reply to Jonathan NiederPrepare for the line_buffer lib to support input from multiple files, by collecting global state in a struct that can be easily passed around.
--- vcs-svn/line_buffer.c | 45 ++++++++++++++++++++++----------------------- vcs-svn/line_buffer.h | 11 +++++++++++ 2 files changed, 33 insertions(+), 23 deletions(-)
vcs-svn/line_buffer.c +22 -23
@@ -7,17 +7,16 @@#include "line_buffer.h" #include "strbuf.h" -#define LINE_BUFFER_LEN 10000#define COPY_BUFFER_LEN 4096 - -static char line_buffer[LINE_BUFFER_LEN ]; -static struct strbuf blob_buffer =STRBUF_INIT ; -static FILE *infile; +static struct line_buffer buf_ =LINE_BUFFER_INIT ; +static struct line_buffer *buf;int buffer_init (const char *filename) { - infile = filename ?fopen (filename,"r" ) : stdin; -if (!infile) + buf = &buf_; + + buf->infile = filename ?fopen (filename,"r" ) : stdin; +if (!buf->infile)return -1 ;return 0 ; }
@@ -25,10 +24,10 @@ int buffer_init(const char *filename)int buffer_deinit (void ) {int err; -if (infile == stdin) -return ferror (infile); - err =ferror (infile); - err |=fclose (infile); +if (buf->infile == stdin) +return ferror (buf->infile); + err =ferror (buf->infile); + err |=fclose (buf->infile);return err; }
@@ -36,13 +35,13 @@ int buffer_deinit(void)char *buffer_read_line (void ) {char *end; -if (!fgets (line_buffer,sizeof (line_buffer), infile)) +if (!fgets (buf->line_buffer,sizeof (buf->line_buffer), buf->infile))/* Error or data exhausted. */ return NULL ; - end = line_buffer +strlen (line_buffer); + end = buf->line_buffer +strlen (buf->line_buffer);if (end[-1 ] =='\n' ) end[-1 ] ='\0' ; -else if (feof (infile)) +else if (feof (buf->infile)) ;/* No newline at end of file. That's fine. */ else /*
@@ -51,23 +50,23 @@ char *buffer_read_line(void)* but for now let's return an error. */ return NULL ; -return line_buffer; +return buf->line_buffer; }char *buffer_read_string (uint32_t len) { -strbuf_reset (&blob_buffer); -strbuf_fread (&blob_buffer, len, infile); -return ferror (infile) ?NULL : blob_buffer.buf; +strbuf_reset (&buf->blob_buffer); +strbuf_fread (&buf->blob_buffer, len, buf->infile); +return ferror (buf->infile) ?NULL : buf->blob_buffer.buf; }void buffer_copy_bytes (uint32_t len) {char byte_buffer[COPY_BUFFER_LEN ];uint32_t in; -while (len >0 && !feof (infile) && !ferror (infile)) { +while (len >0 && !feof (buf->infile) && !ferror (buf->infile)) { in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ; - in =fread (byte_buffer,1 , in, infile); + in =fread (byte_buffer,1 , in, buf->infile); len -= in;fwrite (byte_buffer,1 , in, stdout);if (ferror (stdout)) {
@@ -81,14 +80,14 @@ void buffer_skip_bytes(uint32_t len) {char byte_buffer[COPY_BUFFER_LEN ];uint32_t in; -while (len >0 && !feof (infile) && !ferror (infile)) { +while (len >0 && !feof (buf->infile) && !ferror (buf->infile)) { in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ; - in =fread (byte_buffer,1 , in, infile); + in =fread (byte_buffer,1 , in, buf->infile); len -= in; } }void buffer_reset (void ) { -strbuf_release (&blob_buffer); +strbuf_release (&buf->blob_buffer); }
vcs-svn/line_buffer.h +11 -0
@@ -1,6 +1,17 @@#ifndef LINE_BUFFER_H_ #define LINE_BUFFER_H_ +#include "strbuf.h" + +#define LINE_BUFFER_LEN 10000 + +struct line_buffer { +char line_buffer[LINE_BUFFER_LEN ]; +struct strbuf blob_buffer; +FILE *infile; +}; +#define LINE_BUFFER_INIT {"", STRBUF_INIT, NULL} +int buffer_init (const char *filename);int buffer_deinit (void );char *buffer_read_line (void );
Signature · 1 line
1.7.2.3
PATCH 4/16 vcs-svn: Teach line_buffer to handle multiple input files
In reply to Jonathan NiederCollect the line_buffer state in a newly public line_buffer struct. Callers can use multiple line_buffers to manage input from multiple files at a time.
The Subversion-format delta applier will use this to stream a delta and the preimage it applies to at the same time.
--- vcs-svn/line_buffer.txt | 5 +++-- vcs-svn/fast_export.c | 6 +++--- vcs-svn/fast_export.h | 5 ++++- vcs-svn/line_buffer.c | 20 ++++++++------------ vcs-svn/line_buffer.h | 14 +++++++------- vcs-svn/svndump.c | 29 ++++++++++++++++------------- test-line-buffer.c | 17 +++++++++-------- 7 files changed, 50 insertions(+), 46 deletions(-)
vcs-svn/line_buffer.txt +3 -2
@@ -14,14 +14,15 @@ Calling sequence The calling program: + - initializes a `struct line_buffer` to LINE_BUFFER_INIT - specifies a file to read with `buffer_init` - processes input with `buffer_read_line`, `buffer_read_string`, `buffer_skip_bytes`, and `buffer_copy_bytes` - closes the file with `buffer_deinit`, perhaps to start over and read another file. -Before exiting, the caller can use `buffer_reset` to deallocate -resources for the benefit of profiling tools. +When finished, the caller can use `buffer_reset` to deallocate +resources. Functions ---------
vcs-svn/fast_export.c +3 -3
@@ -63,14 +63,14 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log,printf ("progress Imported commit %" PRIu32".\n\n" , revision); } -void fast_export_blob (uint32_t mode,uint32_t mark,uint32_t len) +void fast_export_blob (uint32_t mode,uint32_t mark,uint32_t len,struct line_buffer *input) {if (mode ==REPO_MODE_LNK ) {/* svn symlink blobs start with "link " */ -buffer_skip_bytes (5 ); +buffer_skip_bytes (input,5 ); len -=5 ; }printf ("blob\nmark :%" PRIu32"\ndata %" PRIu32"\n" , mark, len); -buffer_copy_bytes (len); +buffer_copy_bytes (input, len);fputc ('\n' , stdout); }
vcs-svn/fast_export.h +4 -1
@@ -1,11 +1,14 @@#ifndef FAST_EXPORT_H_ #define FAST_EXPORT_H_ +#include "line_buffer.h" +void fast_export_delete (uint32_t depth,uint32_t *path);void fast_export_modify (uint32_t depth,uint32_t *path,uint32_t mode,uint32_t mark);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); +void fast_export_blob (uint32_t mode,uint32_t mark,uint32_t len, +struct line_buffer *input);#endif
vcs-svn/line_buffer.c +8 -12
@@ -8,20 +8,16 @@#include "strbuf.h" #define COPY_BUFFER_LEN 4096 -static struct line_buffer buf_ =LINE_BUFFER_INIT ; -static struct line_buffer *buf; -int buffer_init (const char *filename) +int buffer_init (struct line_buffer *buf,const char *filename) { - buf = &buf_; - buf->infile = filename ?fopen (filename,"r" ) : stdin;if (!buf->infile)return -1 ;return 0 ; } -int buffer_deinit (void ) +int buffer_deinit (struct line_buffer *buf) {int err;if (buf->infile == stdin)
@@ -32,7 +28,7 @@ int buffer_deinit(void) }/* Read a line without trailing newline. */ -char *buffer_read_line (void ) +char *buffer_read_line (struct line_buffer *buf) {char *end;if (!fgets (buf->line_buffer,sizeof (buf->line_buffer), buf->infile))
@@ -53,14 +49,14 @@ char *buffer_read_line(void)return buf->line_buffer; } -char *buffer_read_string (uint32_t len) +char *buffer_read_string (struct line_buffer *buf,uint32_t len) {strbuf_reset (&buf->blob_buffer);strbuf_fread (&buf->blob_buffer, len, buf->infile);return ferror (buf->infile) ?NULL : buf->blob_buffer.buf; } -void buffer_copy_bytes (uint32_t len) +void buffer_copy_bytes (struct line_buffer *buf,uint32_t len) {char byte_buffer[COPY_BUFFER_LEN ];uint32_t in;
@@ -70,13 +66,13 @@ void buffer_copy_bytes(uint32_t len) len -= in;fwrite (byte_buffer,1 , in, stdout);if (ferror (stdout)) { -buffer_skip_bytes (len); +buffer_skip_bytes (buf, len);return ; } } } -void buffer_skip_bytes (uint32_t len) +void buffer_skip_bytes (struct line_buffer *buf,uint32_t len) {char byte_buffer[COPY_BUFFER_LEN ];uint32_t in;
@@ -87,7 +83,7 @@ void buffer_skip_bytes(uint32_t len) } } -void buffer_reset (void ) +void buffer_reset (struct line_buffer *buf) {strbuf_release (&buf->blob_buffer); }
vcs-svn/line_buffer.h +7 -7
@@ -12,12 +12,12 @@ struct line_buffer { };#define LINE_BUFFER_INIT {"", STRBUF_INIT, NULL} -int buffer_init (const char *filename); -int buffer_deinit (void ); -char *buffer_read_line (void ); -char *buffer_read_string (uint32_t len); -void buffer_copy_bytes (uint32_t len); -void buffer_skip_bytes (uint32_t len); -void buffer_reset (void ); +int buffer_init (struct line_buffer *buf,const char *filename); +int buffer_deinit (struct line_buffer *buf); +char *buffer_read_line (struct line_buffer *buf); +char *buffer_read_string (struct line_buffer *buf,uint32_t len); +void buffer_copy_bytes (struct line_buffer *buf,uint32_t len); +void buffer_skip_bytes (struct line_buffer *buf,uint32_t len); +void buffer_reset (struct line_buffer *buf);#endif
vcs-svn/svndump.c +16 -13
@@ -30,6 +30,8 @@/* Create memory pool for log messages */ obj_pool_gen(log, char, 4096) +static struct line_buffer input =LINE_BUFFER_INIT ; +static char *log_copy (uint32_t length,char *log) {char *buffer;
@@ -113,14 +115,14 @@ static void read_props(void)uint32_t key = ~0 ;char *val =NULL ;char *t; -while ((t =buffer_read_line ()) &&strcmp (t,"PROPS-END" )) { +while ((t =buffer_read_line (&input)) &&strcmp (t,"PROPS-END" )) {if (!strncmp (t,"K " ,2 )) { len =atoi (&t[2 ]); - key =pool_intern (buffer_read_string (len)); -buffer_read_line (); + key =pool_intern (buffer_read_string (&input, len)); +buffer_read_line (&input); }else if (!strncmp (t,"V " ,2 )) { len =atoi (&t[2 ]); - val =buffer_read_string (len); + val =buffer_read_string (&input, len);if (key == keys.svn_log) {/* Value length excludes terminating nul. */ rev_ctx.log =log_copy (len +1 , val);
@@ -135,7 +137,7 @@ static void read_props(void) node_ctx.type =REPO_MODE_LNK ; } key = ~0 ; -buffer_read_line (); +buffer_read_line (&input); } } }
@@ -177,9 +179,10 @@ static void handle_node(void) node_ctx.type = node_ctx.srcMode;if (node_ctx.mark) -fast_export_blob (node_ctx.type, node_ctx.mark, node_ctx.textLength); +fast_export_blob (node_ctx.type, + node_ctx.mark, node_ctx.textLength, &input);else if (node_ctx.textLength !=LENGTH_UNKNOWN ) -buffer_skip_bytes (node_ctx.textLength); +buffer_skip_bytes (&input, node_ctx.textLength); }static void handle_revision (void )
@@ -198,7 +201,7 @@ void svndump_read(const char *url)uint32_t key;reset_dump_ctx (pool_intern (url)); -while ((t =buffer_read_line ())) { +while ((t =buffer_read_line (&input))) { val =strstr (t,": " );if (!val)continue ;
@@ -250,7 +253,7 @@ void svndump_read(const char *url) node_ctx.propLength =atoi (val); }else if (key == keys.content_length) { len =atoi (val); -buffer_read_line (); +buffer_read_line (&input);if (active_ctx ==REV_CTX ) {read_props (); }else if (active_ctx ==NODE_CTX ) {
@@ -258,7 +261,7 @@ void svndump_read(const char *url) active_ctx =REV_CTX ; }else {fprintf (stderr,"Unexpected content length header: %" PRIu32"\n" , len); -buffer_skip_bytes (len); +buffer_skip_bytes (&input, len); } } }
@@ -270,7 +273,7 @@ void svndump_read(const char *url)void svndump_init (const char *filename) { -buffer_init (filename); +buffer_init (&input, filename);repo_init ();reset_dump_ctx (~0 );reset_rev_ctx (0 );
@@ -285,7 +288,7 @@ void svndump_deinit(void)reset_dump_ctx (~0 );reset_rev_ctx (0 );reset_node_ctx (NULL ); -if (buffer_deinit ()) +if (buffer_deinit (&input))fprintf (stderr,"Input error\n" );if (ferror (stdout))fprintf (stderr,"Output error\n" );
@@ -294,7 +297,7 @@ void svndump_deinit(void)void svndump_reset (void ) {log_reset (); -buffer_reset (); +buffer_reset (&input);repo_reset ();reset_dump_ctx (~0 );reset_rev_ctx (0 );
test-line-buffer.c +9 -8
@@ -22,25 +22,26 @@ static uint32_t strtouint32(const char *s)int main (int argc,char *argv[]) { +struct line_buffer buf =LINE_BUFFER_INIT ;char *s;if (argc !=1 )usage ("test-line-buffer < input.txt" ); -if (buffer_init (NULL )) +if (buffer_init (&buf,NULL ))die_errno ("open error" ); -while ((s =buffer_read_line ())) { - s =buffer_read_string (strtouint32 (s)); +while ((s =buffer_read_line (&buf))) { + s =buffer_read_string (&buf,strtouint32 (s));fputs (s, stdout);fputc ('\n' , stdout); -buffer_skip_bytes (1 ); -if (!(s =buffer_read_line ())) +buffer_skip_bytes (&buf,1 ); +if (!(s =buffer_read_line (&buf)))break ; -buffer_copy_bytes (strtouint32 (s) +1 ); +buffer_copy_bytes (&buf,strtouint32 (s) +1 ); } -if (buffer_deinit ()) +if (buffer_deinit (&buf))die ("input error" );if (ferror (stdout))die ("output error" ); -buffer_reset (); +buffer_reset (&buf);return 0 ; }
Signature · 1 line
1.7.2.3
PATCH 5/16 vcs-svn: Make buffer_skip_bytes() report partial reads
In reply to Jonathan NiederTell the caller know how many bytes were actually skipped.
--- vcs-svn/line_buffer.txt | 3 ++- vcs-svn/line_buffer.c | 15 ++++++++------- vcs-svn/line_buffer.h | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-)
vcs-svn/line_buffer.txt +2 -1
@@ -53,7 +53,8 @@ Functions `buffer_skip_bytes`:: Discards `len` bytes from the input stream (stopping early - if necessary because of an error or eof). + if necessary because of an error or eof). Return value is + the number of bytes successfully read. `buffer_reset`:: Deallocates non-static buffers.
vcs-svn/line_buffer.c +8 -7
@@ -72,15 +72,16 @@ void buffer_copy_bytes(struct line_buffer *buf, uint32_t len) } } -void buffer_skip_bytes (struct line_buffer *buf,uint32_t len) +uint32_t buffer_skip_bytes (struct line_buffer *buf,uint32_t nbytes) { -char byte_buffer[COPY_BUFFER_LEN ]; -uint32_t in; -while (len >0 && !feof (buf->infile) && !ferror (buf->infile)) { - in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ; - in =fread (byte_buffer,1 , in, buf->infile); - len -= in; +uint32_t done =0 ; +while (done < nbytes && !feof (buf->infile) && !ferror (buf->infile)) { +char byte_buffer[COPY_BUFFER_LEN ]; +uint32_t len = nbytes - done; +uint32_t in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ; + done +=fread (byte_buffer,1 , in, buf->infile); } +return done; }void buffer_reset (struct line_buffer *buf)
vcs-svn/line_buffer.h +1 -1
@@ -17,7 +17,7 @@ int buffer_deinit(struct line_buffer *buf);char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len);void buffer_copy_bytes (struct line_buffer *buf,uint32_t len); -void buffer_skip_bytes (struct line_buffer *buf,uint32_t len); +uint32_t buffer_skip_bytes (struct line_buffer *buf,uint32_t len);void buffer_reset (struct line_buffer *buf);#endif
Signature · 1 line
1.7.2.3
PATCH 6/16 vcs-svn: Improve support for reading large files
In reply to Jonathan NiederTweak the line_buffer API to permit seeking and cat-ing segments longer than 4 GiB. This would be particularly useful for applying deltas that remove a large segment from the middle of a file.
Callers would still have to be updated to take advantage of this.
---
Since off_t is a signed type, on systems with 32-bit file offsets, this might make things worse. Is that worth worrying about?
vcs-svn/line_buffer.c | 8 ++++---- vcs-svn/line_buffer.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
vcs-svn/line_buffer.c +4 -4
@@ -56,7 +56,7 @@ char *buffer_read_string(struct line_buffer *buf, uint32_t len)return ferror (buf->infile) ?NULL : buf->blob_buffer.buf; } -void buffer_copy_bytes (struct line_buffer *buf,uint32_t len) +void buffer_copy_bytes (struct line_buffer *buf,off_t len) {char byte_buffer[COPY_BUFFER_LEN ];uint32_t in;
@@ -72,12 +72,12 @@ void buffer_copy_bytes(struct line_buffer *buf, uint32_t len) } } -uint32_t buffer_skip_bytes (struct line_buffer *buf,uint32_t nbytes) +off_t buffer_skip_bytes (struct line_buffer *buf,off_t nbytes) { -uint32_t done =0 ; +off_t done =0 ;while (done < nbytes && !feof (buf->infile) && !ferror (buf->infile)) {char byte_buffer[COPY_BUFFER_LEN ]; -uint32_t len = nbytes - done; +off_t len = nbytes - done;uint32_t in = len <COPY_BUFFER_LEN ? len :COPY_BUFFER_LEN ; done +=fread (byte_buffer,1 , in, buf->infile); }
vcs-svn/line_buffer.h +2 -2
@@ -16,8 +16,8 @@ int buffer_init(struct line_buffer *buf, const char *filename);int buffer_deinit (struct line_buffer *buf);char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len); -void buffer_copy_bytes (struct line_buffer *buf,uint32_t len); -uint32_t buffer_skip_bytes (struct line_buffer *buf,uint32_t len); +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
Signature · 1 line
1.7.2.3
PATCH 7/16 vcs-svn: Add binary-safe read() function
In reply to Jonathan Niederbuffer_read_binary() writes to a strbuf so the caller does not need to keep track of the number of bytes read.
--- vcs-svn/line_buffer.c | 6 ++++++ vcs-svn/line_buffer.h | 1 + 2 files changed, 7 insertions(+), 0 deletions(-)
vcs-svn/line_buffer.c +6 -0
@@ -56,6 +56,12 @@ char *buffer_read_string(struct line_buffer *buf, uint32_t len)return ferror (buf->infile) ?NULL : buf->blob_buffer.buf; } +void buffer_read_binary (struct strbuf *sb,uint32_t size, +struct line_buffer *buf) +{ +strbuf_fread (sb, size, buf->infile); +} +void buffer_copy_bytes (struct line_buffer *buf,off_t len) {char byte_buffer[COPY_BUFFER_LEN ];
vcs-svn/line_buffer.h +1 -0
@@ -16,6 +16,7 @@ int buffer_init(struct line_buffer *buf, const char *filename);int buffer_deinit (struct line_buffer *buf);char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len); +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);
Signature · 1 line
1.7.2.3
PATCH 8/16 vcs-svn: Let callers peek ahead to find stream end
In reply to Jonathan NiederThe buffer_at_eof() function returns 1 if and only if all input from the input stream has been exhausted (because of EOF or error). The implementation calls fgetc() followed by ungetc() to force an EOF condition when there is no more input remaining.
Like many functions in the line_buffer API, this function is not thread-safe. It could be made to be so with a mutex if needed.
--- vcs-svn/line_buffer.c | 10 ++++++++++ vcs-svn/line_buffer.h | 1 + 2 files changed, 11 insertions(+), 0 deletions(-)
vcs-svn/line_buffer.c +10 -0
@@ -27,6 +27,16 @@ int buffer_deinit(struct line_buffer *buf)return err; } +int buffer_at_eof (struct line_buffer *buf) +{ +int ch; +if ((ch =fgetc (buf->infile)) ==EOF ) +return 1 ; +if (ungetc (ch, buf->infile) ==EOF ) +return error ("cannot unget %c: %s\n" , ch,strerror (errno)); +return 0 ; +} +/* Read a line without trailing newline. */ char *buffer_read_line (struct line_buffer *buf) {
vcs-svn/line_buffer.h +1 -0
@@ -14,6 +14,7 @@ struct line_buffer {int buffer_init (struct line_buffer *buf,const char *filename);int buffer_deinit (struct line_buffer *buf); +int buffer_at_eof (struct line_buffer *buf);char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len);void buffer_read_binary (struct strbuf *sb,uint32_t len,struct line_buffer *f);
Signature · 1 line
1.7.2.3
PATCH 9/16 vcs-svn: Allow input errors to be detected early
In reply to Jonathan NiederAdd a buffer_ferror() function to read the error flag from the input stream, so callers can do:
some_error_prone_operation(f, ...);
if (buffer_ferror(f))
return error("input error: %s", strerror(errno));instead of waiting until it is time to close the file.
--- vcs-svn/line_buffer.c | 5 +++++ vcs-svn/line_buffer.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
vcs-svn/line_buffer.c +5 -0
@@ -27,6 +27,11 @@ int buffer_deinit(struct line_buffer *buf)return err; } +int buffer_ferror (struct line_buffer *buf) +{ +return ferror (buf->infile); +} +int buffer_at_eof (struct line_buffer *buf) {int ch;
vcs-svn/line_buffer.h +1 -0
@@ -14,6 +14,7 @@ struct line_buffer {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);char *buffer_read_line (struct line_buffer *buf);char *buffer_read_string (struct line_buffer *buf,uint32_t len);
Signature · 1 line
1.7.2.3
PATCH 10/16 vcs-svn: Allow character-oriented input
In reply to Jonathan Niederbuffer_read_char() can be used in place of buffer_read_string(1) to avoid consuming valuable static buffer space. The delta applier will use this to read variable-length integers one byte at a time.
Underneath, it is fgetc(), wrapped so the line_buffer library can maintain its role as gatekeeper of input.
--- vcs-svn/line_buffer.c | 5 +++++ vcs-svn/line_buffer.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
vcs-svn/line_buffer.c +5 -0
@@ -42,6 +42,11 @@ int buffer_at_eof(struct line_buffer *buf)return 0 ; } +int buffer_read_char (struct line_buffer *buf) +{ +return fgetc (buf->infile); +} +/* Read a line without trailing newline. */ char *buffer_read_line (struct line_buffer *buf) {
vcs-svn/line_buffer.h +1 -0
@@ -18,6 +18,7 @@ int buffer_ferror(struct line_buffer *buf);int buffer_at_eof (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);
Signature · 1 line
1.7.2.3
PATCH 11/16 vcs-svn: Add code to maintain a sliding view of a file
In reply to Jonathan NiederSubversion's delta format has the convenient property that applying each section of the delta only requires examining (and keeping in memory) a small portion of the preimage. At any moment, this portion begins at a well-defined file offset and has a well-defined length, and as the delta is applied, it moves from the beginning to the end of the file. Add a move_window() function to keep track of such a window into a file.
You can use it like this:
struct line_buffer preimage = LINE_BUFFER_INIT;
buffer_init(&preimage, NULL);
struct view window = {&preimage, 0, STRBUF_INIT};
move_window(&window, 3, 7); /* (1) */
move_window(&window, 5, 5); /* (2) */
move_window(&window, 12, 2); /* (3) */
strbuf_release(&window.buf);
buffer_deinit(&preimage);In this example: (1) reads 10 bytes and discards the first 3;
(2) discards the first 2, which are not needed any more; and (3) skips 2 bytes and reads 2 new bytes to work with.
Whenever move_window() returns, the file position indicator is at position window->off + window->buf.len and the data from positions window->off to the current file position are stored in window->buf.
This function does only sequential access and never seeks, so it can be safely used on pipes and sockets.
On end-of-file, move_window() just silently reads less than the caller requested. On other errors, it prints a message to stderr and returns -1.
--- Makefile | 5 ++- vcs-svn/sliding_window.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++ vcs-svn/sliding_window.h | 14 ++++++++++ vcs-svn/LICENSE | 2 + 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 vcs-svn/sliding_window.c create mode 100644 vcs-svn/sliding_window.h
Makefile +3 -2
@@ -1765,7 +1765,8 @@ 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 \ - vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o + vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o \ + vcs-svn/sliding_window.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1892,7 +1893,7 @@ 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/svndump.h + vcs-svn/svndump.h vcs-svn/sliding_window.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
vcs-svn/sliding_window.c new file +65 -0
65 lines not on this page · raw message
vcs-svn/sliding_window.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef SLIDING_WINDOW_H_ +#define SLIDING_WINDOW_H_ + +#include "strbuf.h" + +struct view { +struct line_buffer *file; +off_t off; +struct strbuf buf; +}; + +extern int move_window (struct view *view,off_t off,size_t len); + +#endif
vcs-svn/LICENSE +2 -0
@@ -1,6 +1,8 @@ Copyright (C) 2010 David Barr <[email protected]>. All rights reserved. +Copyright (C) 2010 Jonathan Nieder <[email protected]>. + Copyright (C) 2008 Jason Evans <[email protected]>. All rights reserved.
Signature · 1 line
1.7.2.3
PATCH 12/16 vcs-svn: Learn to parse variable-length integers
In reply to Jonathan NiederThe humble beginnings of the svn-format delta applier.
---
Maybe this should be squashed with patch 16.
Ideas for eliminating the code duplication?
vcs-svn/svndiff.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-) create mode 100644 vcs-svn/svndiff.c
vcs-svn/svndiff.c new file +59 -0
@@ -0,0 +1,59 @@ +/* +* Licensed under a two-clause BSD-style license. +* See LICENSE for details. +*/ + +#include "git-compat-util.h" +#include "line_buffer.h" + +/* +* svndiff0 applier +* +* See http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff. +* +* int ::= highdigit* lowdigit; +* highdigit ::= # binary 1000 0000 OR-ed with 7 bit value; +* lowdigit ::= # 7 bit value; +*/ + +#define VLI_CONTINUE 0x80 +#define VLI_DIGIT_MASK 0x7f +#define VLI_BITS_PER_DIGIT 7 + +static int read_int (struct line_buffer *in,uintmax_t *result,off_t *len) +{ +off_t sz = *len; +uintmax_t rv =0 ; +while (sz) { +int ch =buffer_read_char (in); +if (ch ==EOF ) +break ; + sz--; + rv <<=VLI_BITS_PER_DIGIT ; + rv += (ch &VLI_DIGIT_MASK ); +if (!(ch &VLI_CONTINUE )) { + *result = rv; + *len = sz; +return 0 ; + } + } +return error ("Invalid delta: incomplete integer %" PRIuMAX, rv); +} + +static int parse_int (const char **buf,size_t *result,const char *end) +{ +const char *pos; +size_t rv =0 ; +for (pos = *buf; pos != end; pos++) { +unsigned char ch = *pos; + rv <<=VLI_BITS_PER_DIGIT ; + rv += (ch &VLI_DIGIT_MASK ); +if (!(ch &VLI_CONTINUE )) { + *result = rv; + *buf = pos +1 ; +return 0 ; + } + } +return error ("Invalid instruction: incomplete integer %" PRIu64, + (uint64_t ) rv); +}
Signature · 1 line
1.7.2.3
PATCH 13/16 vcs-svn: Learn to check for SVN\0 magic
In reply to Jonathan NiederThe magic number of svn deltas is SVN followed by a null byte. An alternative format (with compressed text) uses magic number SVN\1, but that is deprecated in favor of compressing the deltas as a whole as far as I can tell.
--- vcs-svn/svndiff.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
vcs-svn/svndiff.c +18 -0
@@ -11,6 +11,7 @@* * See http://svn.apache.org/repos/asf/subversion/trunk/notes/svndiff. * +* svndiff0 ::= 'SVN\0' window window*; * int ::= highdigit* lowdigit; * highdigit ::= # binary 1000 0000 OR-ed with 7 bit value; * lowdigit ::= # 7 bit value;
@@ -20,6 +21,23 @@#define VLI_DIGIT_MASK 0x7f#define VLI_BITS_PER_DIGIT 7 +static int read_magic (struct line_buffer *in,off_t *len) +{ +static const char magic[] = {'S' ,'V' ,'N' ,'\0' }; +struct strbuf sb =STRBUF_INIT ; +if (*len <sizeof (magic)) +return error ("Invalid delta: no file type header" ); +buffer_read_binary (&sb,sizeof (magic), in); +if (sb.len !=sizeof (magic)) +return error ("Invalid delta: no file type header" ); +if (memcmp (sb.buf, magic,sizeof (magic))) +return error ("Unrecognized file type %.*s" , + (int )sizeof (magic), sb.buf); + *len -=sizeof (magic); +strbuf_release (&sb); +return 0 ; +} +static int read_int (struct line_buffer *in,uintmax_t *result,off_t *len) {off_t sz = *len;
Signature · 1 line
1.7.2.3
PATCH 14/16 compat: helper for detecting unsigned overflow
In reply to Jonathan NiederThe idiom (a + b < a) works fine for detecting that an unsigned integer has overflowed, but the more explicit
unsigned_add_overflows(a, b)
might be easier to read.
Define such a macro, expanding roughly to ((a) < UINT_MAX - (b)). Because the expansion uses each argument only once outside of sizeof() expressions, it is safe to use this macro with arguments that have side-effects.
--- git-compat-util.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
git-compat-util.h +6 -0
@@ -31,6 +31,9 @@#define maximum_signed_value_of_type (a) \ (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) +#define maximum_unsigned_value_of_type (a) \ + (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) +/* * Signed integer overflow is undefined in C, so here's a helper macro * to detect if the sum of two integers will overflow.
@@ -40,6 +43,9 @@#define signed_add_overflows (a, b) \ ((b) > maximum_signed_value_of_type(a) - (a)) +#define unsigned_add_overflows (a, b) \ + ((b) > maximum_unsigned_value_of_type(a) - (a)) +#ifdef __GNUC__#define TYPEOF (x) (__typeof__(x))#else
Signature · 1 line
1.7.2.3
PATCH 15/16 t9010 (svn-fe): Eliminate dependency on svn perl bindings
In reply to Jonathan NiederFrom: Ramkumar Ramachandra <[email protected]>
The svn-fe test script only requires git and the svn command-line tools. Make these tests easier to read and run by not using the perl libsvn bindings and instead duplicating only the relevant code from lib-git-svn.sh.
--- t/t9010-svn-fe.sh | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
t/t9010-svn-fe.sh +12 -2
@@ -2,9 +2,19 @@ test_description='check svn dumpfile importer' -. ./lib-git-svn.sh +. ./test-lib.sh -test_dump() { +svnconf=$PWD/svnconf +export svnconf + +svn_cmd () { + subcommand=$1 && + shift && + mkdir -p "$svnconf" && + svn "$subcommand" --config-dir "$svnconf" "$@" +} + +test_dump () { label=$1 dump=$2 test_expect_success "$dump" '
Signature · 1 line
1.7.2.3
[PATCH/RFC 16'/16] vcs-svn: Add svn delta parser
In reply to Jonathan NiederImplement an svndiff 0 interpreter, for use by the dumpfilev3 importer. It is slower than it needs to be (e.g., it does not use fseek() on input) for simplicity.
This is based only on the spec and not Subversion's implementation of the svndiff0 spec.
The tests come from various deltas encountered in importing the Apache SVN repo.
The svndiff0 semantics are not completely documented, meaning that some of this work had to be done by guesswork. It is not complete.
This version of the patch omits the enormous Xerces.cpp test (which is not so interesting because it passes, anyway).
---
[alternate ending, for those who do not like reading 3-MiB messages - sorry about that]
Still not signed off because I haven't checked the copyright of the tests. I would prefer tiny deltas or deltas of some public-domain work (e.g., drafts of foundation documents of some country).
This patch owes a great deal to David and Ram, probably more than it owes to me. David made lots and lots of fixes. Ram introduced the tests and helped with design. Thomas provided an early sanity check for code clarity.
Thanks for reading.
Makefile | 4 +- t/t9010-svn-fe.sh | 14 ++ t/t9010/newdata.diff0 | Bin 0 -> 19392 bytes t/t9010/newdata.done | 522 +++++++++++++++++++++++++++++++++++++++++++++++++ t/t9010/src.diff0 | Bin 0 -> 74 bytes t/t9010/src.done | 522 +++++++++++++++++++++++++++++++++++++++++++++++++ test-svn-fe.c | 37 +++- vcs-svn/svndiff.c | 265 +++++++++++++++++++++++++ vcs-svn/svndiff.h | 9 + 9 files changed, 1364 insertions(+), 9 deletions(-) create mode 100644 t/t9010/blank.done create mode 100644 t/t9010/newdata.diff0 create mode 100644 t/t9010/newdata.done create mode 100644 t/t9010/src.diff0 create mode 100644 t/t9010/src.done create mode 100644 vcs-svn/svndiff.h
Makefile +2 -2
@@ -1766,7 +1766,7 @@ 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 \ vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o \ - vcs-svn/sliding_window.o + vcs-svn/sliding_window.o vcs-svn/svndiff.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1893,7 +1893,7 @@ 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/svndump.h vcs-svn/sliding_window.h + vcs-svn/sliding_window.h vcs-svn/svndump.h vcs-svn/svndiff.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t9010-svn-fe.sh +14 -0
@@ -14,6 +14,18 @@ svn_cmd () { svn "$subcommand" --config-dir "$svnconf" "$@" } +test_delta () { + delta="$TEST_DIRECTORY/$1" + preimage="$TEST_DIRECTORY/$2" + expect="$TEST_DIRECTORY/$3" + expectation=${4:-success} + test_expect_$expectation "$delta" ' + delta_len=$(wc -c <"$delta") && + test-svn-fe -d "$preimage" "$delta" $delta_len >actual && + test_cmp "$expect" actual + ' +} + test_dump () { label=$1 dump=$2
@@ -38,5 +50,7 @@ test_dump () { } test_dump simple t9135/svn.dump +test_delta t9010/newdata.diff0 t9010/blank.done t9010/newdata.done +test_delta t9010/src.diff0 t9010/newdata.done t9010/src.done failure test_done
t/t9010/blank.done new file +0 -0
t/t9010/newdata.diff0 new file binary +0 -0
t/t9010/newdata.done new file +522 -0
522 lines not on this page · raw message
t/t9010/src.diff0 new file binary +0 -0
t/t9010/src.done new file +522 -0
522 lines not on this page · raw message
test-svn-fe.c +30 -7
@@ -4,14 +4,37 @@#include "git-compat-util.h" #include "vcs-svn/svndump.h" +#include "vcs-svn/svndiff.h" +#include "vcs-svn/line_buffer.h" int main (int argc,char *argv[]) { -if (argc !=2 ) -usage ("test-svn-fe <file>" ); -svndump_init (argv[1 ]); -svndump_read (NULL ); -svndump_deinit (); -svndump_reset (); -return 0 ; +static const char test_svnfe_usage[] = +"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)" ; +if (argc <2 ) +usage (test_svnfe_usage); +if (argc ==2 ) { +svndump_init (argv[1 ]); +svndump_read (NULL ); +svndump_deinit (); +svndump_reset (); +return 0 ; + } +if (argc ==5 && !strcmp (argv[1 ],"-d" )) { +struct line_buffer preimage =LINE_BUFFER_INIT ; +struct line_buffer delta =LINE_BUFFER_INIT ; +buffer_init (&preimage, argv[2 ]); +buffer_init (&delta, argv[3 ]); +if (svndiff0_apply (&delta, (off_t )strtoull (argv[4 ],NULL ,0 ), + &preimage, stdout)) +return 1 ; +if (buffer_deinit (&preimage)) +die_errno ("cannot close preimage" ); +if (buffer_deinit (&delta)) +die_errno ("cannot close delta" ); +buffer_reset (&preimage); +buffer_reset (&delta); +return 0 ; + } +usage (test_svnfe_usage); }
vcs-svn/svndiff.c +265 -0
289 lines not on this page · raw message
vcs-svn/svndiff.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef SVNDIFF_H_ +#define SVNDIFF_H_ + +#include "line_buffer.h" + +extern int svndiff0_apply (struct line_buffer *delta,off_t delta_len, +struct line_buffer *preimage,FILE *postimage); + +#endif
Signature · 1 line
1.7.2.3
cover Building up the delta parser
Quoted 1 line · Jonathan Nieder
Implement an svndiff 0 interpreter
I hear that was nigh unreadable, so here's a reroll. Less cargo-cult support for broken deltas, more readability and tests. Patches apply on top of "[PATCH 15/16] t9010 (svn-fe): Eliminate dependency on svn perl bindings". As before, the end result includes a 'test-svn-fe -d' command that can apply svndiff0-format deltas, meaning less binary garbage to worry about as you puzzle over that confusing "svnrdump dump" output in debugging sessions.
Questions? Improvements? Bugs?
Patch 1 is a fixup to the variable-length integer parsing code, to report unexpected EOF (i.e., declared content length too long) correctly when it occurs in the middle of such an integer.
Patch 2 is the svndiff0 interpreter in broad strokes: read window, read window, read window, .... The patch doesn't encode any knowledge about what actually goes _in_ a window aside from the header, so it will error out for nonempty windows.
Patch 3 teaches the nacent interpreter to keep the appropriate piece of the preimage in memory. This is probably earlier in the series than it ought to be, but I wanted to try out the sliding window code.
With patches 4 and 5, the interpreter learns to read the "data" and "instructions" section of a window. The effect is observable because it finds the beginning of the next window correctly.
Patch 6 is an example instruction (copyfrom_data).
Patches 7-8 introduce some sanity checks.
Patches 9 and 10 are another instruction (copyfrom_target) and another sanity check.
Patch 11 is the last instruction (copyfrom_source). That's it. You can apply deltas now!
If anything seems unclear, please don't spend time puzzling it out --- just yell at me, so the code or documentation can be cleaned up. Happy reading.
PATCH 1/11 fixup! vcs-svn: Learn to parse variable-length integers
Report EOF correctly in integer parsing code.
---
This patch is meant for squashing.
vcs-svn/svndiff.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
vcs-svn/svndiff.c +2 -1
@@ -45,7 +45,8 @@ static int read_int(struct line_buffer *in, uintmax_t *result, off_t *len)while (sz) {int ch =buffer_read_char (in);if (ch ==EOF ) -break ; +return error ("Delta ends early (%" PRIu64" bytes remaining)" , + (uint64_t ) sz); sz--; rv <<=VLI_BITS_PER_DIGIT ; rv += (ch &VLI_DIGIT_MASK );
Signature · 1 line
1.7.2.3
PATCH 2/11 vcs-svn: Skeleton of an svn delta parser
In reply to Jonathan NiederA delta in the subversion delta (svndiff0) format consists of the magic bytes SVN\0 followed by a sequence of windows, each beginning with a window header consisting of five integers (with variable-length representation):
source view offset
source view length
output length
instructions length
auxiliary data length
Add an svndiff0_apply() function and test-svn-fe -d commandline tool to parse such a delta in the special case of not including any instructions or auxiliary data.
Later patches will add features to turn this into a fully functional delta applier, for use by svn-fe in parsing the streams produced by "svnrdump dump" and "svnadmin dump --deltas".
--- Makefile | 4 +- t/t9011-svn-da.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test-svn-fe.c | 39 ++++++++++++++++++++---- vcs-svn/svndiff.c | 64 +++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndiff.h | 9 ++++++ 5 files changed, 189 insertions(+), 9 deletions(-) create mode 100755 t/t9011-svn-da.sh create mode 100644 vcs-svn/svndiff.h
Makefile +2 -2
@@ -1766,7 +1766,7 @@ 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 \ vcs-svn/repo_tree.o vcs-svn/fast_export.o vcs-svn/svndump.o \ - vcs-svn/sliding_window.o + vcs-svn/sliding_window.o vcs-svn/svndiff.o OBJECTS := $(GIT_OBJS) $(XDIFF_OBJS) $(VCSSVN_OBJS) dep_files := $(foreach f,$(OBJECTS),$(dir $f).depend/$(notdir $f).d)
@@ -1893,7 +1893,7 @@ 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/svndump.h vcs-svn/sliding_window.h + vcs-svn/sliding_window.h vcs-svn/svndump.h vcs-svn/svndiff.h endif exec_cmd.s exec_cmd.o: EXTRA_CPPFLAGS = \
t/t9011-svn-da.sh new file +82 -0
82 lines not on this page · raw message
test-svn-fe.c +32 -7
@@ -4,14 +4,39 @@#include "git-compat-util.h" #include "vcs-svn/svndump.h" +#include "vcs-svn/svndiff.h" +#include "vcs-svn/line_buffer.h" int main (int argc,char *argv[]) { -if (argc !=2 ) -usage ("test-svn-fe <file>" ); -svndump_init (argv[1 ]); -svndump_read (NULL ); -svndump_deinit (); -svndump_reset (); -return 0 ; +static const char test_svnfe_usage[] = +"test-svn-fe (<dumpfile> | [-d] <preimage> <delta> <len>)" ; +if (argc <2 ) +usage (test_svnfe_usage); +if (argc ==2 ) { +svndump_init (argv[1 ]); +svndump_read (NULL ); +svndump_deinit (); +svndump_reset (); +return 0 ; + } +if (argc ==5 && !strcmp (argv[1 ],"-d" )) { +struct line_buffer preimage =LINE_BUFFER_INIT ; +struct line_buffer delta =LINE_BUFFER_INIT ; +if (buffer_init (&preimage, argv[2 ])) +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)) +return 1 ; +if (buffer_deinit (&preimage)) +die_errno ("cannot close preimage" ); +if (buffer_deinit (&delta)) +die_errno ("cannot close delta" ); +buffer_reset (&preimage); +buffer_reset (&delta); +return 0 ; + } +usage (test_svnfe_usage); }
vcs-svn/svndiff.c +64 -0
73 lines not on this page · raw message
vcs-svn/svndiff.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef SVNDIFF_H_ +#define SVNDIFF_H_ + +#include "line_buffer.h" + +extern int svndiff0_apply (struct line_buffer *delta,off_t delta_len, +struct line_buffer *preimage,FILE *postimage); + +#endif
Signature · 1 line
1.7.2.3
PATCH 3/11 vcs-svn: Read the preimage while applying deltas
In reply to Jonathan NiederThe source view offset heading each svndiff0 window represents a number of bytes past the beginning of the preimage. Together with the source view length, it instructs the delta applier about what portion of the preimage instructions will refer to. Read in that data right away using the sliding window code.
Maybe some day we will mmap() to prepare to read data more lazily.
For compatibility with Subversion's implementation, tolerate source view offsets pointing past the end of the preimage file (a later patch will remove this flexibility). For simplicity, also permit source views that start within the preimage and end outside of it, even though Subversion does not.
This does not teach the delta applier to read instructions or copy data from the source view yet. Deltas that would produce nonempty output are still rejected.
---
It occurs to me that Sam Vilain may well have something valuable to say about this series, having implemented something similar[1].
Sam, this series adds an svndiff0 parser for git to use in parsing v3 dumps (which are way easier to produce with remote access to an svn repository than v2 dumps). The beginning of the series is at [2], though that cover letter is out of date: now, modulo any new bugs I've introduced with this reroll, it is known to successfully apply all the deltas involved in a complete dump of the ASF repo.
I am interested in improvements and complaints of all kinds.
[1] http://search.cpan.org/~samv/Parse-SVNDiff-0.03/lib/Parse/SVNDiff.pm
[2] http://thread.gmane.org/gmane.comp.version-control.git/151086/focus=158731
t/t9011-svn-da.sh | 38 ++++++++++++++++++++++++++++++++++++++ vcs-svn/svndiff.c | 22 +++++++++++++++------- 2 files changed, 53 insertions(+), 7 deletions(-)
t/t9011-svn-da.sh +38 -0
@@ -79,4 +79,42 @@ test_expect_success 'nonempty (but unused) preimage view' ' test_cmp empty actual ' +test_expect_success 'preimage view: right endpoint cannot backtrack' ' + printf "SVNQ%b%b" "Q\003QQQ" "Q\002QQQ" | + q_to_nul >clear.backtrack && + test_must_fail test-svn-fe -d preimage clear.backtrack 14 +' + +test_expect_success 'preimage view: left endpoint can advance' ' + printf "SVNQ%b%b" "Q\003QQQ" "\001\002QQQ" | + q_to_nul >clear.preshrink && + printf "SVNQ%b%b" "Q\003QQQ" "\001\001QQQ" | + q_to_nul >clear.shrinkbacktrack && + test-svn-fe -d preimage clear.preshrink 14 >actual && + test_must_fail test-svn-fe -d preimage clear.shrinkbacktrack 14 && + test_cmp empty actual +' + +test_expect_success 'preimage view: offsets compared by value' ' + printf "SVNQ%b%b" "\001\001QQQ" "\0200Q\003QQQ" | + q_to_nul >clear.noisybacktrack && + printf "SVNQ%b%b" "\001\001QQQ" "\0200\001\002QQQ" | + q_to_nul >clear.noisyadvance && + test_must_fail test-svn-fe -d preimage clear.noisybacktrack 15 + test-svn-fe -d preimage clear.noisyadvance 15 && + test_cmp empty actual +' + +test_expect_success 'preimage view: accept truncated preimage' ' + printf "SVNQ%b" "\010QQQQ" | q_to_nul >clear.lateemptyread && + printf "SVNQ%b" "\010\001QQQ" | q_to_nul >clear.latenonemptyread && + printf "SVNQ%b" "\001\010QQQ" | q_to_nul >clear.longread && + test-svn-fe -d preimage clear.lateemptyread 9 >actual.emptyread && + test-svn-fe -d preimage clear.latenonemptyread 9 >actual.nonemptyread && + test-svn-fe -d preimage clear.longread 9 >actual.longread && + test_cmp empty actual.emptyread && + test_cmp empty actual.nonemptyread && + test_cmp empty actual.longread +' + test_done
vcs-svn/svndiff.c +15 -7
@@ -4,6 +4,7 @@*/ #include "git-compat-util.h" +#include "sliding_window.h" #include "line_buffer.h" /*
@@ -122,21 +123,28 @@ 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) { +struct view preimage_view = {preimage,0 ,STRBUF_INIT };assert (delta && preimage && postimage);if (read_magic (delta, &delta_len)) -return -1 ; + goto fail;while (delta_len >0 ) {/* For each window: */ -off_t pre_off; +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) ||apply_one_window (delta, &delta_len)) -return -1 ; -if (delta_len &&buffer_at_eof (delta)) -return error ("Delta ends early! " -"(%" PRIu64" bytes remaining)" , - (uint64_t ) delta_len); + goto fail; +if (delta_len &&buffer_at_eof (delta)) { +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 ; }
Signature · 1 line
1.7.2.3
Re: [PATCH 03/11] vcs-svn: Read the preimage while applying deltas
Quoted 11 lines · Jonathan Nieder
It occurs to me that Sam Vilain may well have something valuable to say about this series, having implemented something similar[1].
Sam, this series adds an svndiff0 parser for git to use in parsing v3 dumps (which are way easier to produce with remote access to an svn repository than v2 dumps). The beginning of the series is at [2], though that cover letter is out of date: now, modulo any new bugs I've introduced with this reroll, it is known to successfully apply all the deltas involved in a complete dump of the ASF repo.
[1] http://search.cpan.org/~samv/Parse-SVNDiff-0.03/lib/Parse/SVNDiff.pm
All I did was make the module lazy - version 0.02 was by 唐鳳, any detailed knowledge I had of the binary format fell out of my head pretty quickly :-)
Sam
Re: [PATCH 03/11] vcs-svn: Read the preimage while applying deltas
Quoted 3 lines · Sam Vilain
All I did was make the module lazy - version 0.02 was by 唐鳳, any detailed knowledge I had of the binary format fell out of my head pretty quickly :-)
Ah, my bad. 唐鳳, as part of an attempt to natively support fetching from and pushing to svn repositories, some contributors to the git project are working on an svndiff0 applier. If you're interested in reliving old memories, please feel free to look it over (especially the test cases). Thoughts, simplifications, bug reports, improvements welcome.
http://thread.gmane.org/gmane.comp.version-control.git/151086/focus=158913
Anyone wanting to try it can check out
git://repo.or.cz/git/jrn.git svn-da
and use the test-svn-fe command:
make test-svn-fe
./test-svn-fe -d <preimage> <delta> <delta length>
or the tests:
make cd t && sh t9011-svn-da.sh -v -i
The preimage or delta argument can be /dev/stdin for use in a pipeline.
Thanks for your work on svk and pugs!
Jonathan
PATCH 4/11 vcs-svn: Read inline data from deltas
In reply to Jonathan NiederEach window of an svndiff0-format delta includes a section for new data that will be copied into the preimage (in the order it appears in the window, possibly interspersed with other data).
Read this data when encountering it. It is not actually necessary to do so --- it would be just as easy to copy straight from the delta to output when interpreting the relevant instructions --- but this way, the code that interprets svndiff0 instructions can proceed more quickly because it does not require any I/O.
Subversion's implementation rejects deltas that do not consume all the auxiliary data that is available. Do not check that for now, because it would make it impossible to test the function of this patch until the instructions to consume data are implemented.
Do check for truncated data sections. Since Subversion's applier rejects deltas that end before the new-data section is declared to end, it should be safe for this applier to reject such deltas, too.
--- t/t9011-svn-da.sh | 12 ++++++++++++ vcs-svn/svndiff.c | 27 ++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-)
t/t9011-svn-da.sh +12 -0
@@ -117,4 +117,16 @@ test_expect_success 'preimage view: accept truncated preimage' ' test_cmp empty actual.longread ' +test_expect_success 'inline data' ' + printf "SVNQ%b%s%b%s" "QQQQ\003" "bar" "QQQQ\001" "x" | + q_to_nul >inline.clear && + test-svn-fe -d preimage inline.clear 18 >actual && + test_cmp empty actual +' + +test_expect_success 'truncated inline data' ' + printf "SVNQ%b%s" "QQQQ\003" "b" | q_to_nul >inline.trunc && + test_must_fail test-svn-fe -d preimage inline.trunc 10 +' + test_done
vcs-svn/svndiff.c +24 -3
@@ -23,6 +23,10 @@#define VLI_DIGIT_MASK 0x7f#define VLI_BITS_PER_DIGIT 7 +struct window { +struct strbuf data; +}; +static int read_magic (struct line_buffer *in,off_t *len) {static const char magic[] = {'S' ,'V' ,'N' ,'\0' };
@@ -101,11 +105,25 @@ static int read_length(struct line_buffer *in, size_t *result, off_t *len)return 0 ; } +static int read_chunk (struct line_buffer *delta,off_t *delta_len, +struct strbuf *buf,size_t len) +{ +if (len >maximum_signed_value_of_type (off_t) || + (off_t ) len > *delta_len) +return -1 ; +strbuf_reset (buf); +buffer_read_binary (buf, len, delta); + *delta_len -= buf->len; +return 0 ; +} +static int apply_one_window (struct line_buffer *delta,off_t *delta_len) { +struct window ctx = {STRBUF_INIT };size_t out_len;size_t instructions_len;size_t data_len; +int rv =0 ;assert (delta_len);/* "source view" offset and length already handled; */
@@ -115,9 +133,12 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len)return -1 ;if (instructions_len >0 )return error ("What do you think I am? A delta applier?" ); -if (data_len >0 ) -return error ("No support for inline data yet" ); -return 0 ; +if (read_chunk (delta, delta_len, &ctx.data, data_len)) +return error ("Invalid delta: incomplete data section" ); +if (buffer_ferror (delta)) + rv =error ("Cannot read delta: %s" ,strerror (errno)); +strbuf_release (&ctx.data); +return rv; } int svndiff0_apply(struct line_buffer *delta, off_t delta_len,
Signature · 1 line
1.7.2.3
PATCH 5/11 vcs-svn: Read instructions from deltas
In reply to Jonathan NiederBuffer the instruction section upon encountering it for later interpretation.
An alternative design would involve parsing the instructions at this point and buffering them in some processed form. Using the unprocessed form is simpler.
--- t/t9011-svn-da.sh | 5 +++++ vcs-svn/svndiff.c | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-)
t/t9011-svn-da.sh +5 -0
@@ -129,4 +129,9 @@ test_expect_success 'truncated inline data' ' test_must_fail test-svn-fe -d preimage inline.trunc 10 ' +test_expect_success 'truncated inline data (after instruction section)' ' + printf "SVNQ%b%b%s" "QQ\001\001\003" "\0201" "b" | q_to_nul >insn.trunc && + test_must_fail test-svn-fe -d preimage insn.trunc 11 +' + test_done
vcs-svn/svndiff.c +18 -5
@@ -24,6 +24,7 @@#define VLI_BITS_PER_DIGIT 7struct window { +struct strbuf instructions;struct strbuf data; };
@@ -119,7 +120,7 @@ static int read_chunk(struct line_buffer *delta, off_t *delta_len,static int apply_one_window (struct line_buffer *delta,off_t *delta_len) { -struct window ctx = {STRBUF_INIT }; +struct window ctx = {STRBUF_INIT ,STRBUF_INIT };size_t out_len;size_t instructions_len;size_t data_len;
@@ -131,13 +132,25 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len) read_length(delta, &instructions_len, delta_len) || read_length(delta, &data_len, delta_len))return -1 ; +if (read_chunk (delta, delta_len, &ctx.instructions, instructions_len)) +return error ("Invalid delta: incomplete instructions section" ); +if (buffer_ferror (delta)) { + rv =error ("Cannot read delta: %s" ,strerror (errno)); + goto done; + } +if (read_chunk (delta, delta_len, &ctx.data, data_len)) { + rv =error ("Invalid delta: incomplete data section" ); + goto done; + } +if (buffer_ferror (delta)) { + rv =error ("Cannot read delta: %s" ,strerror (errno)); + goto done; + }if (instructions_len >0 )return error ("What do you think I am? A delta applier?" ); -if (read_chunk (delta, delta_len, &ctx.data, data_len)) -return error ("Invalid delta: incomplete data section" ); -if (buffer_ferror (delta)) - rv =error ("Cannot read delta: %s" ,strerror (errno)); + done:strbuf_release (&ctx.data); +strbuf_release (&ctx.instructions);return rv; }
Signature · 1 line
1.7.2.3
PATCH 6/11 vcs-svn: Implement copyfrom_data delta instruction
In reply to Jonathan NiederThe copyfrom_data instruction copies a few bytes verbatim from the auxiliary data section of a window to the postimage.
--- t/t9011-svn-da.sh | 31 +++++++++++++++++++ vcs-svn/svndiff.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 112 insertions(+), 5 deletions(-)
t/t9011-svn-da.sh +31 -0
@@ -134,4 +134,35 @@ test_expect_success 'truncated inline data (after instruction section)' ' test_must_fail test-svn-fe -d preimage insn.trunc 11 ' +test_expect_success 'copyfrom_data' ' + echo hi >expect && + printf "SVNQ%b%b%b" "QQ\003\001\003" "\0203" "hi\n" | q_to_nul >copydat && + test-svn-fe -d preimage copydat 13 >actual && + test_cmp expect actual +' + +test_expect_success 'multiple copyfrom_data' ' + echo hi >expect && + printf "SVNQ%b%b%b%b%b" "QQ\003\002\003" "\0201\0202" "hi\n" \ + "QQQ\002Q" "\0200Q" | q_to_nul >copy.multi && + len=$(wc -c <copy.multi) && + test-svn-fe -d preimage copy.multi $len >actual && + test_cmp expect actual +' + +test_expect_success 'incomplete multiple insn' ' + printf "SVNQ%b%b%b" "QQ\003\002\003" "\0203\0200" "hi\n" | + q_to_nul >copy.partial && + len=$(wc -c <copy.partial) && + test_must_fail test-svn-fe -d preimage copy.partial $len +' + +test_expect_success 'catch attempt to copy missing data' ' + printf "SVNQ%b%b%s%b%s" "QQ\002\002\001" "\0201\0201" "X" \ + "QQQQ\002" "YZ" | + q_to_nul >copy.incomplete && + len=$(wc -c <copy.incomplete) && + test_must_fail test-svn-fe -d preimage copy.incomplete $len +' + test_done
vcs-svn/svndiff.c +81 -5
125 lines not on this page · raw message
Signature · 1 line
1.7.2.3
PATCH 7/11 vcs-svn: Check declared number of output bytes
In reply to Jonathan NiederCheck that the declared output size for each window is correct, and reserve that amount of space in the output buffer in advance.
--- vcs-svn/svndiff.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
vcs-svn/svndiff.c +5 -0
@@ -220,10 +220,15 @@ static int apply_one_window(struct line_buffer *delta, off_t *delta_len, rv =error ("Cannot read delta: %s" ,strerror (errno)); goto done; } +strbuf_grow (&ctx.out, out_len);if (apply_window_in_core (&ctx) ||write_strbuf (&ctx.out, out)) { rv =-1 ; goto done; } +if (ctx.out.len != out_len) { + rv =error ("Invalid delta: incorrect postimage length" ); + goto done; + } done:strbuf_release (&ctx.data);strbuf_release (&ctx.instructions);
Signature · 1 line
1.7.2.3
PATCH 8/11 vcs-svn: Reject deltas that do not consume all inline data
In reply to Jonathan NiederThe main point is to constrain the format of deltas more, so corruption and other breakage can be more easily detected.
Requiring deltas not to provide unconsumed data also opens the possibility of ignoring the declared amount of new data and simply streaming the data as needed to fulfill copyfrom_data requests.
--- t/t9011-svn-da.sh | 12 +++--------- vcs-svn/svndiff.c | 2 ++ 2 files changed, 5 insertions(+), 9 deletions(-)
t/t9011-svn-da.sh +3 -9
@@ -117,20 +117,14 @@ test_expect_success 'preimage view: accept truncated preimage' ' test_cmp empty actual.longread ' -test_expect_success 'inline data' ' +test_expect_success 'unconsumed inline data' ' printf "SVNQ%b%s%b%s" "QQQQ\003" "bar" "QQQQ\001" "x" | q_to_nul >inline.clear && - test-svn-fe -d preimage inline.clear 18 >actual && - test_cmp empty actual + test_must_fail test-svn-fe -d preimage inline.clear 18 >actual ' test_expect_success 'truncated inline data' ' - printf "SVNQ%b%s" "QQQQ\003" "b" | q_to_nul >inline.trunc && - test_must_fail test-svn-fe -d preimage inline.trunc 10 -' - -test_expect_success 'truncated inline data (after instruction section)' ' - printf "SVNQ%b%b%s" "QQ\001\001\003" "\0201" "b" | q_to_nul >insn.trunc && + printf "SVNQ%b%b%s" "QQ\003\001\003" "\0203" "b" | q_to_nul >insn.trunc && test_must_fail test-svn-fe -d preimage insn.trunc 11 '
vcs-svn/svndiff.c +2 -0
@@ -188,6 +188,8 @@ static int apply_window_in_core(struct window *ctx)while (insn != ctx->instructions.buf + ctx->instructions.len)if (step (ctx, &insn, &data_pos))return -1 ; +if (data_pos != ctx->data.len) +return error ("Invalid delta: does not copy all new data" );return 0 ; }
Signature · 1 line
1.7.2.3
PATCH 9/11 vcs-svn: Let deltas use data from postimage
In reply to Jonathan NiederThe copyfrom_target instruction copies appends data that is already present in the current output view to the end of output. (The offset argument is relative to the beginning of output produced by the current window.)
The region copied is allowed to run past the end of the existing output. To support that case, copy one character at a time rather than using memcpy() or memmove(). This allows copyfrom_target to be used once to repeat a string many times. For example:
COPYFROM_DATA 2
COPYFROM_OUTPUT 10, 0
DATA "ab"
would produce the output "ababababababababababab".
--- t/t9011-svn-da.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ vcs-svn/svndiff.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-)
t/t9011-svn-da.sh +42 -0
@@ -159,4 +159,46 @@ test_expect_success 'catch attempt to copy missing data' ' test_must_fail test-svn-fe -d preimage copy.incomplete $len ' +test_expect_success 'copyfrom target to repeat data' ' + printf foofoo >expect && + printf "SVNQ%b%b%s" "QQ\006\004\003" "\0203\0100\003Q" "foo" | + q_to_nul >copytarget.repeat && + len=$(wc -c <copytarget.repeat) && + test-svn-fe -d preimage copytarget.repeat $len >actual && + test_cmp expect actual +' + +test_expect_success 'copyfrom target out of order' ' + printf foooof >expect && + printf "SVNQ%b%b%s" \ + "QQ\006\007\003" "\0203\0101\002\0101\001\0101Q" "foo" | + q_to_nul >copytarget.reverse && + len=$(wc -c <copytarget.reverse) && + test-svn-fe -d preimage copytarget.reverse $len >actual && + test_cmp expect actual +' + +test_expect_success 'catch copyfrom future' ' + printf "SVNQ%b%b%s" "QQ\004\004\003" "\0202\0101\002\0201" "XYZ" | + q_to_nul >copytarget.infuture && + len=$(wc -c <copytarget.infuture) && + test_must_fail test-svn-fe -d preimage copytarget.infuture $len +' + +test_expect_success 'copy to sustain' ' + printf XYXYXYXYXYXZ >expect && + printf "SVNQ%b%b%s" "QQ\014\004\003" "\0202\0111Q\0201" "XYZ" | + q_to_nul >copytarget.sustain && + len=$(wc -c <copytarget.sustain) && + test-svn-fe -d preimage copytarget.sustain $len >actual && + test_cmp expect actual +' + +test_expect_success 'catch copy that overflows' ' + printf "SVNQ%b%b%s" "QQ\003\003\001" "\0201\0177Q" X | + q_to_nul >copytarget.overflow && + len=$(wc -c <copytarget.overflow) && + test_must_fail test-svn-fe -d preimage copytarget.overflow $len +' + test_done
vcs-svn/svndiff.c +28 -2
@@ -20,7 +20,12 @@* | packed_view_selector int * | packed_copyfrom_data * ; +* view_selector ::= copyfrom_source +* | copyfrom_target +* ; +* copyfrom_target ::= # binary 01 000000; * copyfrom_data ::= # binary 10 000000; +* packed_view_selector ::= # view_selector OR-ed with 6 bit value; * packed_copyfrom_data ::= # copyfrom_data OR-ed with 6 bit value; * int ::= highdigit* lowdigit; * highdigit ::= # binary 1000 0000 OR-ed with 7 bit value;
@@ -28,6 +33,7 @@*/ #define INSN_MASK 0xc0 +#define INSN_COPYFROM_TARGET 0x40#define INSN_COPYFROM_DATA 0x80#define OPERAND_MASK 0x3f
@@ -138,6 +144,21 @@ static int read_chunk(struct line_buffer *delta, off_t *delta_len,return 0 ; } +static int copyfrom_target (struct window *ctx,const char **instructions, +size_t nbytes,const char *insns_end) +{ +size_t offset; +if (parse_int (instructions, &offset, insns_end)) +return -1 ; +if (offset >= ctx->out.len) +return error ("Invalid delta: copies from the future." ); +while (nbytes) { +strbuf_addch (&ctx->out, ctx->out.buf[offset++]); + nbytes--; + } +return 0 ; +} +static int copyfrom_data (struct window *ctx,size_t *data_pos,size_t nbytes) {const size_t pos = *data_pos;
@@ -171,9 +192,14 @@ static int step(struct window *ctx, const char **instructions, size_t *data_pos) instruction = (unsigned char ) **instructions;if (parse_first_operand (instructions, &nbytes, insns_end))return -1 ; -if ((instruction &INSN_MASK ) !=INSN_COPYFROM_DATA ) +switch (instruction &INSN_MASK ) { +case INSN_COPYFROM_TARGET : +return copyfrom_target (ctx, instructions, nbytes, insns_end); +case INSN_COPYFROM_DATA : +return copyfrom_data (ctx, data_pos, nbytes); +default :return error ("Unknown instruction %x" , instruction); -return copyfrom_data (ctx, data_pos, nbytes); + } }static int apply_window_in_core (struct window *ctx)
Signature · 1 line
1.7.2.3
PATCH 10/11 vcs-svn: Reject deltas that read past end of preimage
In reply to Jonathan NiederSome particularly strange deltas of unknown origin were found to request copies beyond the end of the preimage. But svn 1.6 never produces anything like that.
Although Subversion accepts these perverse deltas as input, let's error out if some future version of subversion starts to actually produce them.
Without this change, the diff applier would have to separately keep track of the number of bytes supposedly and actually written out.
--- t/t9011-svn-da.sh | 11 ++++------- vcs-svn/sliding_window.c | 10 ++++++---- 2 files changed, 10 insertions(+), 11 deletions(-)
t/t9011-svn-da.sh +4 -7
@@ -105,16 +105,13 @@ test_expect_success 'preimage view: offsets compared by value' ' test_cmp empty actual ' -test_expect_success 'preimage view: accept truncated preimage' ' +test_expect_success 'preimage view: reject truncated preimage' ' printf "SVNQ%b" "\010QQQQ" | q_to_nul >clear.lateemptyread && printf "SVNQ%b" "\010\001QQQ" | q_to_nul >clear.latenonemptyread && printf "SVNQ%b" "\001\010QQQ" | q_to_nul >clear.longread && - test-svn-fe -d preimage clear.lateemptyread 9 >actual.emptyread && - test-svn-fe -d preimage clear.latenonemptyread 9 >actual.nonemptyread && - test-svn-fe -d preimage clear.longread 9 >actual.longread && - test_cmp empty actual.emptyread && - test_cmp empty actual.nonemptyread && - test_cmp empty actual.longread + test_must_fail test-svn-fe -d preimage clear.lateemptyread 9 && + test_must_fail test-svn-fe -d preimage clear.latenonemptyread 9 && + test_must_fail test-svn-fe -d preimage clear.longread 9 ' test_expect_success 'unconsumed inline data' '
vcs-svn/sliding_window.c +6 -4
@@ -49,17 +49,19 @@ int move_window(struct view *view, off_t off, size_t len)const off_t gap = off - file_offset;const off_t nread =buffer_skip_bytes (view->file, gap);if (nread != gap) { -if (!buffer_ferror (view->file))/* View ends early. */ - goto done; +if (!buffer_ferror (view->file)) +return error ("Preimage ends early" );return error ("Cannot seek forward in input: %s" ,strerror (errno)); } file_offset += gap; }buffer_read_binary (&view->buf, len - view->buf.len, view->file); -if (buffer_ferror (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)); - done: + } view->off = off;return 0 ; }
Signature · 1 line
1.7.2.3
PATCH 11/11 vcs-svn: Allow deltas to copy from preimage
In reply to Jonathan NiederThe copyfrom_source instruction appends data from the preimage buffer to the end of output. Its arguments are a length and an offset relative to the beginning of the source view.
---
That's the end of the series. Thanks for reading. Hopefully this round did not introduce too many bugs but if it did, I'd be glad to hear about them.
Good night,
Jonathan
t/t9011-svn-da.sh | 35 +++++++++++++++++++++++++++++++++++ vcs-svn/svndiff.c | 27 +++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 4 deletions(-)
t/t9011-svn-da.sh +35 -0
@@ -198,4 +198,39 @@ test_expect_success 'catch copy that overflows' ' test_must_fail test-svn-fe -d preimage copytarget.overflow $len ' +test_expect_success 'copyfrom source' ' + printf foo >expect && + printf "SVNQ%b%b" "Q\003\003\002Q" "\003Q" | q_to_nul >copysource.all && + test-svn-fe -d preimage copysource.all 11 >actual && + test_cmp expect actual +' + +test_expect_success 'copy backwards' ' + printf oof >expect && + printf "SVNQ%b%b" "Q\003\003\006Q" "\001\002\001\001\001Q" | + q_to_nul >copysource.rev && + test-svn-fe -d preimage copysource.rev 15 >actual && + test_cmp expect actual +' + +test_expect_success 'offsets are relative to window' ' + printf fo >expect && + printf "SVNQ%b%b%b%b" "Q\003\001\002Q" "\001Q" \ + "\002\001\001\002Q" "\001Q" | + q_to_nul >copysource.two && + test-svn-fe -d preimage copysource.two 18 >actual && + test_cmp expect actual +' + +test_expect_success 'example from notes/svndiff' ' + printf aaaaccccdddddddd >expect && + printf aaaabbbbcccc >source && + printf "SVNQ%b%b%s" "Q\014\020\007\001" \ + "\004Q\004\010\0201\0107\010" d | + q_to_nul >delta.example && + len=$(wc -c <delta.example) && + test-svn-fe -d source delta.example $len >actual && + test_cmp expect actual +' + test_done
vcs-svn/svndiff.c +23 -4
@@ -23,6 +23,7 @@* view_selector ::= copyfrom_source * | copyfrom_target * ; +* copyfrom_source ::= # binary 00 000000; * copyfrom_target ::= # binary 01 000000; * copyfrom_data ::= # binary 10 000000; * packed_view_selector ::= # view_selector OR-ed with 6 bit value;
@@ -33,6 +34,7 @@*/ #define INSN_MASK 0xc0 +#define INSN_COPYFROM_SOURCE 0x00#define INSN_COPYFROM_TARGET 0x40#define INSN_COPYFROM_DATA 0x80#define OPERAND_MASK 0x3f
@@ -42,6 +44,7 @@#define VLI_BITS_PER_DIGIT 7struct window { +struct view *in;struct strbuf out;struct strbuf instructions;struct strbuf data;
@@ -144,6 +147,19 @@ static int read_chunk(struct line_buffer *delta, off_t *delta_len,return 0 ; } +static int copyfrom_source (struct window *ctx,const char **instructions, +size_t nbytes,const char *insns_end) +{ +size_t offset; +if (parse_int (instructions, &offset, insns_end)) +return -1 ; +if (unsigned_add_overflows (offset, nbytes) || + offset + nbytes > ctx->in->buf.len) +return error ("Invalid delta: copies source data outside view." ); +strbuf_add (&ctx->out, ctx->in->buf.buf + offset, nbytes); +return 0 ; +} +static int copyfrom_target (struct window *ctx,const char **instructions,size_t nbytes,const char *insns_end) {
@@ -193,12 +209,14 @@ static int step(struct window *ctx, const char **instructions, size_t *data_pos)if (parse_first_operand (instructions, &nbytes, insns_end))return -1 ;switch (instruction &INSN_MASK ) { +case INSN_COPYFROM_SOURCE : +return copyfrom_source (ctx, instructions, nbytes, insns_end);case INSN_COPYFROM_TARGET :return copyfrom_target (ctx, instructions, nbytes, insns_end);case INSN_COPYFROM_DATA :return copyfrom_data (ctx, data_pos, nbytes);default : -return error ("Unknown instruction %x" , instruction); +return error ("Invalid instruction %x" , instruction); } }
@@ -220,9 +238,9 @@ static int apply_window_in_core(struct window *ctx) }static int apply_one_window (struct line_buffer *delta,off_t *delta_len, -FILE *out) +struct view *preimage,FILE *out) { -struct window ctx = {STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT }; +struct window ctx = {preimage,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT };size_t out_len;size_t instructions_len;size_t data_len;
@@ -277,7 +295,8 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,if (read_offset (delta, &pre_off, &delta_len) ||read_length (delta, &pre_len, &delta_len) ||move_window (&preimage_view, pre_off, pre_len) || -apply_one_window (delta, &delta_len, postimage)) +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)",
Signature · 1 line
1.7.2.3
PATCH 11/11 vcs-svn: Allow deltas to copy from preimage
In reply to Jonathan NiederThe copyfrom_source instruction appends data from the preimage buffer to the end of output. Its arguments are a length and an offset relative to the beginning of the source view.
---
[resending with cc: samv]
That's the end of the series. Thanks for reading. Hopefully this round did not introduce too many bugs but if it did, I'd be glad to hear about them.
Good night,
Jonathan
t/t9011-svn-da.sh | 35 +++++++++++++++++++++++++++++++++++ vcs-svn/svndiff.c | 27 +++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 4 deletions(-)
t/t9011-svn-da.sh +35 -0
@@ -198,4 +198,39 @@ test_expect_success 'catch copy that overflows' ' test_must_fail test-svn-fe -d preimage copytarget.overflow $len ' +test_expect_success 'copyfrom source' ' + printf foo >expect && + printf "SVNQ%b%b" "Q\003\003\002Q" "\003Q" | q_to_nul >copysource.all && + test-svn-fe -d preimage copysource.all 11 >actual && + test_cmp expect actual +' + +test_expect_success 'copy backwards' ' + printf oof >expect && + printf "SVNQ%b%b" "Q\003\003\006Q" "\001\002\001\001\001Q" | + q_to_nul >copysource.rev && + test-svn-fe -d preimage copysource.rev 15 >actual && + test_cmp expect actual +' + +test_expect_success 'offsets are relative to window' ' + printf fo >expect && + printf "SVNQ%b%b%b%b" "Q\003\001\002Q" "\001Q" \ + "\002\001\001\002Q" "\001Q" | + q_to_nul >copysource.two && + test-svn-fe -d preimage copysource.two 18 >actual && + test_cmp expect actual +' + +test_expect_success 'example from notes/svndiff' ' + printf aaaaccccdddddddd >expect && + printf aaaabbbbcccc >source && + printf "SVNQ%b%b%s" "Q\014\020\007\001" \ + "\004Q\004\010\0201\0107\010" d | + q_to_nul >delta.example && + len=$(wc -c <delta.example) && + test-svn-fe -d source delta.example $len >actual && + test_cmp expect actual +' + test_done
vcs-svn/svndiff.c +23 -4
@@ -23,6 +23,7 @@* view_selector ::= copyfrom_source * | copyfrom_target * ; +* copyfrom_source ::= # binary 00 000000; * copyfrom_target ::= # binary 01 000000; * copyfrom_data ::= # binary 10 000000; * packed_view_selector ::= # view_selector OR-ed with 6 bit value;
@@ -33,6 +34,7 @@*/ #define INSN_MASK 0xc0 +#define INSN_COPYFROM_SOURCE 0x00#define INSN_COPYFROM_TARGET 0x40#define INSN_COPYFROM_DATA 0x80#define OPERAND_MASK 0x3f
@@ -42,6 +44,7 @@#define VLI_BITS_PER_DIGIT 7struct window { +struct view *in;struct strbuf out;struct strbuf instructions;struct strbuf data;
@@ -144,6 +147,19 @@ static int read_chunk(struct line_buffer *delta, off_t *delta_len,return 0 ; } +static int copyfrom_source (struct window *ctx,const char **instructions, +size_t nbytes,const char *insns_end) +{ +size_t offset; +if (parse_int (instructions, &offset, insns_end)) +return -1 ; +if (unsigned_add_overflows (offset, nbytes) || + offset + nbytes > ctx->in->buf.len) +return error ("Invalid delta: copies source data outside view." ); +strbuf_add (&ctx->out, ctx->in->buf.buf + offset, nbytes); +return 0 ; +} +static int copyfrom_target (struct window *ctx,const char **instructions,size_t nbytes,const char *insns_end) {
@@ -193,12 +209,14 @@ static int step(struct window *ctx, const char **instructions, size_t *data_pos)if (parse_first_operand (instructions, &nbytes, insns_end))return -1 ;switch (instruction &INSN_MASK ) { +case INSN_COPYFROM_SOURCE : +return copyfrom_source (ctx, instructions, nbytes, insns_end);case INSN_COPYFROM_TARGET :return copyfrom_target (ctx, instructions, nbytes, insns_end);case INSN_COPYFROM_DATA :return copyfrom_data (ctx, data_pos, nbytes);default : -return error ("Unknown instruction %x" , instruction); +return error ("Invalid instruction %x" , instruction); } }
@@ -220,9 +238,9 @@ static int apply_window_in_core(struct window *ctx) }static int apply_one_window (struct line_buffer *delta,off_t *delta_len, -FILE *out) +struct view *preimage,FILE *out) { -struct window ctx = {STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT }; +struct window ctx = {preimage,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT };size_t out_len;size_t instructions_len;size_t data_len;
@@ -277,7 +295,8 @@ int svndiff0_apply(struct line_buffer *delta, off_t delta_len,if (read_offset (delta, &pre_off, &delta_len) ||read_length (delta, &pre_len, &delta_len) ||move_window (&preimage_view, pre_off, pre_len) || -apply_one_window (delta, &delta_len, postimage)) +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)",
Signature · 1 line
1.7.2.3
Re: [PATCH/RFC 0/11] Building up the delta parser
In reply to Jonathan NiederHi Jonathan,
Quoted 11 lines · Jonathan Nieder
Quoted 1 line · Jonathan Nieder
Implement an svndiff 0 interpreter
I hear that was nigh unreadable, so here's a reroll. Less cargo-cult support for broken deltas, more readability and tests. Patches apply on top of "[PATCH 15/16] t9010 (svn-fe): Eliminate dependency on svn perl bindings". As before, the end result includes a 'test-svn-fe -d' command that can apply svndiff0-format deltas, meaning less binary garbage to worry about as you puzzle over that confusing "svnrdump dump" output in debugging sessions.
Thanks for this! The code looks really good and the test suite is quite comprehensive :)
Eager to see this go through to master.
-- Ram
Re: [PATCH/RFC 0/11] Building up the delta parser
Quoted 4 lines · Ramkumar Ramachandra
Quoted 3 lines · Jonathan Nieder
Quoted 1 line · Jonathan Nieder
Implement an svndiff 0 interpreter
[...]
Quoted 1 line
Eager to see this go through to
master.
I think the strbuf use breaks the contrib/svn-fe/svn-fe build somewhere. Probably something like the following is needed.
(moving the -I flags off of the compilation command line is justa "while at it" thing, for consistency with the toplevel Makefile)
---
contrib/svn-fe/Makefile +2 -2
@@ -6,7 +6,7 @@ MV = mv CFLAGS = -g -O2 -Wall LDFLAGS = -ALL_CFLAGS = $(CFLAGS) +ALL_CFLAGS = $(CFLAGS) -I../../vcs-svn -I../.. ALL_LDFLAGS = $(LDFLAGS) EXTLIBS =
@@ -38,7 +38,7 @@ svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(GIT_LIB) $(ALL_LDFLAGS) $(LIBS) svn-fe.o: svn-fe.c ../../vcs-svn/svndump.h - $(QUIET_CC)$(CC) -I../../vcs-svn -o $*.o -c $(ALL_CFLAGS) $< + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $< svn-fe.html: svn-fe.txt $(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \