From 8df0552638c9a5fed216dff4aa2c8faba62b80f5 Mon Sep 17 00:00:00 2001 From: David Barr Date: Thu, 3 Jun 2010 22:19:48 +1000 Subject: [PATCH] Added an init phase to most modules. Derive outstanding state from persisted data structures. Mark only blobs and move mark counter to repo_tree.c Signed-off-by: David Barr --- fast_export.c | 2 +- repo_tree.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- repo_tree.h | 2 ++ string_pool.c | 10 ++++++++++ string_pool.h | 1 + svndump.c | 31 +++++++++++++++++-------------- 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/fast_export.c b/fast_export.c index ca4de52..dc17c54 100644 --- a/fast_export.c +++ b/fast_export.c @@ -35,7 +35,7 @@ void fast_export_commit(uint32_t revision, uint32_t author, char *log, } else { *gitsvnline = '\0'; } - printf("commit refs/heads/master\nmark :%d\n", revision); + printf("commit refs/heads/master\n"); printf("committer %s <%s@%s> %ld +0000\n", ~author ? pool_fetch(author) : "nobody", ~author ? pool_fetch(author) : "nobody", diff --git a/repo_tree.c b/repo_tree.c index 0b9901c..19e4edd 100644 --- a/repo_tree.c +++ b/repo_tree.c @@ -26,9 +26,15 @@ obj_pool_gen(commit, struct repo_commit, 4096); obj_pool_gen(dir, struct repo_dir, 4096); obj_pool_gen(dirent, struct repo_dirent, 4096); -static uint32_t num_dirs_saved = 0; +static uint32_t num_dirs_saved; static uint32_t num_dirents_saved; -static uint32_t active_commit = -1; +static uint32_t active_commit; +static uint32_t _mark; + +uint32_t next_blob_mark(void) +{ + return _mark++; +} static struct repo_dir *repo_commit_root_dir(struct repo_commit *commit) { @@ -296,13 +302,7 @@ void repo_diff(uint32_t r1, uint32_t r2) void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid, uint32_t url, time_t timestamp) { - if (revision == 0) { - active_commit = commit_alloc(1); - commit_pointer(active_commit)->root_dir_offset = - dir_with_dirents_alloc(0); - } else { - fast_export_commit(revision, author, log, uuid, url, timestamp); - } + fast_export_commit(revision, author, log, uuid, url, timestamp); num_dirs_saved = dir_pool.size; num_dirents_saved = dirent_pool.size; active_commit = commit_alloc(1); @@ -310,6 +310,40 @@ void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid, commit_pointer(active_commit - 1)->root_dir_offset; } +static void mark_init(void) +{ + uint32_t i; + _mark = 0; + for (i = 0; i < dirent_pool.size; i++) + if (!repo_dirent_is_dir(dirent_pointer(i)) && + dirent_pointer(i)->content_offset > _mark) + _mark = dirent_pointer(i)->content_offset; + _mark++; +} + +void repo_init() { + pool_init(); + commit_init(); + dir_init(); + dirent_init(); + mark_init(); + num_dirs_saved = dir_pool.size; + num_dirents_saved = dirent_pool.size; + active_commit = commit_pool.size - 1; + if (active_commit == -1) { + commit_alloc(2); + /* Create empty tree for commit 0. */ + commit_pointer(0)->root_dir_offset = + dir_with_dirents_alloc(0); + /* Preallocate commit 1, ready for changes. */ + commit_pointer(1)->root_dir_offset = + commit_pointer(0)->root_dir_offset; + active_commit = 1; + num_dirs_saved = dir_pool.size; + num_dirents_saved = dirent_pool.size; + } +} + void repo_reset(void) { pool_reset(); diff --git a/repo_tree.h b/repo_tree.h index c18cb73..46fc5bc 100644 --- a/repo_tree.h +++ b/repo_tree.h @@ -12,6 +12,7 @@ #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); @@ -20,6 +21,7 @@ void repo_delete(uint32_t *path); void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid, uint32_t url, time_t timestamp); void repo_diff(uint32_t r1, uint32_t r2); +void repo_init(void); void repo_reset(void); #endif diff --git a/string_pool.c b/string_pool.c index 0d41418..49908ca 100644 --- a/string_pool.c +++ b/string_pool.c @@ -94,6 +94,16 @@ uint32_t pool_tok_seq(uint32_t max, uint32_t *seq, char *delim, char *str) return length; } +void pool_init(void) +{ + uint32_t node; + node_init(); + string_init(); + for (node = 0; node < node_pool.size; node++) { + tree_insert(&tree, node_pointer(node)); + } +} + void pool_reset(void) { node_reset(); diff --git a/string_pool.h b/string_pool.h index ac2ae22..d10bb58 100644 --- a/string_pool.h +++ b/string_pool.h @@ -9,6 +9,7 @@ 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_reset(void); #endif diff --git a/svndump.c b/svndump.c index ef7beaa..c03e634 100644 --- a/svndump.c +++ b/svndump.c @@ -30,8 +30,6 @@ #define LENGTH_UNKNOWN (~0) -#define BLOB_MARK_OFFSET 1000000000 - /* Create memory pool for log messages */ obj_pool_gen(log, char, 4096); @@ -112,12 +110,6 @@ static void init_keys(void) keys.content_length = pool_intern("Content-length"); } -static uint32_t next_blob_mark(void) -{ - static uint32_t mark = BLOB_MARK_OFFSET; - return mark++; -} - static void read_props(void) { struct tm tm; @@ -203,8 +195,9 @@ static void handle_node(void) static void handle_revision(void) { - repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log, dump_ctx.uuid, - dump_ctx.url, rev_ctx.timestamp); + if (rev_ctx.revision) + repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log, + dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp); } static void svndump_read(uint32_t url) @@ -282,6 +275,16 @@ static void svndump_read(uint32_t url) if (active_ctx != DUMP_CTX) handle_revision(); } +static void svndump_init(void) +{ + log_init(); + repo_init(); + reset_dump_ctx(~0); + reset_rev_ctx(0); + reset_node_ctx(NULL); + init_keys(); +} + static void svndump_reset(void) { log_reset(); @@ -294,8 +297,8 @@ static void svndump_reset(void) int main(int argc, char **argv) { - init_keys(); - svndump_read((argc > 1) ? pool_intern(argv[1]) : ~0); - svndump_reset(); - return 0; + svndump_init(); + svndump_read((argc > 1) ? pool_intern(argv[1]) : ~0); + svndump_reset(); + return 0; } -- 2.11.4.GIT