1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-30 05:47:53 +01:00

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>
This commit is contained in:
David Barr 2011-03-22 10:49:50 +11:00 committed by Jonathan Nieder
parent c9d1c8ba05
commit dce33c9c18

View file

@ -11,8 +11,8 @@
#include "repo_tree.h" #include "repo_tree.h"
#include "fast_export.h" #include "fast_export.h"
#include "line_buffer.h" #include "line_buffer.h"
#include "obj_pool.h"
#include "string_pool.h" #include "string_pool.h"
#include "strbuf.h"
#define NODEACT_REPLACE 4 #define NODEACT_REPLACE 4
#define NODEACT_DELETE 3 #define NODEACT_DELETE 3
@ -27,20 +27,8 @@
#define LENGTH_UNKNOWN (~0) #define LENGTH_UNKNOWN (~0)
#define DATE_RFC2822_LEN 31 #define DATE_RFC2822_LEN 31
/* Create memory pool for log messages */
obj_pool_gen(log, char, 4096)
static struct line_buffer input = LINE_BUFFER_INIT; static struct line_buffer input = LINE_BUFFER_INIT;
static char *log_copy(uint32_t length, const char *log)
{
char *buffer;
log_free(log_pool.size);
buffer = log_pointer(log_alloc(length));
strncpy(buffer, log, length);
return buffer;
}
static struct { static struct {
uint32_t action, propLength, textLength, srcRev, type; uint32_t action, propLength, textLength, srcRev, type;
uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH]; uint32_t src[REPO_MAX_PATH_DEPTH], dst[REPO_MAX_PATH_DEPTH];
@ -50,7 +38,7 @@ static struct {
static struct { static struct {
uint32_t revision, author; uint32_t revision, author;
unsigned long timestamp; unsigned long timestamp;
char *log; struct strbuf log;
} rev_ctx; } rev_ctx;
static struct { static struct {
@ -83,7 +71,7 @@ static void reset_rev_ctx(uint32_t revision)
{ {
rev_ctx.revision = revision; rev_ctx.revision = revision;
rev_ctx.timestamp = 0; rev_ctx.timestamp = 0;
rev_ctx.log = NULL; strbuf_reset(&rev_ctx.log);
rev_ctx.author = ~0; rev_ctx.author = ~0;
} }
@ -123,8 +111,8 @@ static void handle_property(uint32_t key, const char *val, uint32_t len,
if (key == keys.svn_log) { if (key == keys.svn_log) {
if (!val) if (!val)
die("invalid dump: unsets svn:log"); die("invalid dump: unsets svn:log");
/* Value length excludes terminating nul. */ strbuf_reset(&rev_ctx.log);
rev_ctx.log = log_copy(len + 1, val); strbuf_add(&rev_ctx.log, val, len);
} else if (key == keys.svn_author) { } else if (key == keys.svn_author) {
rev_ctx.author = pool_intern(val); rev_ctx.author = pool_intern(val);
} else if (key == keys.svn_date) { } else if (key == keys.svn_date) {
@ -286,7 +274,7 @@ static void handle_node(void)
static void handle_revision(void) static void handle_revision(void)
{ {
if (rev_ctx.revision) if (rev_ctx.revision)
repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log, repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log.buf,
dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp); dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp);
} }
@ -390,6 +378,7 @@ int svndump_init(const char *filename)
if (buffer_init(&input, filename)) if (buffer_init(&input, filename))
return error("cannot open %s: %s", filename, strerror(errno)); return error("cannot open %s: %s", filename, strerror(errno));
repo_init(); repo_init();
strbuf_init(&rev_ctx.log, 4096);
reset_dump_ctx(~0); reset_dump_ctx(~0);
reset_rev_ctx(0); reset_rev_ctx(0);
reset_node_ctx(NULL); reset_node_ctx(NULL);
@ -399,11 +388,11 @@ int svndump_init(const char *filename)
void svndump_deinit(void) void svndump_deinit(void)
{ {
log_reset();
repo_reset(); repo_reset();
reset_dump_ctx(~0); reset_dump_ctx(~0);
reset_rev_ctx(0); reset_rev_ctx(0);
reset_node_ctx(NULL); reset_node_ctx(NULL);
strbuf_release(&rev_ctx.log);
if (buffer_deinit(&input)) if (buffer_deinit(&input))
fprintf(stderr, "Input error\n"); fprintf(stderr, "Input error\n");
if (ferror(stdout)) if (ferror(stdout))
@ -412,7 +401,6 @@ void svndump_deinit(void)
void svndump_reset(void) void svndump_reset(void)
{ {
log_reset();
buffer_reset(&input); buffer_reset(&input);
repo_reset(); repo_reset();
reset_dump_ctx(~0); reset_dump_ctx(~0);