@matheusbsbs / matheus-bagliano / commits / dce33c9c18
Fork 0

vcs-svn: use strbuf for revision log

obj_pool is overkill for this application: all that is needed is a buffer that can resize from rev to rev to accomodate differently-sized strings. In the spirit of commit deadcef4 (2010-11-06), use a strbuf instead. This is a small step towards removing dependence on obj_pool.h. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

David Barr committed Mar 22, 2011 at 10:49 UTC dce33c9c18e2987da1fe8ade67d27057bcb80a67
1 file changed +8 -20
vcs-svn/svndump.c
+8 -20
@@ -11,8 +11,8 @@
11 #include "repo_tree.h"
12 #include "fast_export.h"
13 #include "line_buffer.h"
14 -#include "obj_pool.h"
14 #include "string_pool.h"
15 +#include "strbuf.h"
16
17 #define NODEACT_REPLACE 4
18 #define NODEACT_DELETE 3
@@ -27,20 +27,8 @@
27 #define LENGTH_UNKNOWN (~0)
28 #define DATE_RFC2822_LEN 31
29
30 -/* Create memory pool for log messages */
31 -obj_pool_gen(log, char, 4096)
32 -
30 static struct line_buffer input = LINE_BUFFER_INIT;
31
35 -static char *log_copy(uint32_t length, const char *log)
36 -{
37 - char *buffer;
38 - log_free(log_pool.size);
39 - buffer = log_pointer(log_alloc(length));
40 - strncpy(buffer, log, length);
41 - return buffer;
42 -}
43 -
32 static struct {
33 uint32_t action, propLength, textLength, srcRev, type;
34 uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
@@ -50,7 +38,7 @@ static struct {
38 static struct {
39 uint32_t revision, author;
40 unsigned long timestamp;
53 - char *log;
41 + struct strbuf log;
42 } rev_ctx;
43
44 static struct {
@@ -83,7 +71,7 @@ static void reset_rev_ctx(uint32_t revision)
71 {
72 rev_ctx.revision = revision;
73 rev_ctx.timestamp = 0;
86 - rev_ctx.log = NULL;
74 + strbuf_reset(&rev_ctx.log);
75 rev_ctx.author = ~0;
76 }
77
@@ -123,8 +111,8 @@ static void handle_property(uint32_t key, const char *val, uint32_t len,
111 if (key == keys.svn_log) {
112 if (!val)
113 die("invalid dump: unsets svn:log");
126 - /* Value length excludes terminating nul. */
127 - rev_ctx.log = log_copy(len + 1, val);
114 + strbuf_reset(&rev_ctx.log);
115 + strbuf_add(&rev_ctx.log, val, len);
116 } else if (key == keys.svn_author) {
117 rev_ctx.author = pool_intern(val);
118 } else if (key == keys.svn_date) {
@@ -286,7 +274,7 @@ static void handle_node(void)
274 static void handle_revision(void)
275 {
276 if (rev_ctx.revision)
289 - repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log,
277 + repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log.buf,
278 dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp);
279 }
280
@@ -390,6 +378,7 @@ int svndump_init(const char *filename)
378 if (buffer_init(&input, filename))
379 return error("cannot open %s: %s", filename, strerror(errno));
380 repo_init();
381 + strbuf_init(&rev_ctx.log, 4096);
382 reset_dump_ctx(~0);
383 reset_rev_ctx(0);
384 reset_node_ctx(NULL);
@@ -399,11 +388,11 @@ int svndump_init(const char *filename)
388
389 void svndump_deinit(void)
390 {
402 - log_reset();
391 repo_reset();
392 reset_dump_ctx(~0);
393 reset_rev_ctx(0);
394 reset_node_ctx(NULL);
395 + strbuf_release(&rev_ctx.log);
396 if (buffer_deinit(&input))
397 fprintf(stderr, "Input error\n");
398 if (ferror(stdout))
@@ -412,7 +401,6 @@ void svndump_deinit(void)
401
402 void svndump_reset(void)
403 {
415 - log_reset();
404 buffer_reset(&input);
405 repo_reset();
406 reset_dump_ctx(~0);