@matheusbsbs / matheus-bagliano / commits / 7c5817d3ba
Fork 0

vcs-svn: use strbuf for author, UUID, and URL

Use strbufs and strings instead of interned strings for values of rev, dump, and node fields that happen to be strings. After this change, the only remaining string_pool use is for paths in the repo_tree API and internals. Functional change: treat an empty author, UUID, or URL as none at all. So for example, in repos where the first revision has an empty svn:author property, the first rev will be treated as by "nobody" rather than by a person with empty name and email address created by prepending an @ sign to the repository UUID. Signed-off-by: David Barr <david.barr@cordelta.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>

David Barr committed Mar 22, 2011 at 17:52 UTC 7c5817d3ba111bb71a5d7e3c8526e0925f96c92d
5 files changed +43 -30
vcs-svn/fast_export.c
+7 -7
@@ -31,24 +31,24 @@ void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
31 }
32
33 static char gitsvnline[MAX_GITSVN_LINE_LEN];
34 -void fast_export_commit(uint32_t revision, uint32_t author, char *log,
35 - uint32_t uuid, uint32_t url,
34 +void fast_export_commit(uint32_t revision, const char *author, char *log,
35 + const char *uuid, const char *url,
36 unsigned long timestamp)
37 {
38 if (!log)
39 log = "";
40 - if (~uuid && ~url) {
40 + if (*uuid && *url) {
41 snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
42 "\n\ngit-svn-id: %s@%"PRIu32" %s\n",
43 - pool_fetch(url), revision, pool_fetch(uuid));
43 + url, revision, uuid);
44 } else {
45 *gitsvnline = '\0';
46 }
47 printf("commit refs/heads/master\n");
48 printf("committer %s <%s@%s> %ld +0000\n",
49 - ~author ? pool_fetch(author) : "nobody",
50 - ~author ? pool_fetch(author) : "nobody",
51 - ~uuid ? pool_fetch(uuid) : "local", timestamp);
49 + *author ? author : "nobody",
50 + *author ? author : "nobody",
51 + *uuid ? uuid : "local", timestamp);
52 printf("data %"PRIu32"\n%s%s\n",
53 (uint32_t) (strlen(log) + strlen(gitsvnline)),
54 log, gitsvnline);
vcs-svn/fast_export.h
+3 -2
@@ -6,8 +6,9 @@
6 void fast_export_delete(uint32_t depth, uint32_t *path);
7 void fast_export_modify(uint32_t depth, uint32_t *path, uint32_t mode,
8 uint32_t mark);
9 -void fast_export_commit(uint32_t revision, uint32_t author, char *log,
10 - uint32_t uuid, uint32_t url, unsigned long timestamp);
9 +void fast_export_commit(uint32_t revision, const char *author, char *log,
10 + const char *uuid, const char *url,
11 + unsigned long timestamp);
12 void fast_export_blob(uint32_t mode, uint32_t mark, uint32_t len,
13 struct line_buffer *input);
14
vcs-svn/repo_tree.c
+2 -2
@@ -278,8 +278,8 @@ void repo_diff(uint32_t r1, uint32_t r2)
278 repo_commit_root_dir(commit_pointer(r2)));
279 }
280
281 -void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid,
282 - uint32_t url, unsigned long timestamp)
281 +void repo_commit(uint32_t revision, const char *author, char *log,
282 + const char *uuid, const char *url, unsigned long timestamp)
283 {
284 fast_export_commit(revision, author, log, uuid, url, timestamp);
285 dent_commit();
vcs-svn/repo_tree.h
+3 -2
@@ -17,8 +17,9 @@ void repo_add(uint32_t *path, uint32_t mode, uint32_t blob_mark);
17 uint32_t repo_read_path(const uint32_t *path);
18 uint32_t repo_read_mode(const uint32_t *path);
19 void repo_delete(uint32_t *path);
20 -void repo_commit(uint32_t revision, uint32_t author, char *log, uint32_t uuid,
21 - uint32_t url, long unsigned timestamp);
20 +void repo_commit(uint32_t revision, const char *author,
21 + char *log, const char *uuid, const char *url,
22 + long unsigned timestamp);
23 void repo_diff(uint32_t r1, uint32_t r2);
24 void repo_init(void);
25 void repo_reset(void);
vcs-svn/svndump.c
+28 -17
@@ -36,13 +36,14 @@ static struct {
36 } node_ctx;
37
38 static struct {
39 - uint32_t revision, author;
39 + uint32_t revision;
40 unsigned long timestamp;
41 - struct strbuf log;
41 + struct strbuf log, author;
42 } rev_ctx;
43
44 static struct {
45 - uint32_t version, uuid, url;
45 + uint32_t version;
46 + struct strbuf uuid, url;
47 } dump_ctx;
48
49 static struct {
@@ -72,14 +73,16 @@ static void reset_rev_ctx(uint32_t revision)
73 rev_ctx.revision = revision;
74 rev_ctx.timestamp = 0;
75 strbuf_reset(&rev_ctx.log);
75 - rev_ctx.author = ~0;
76 + strbuf_reset(&rev_ctx.author);
77 }
78
78 -static void reset_dump_ctx(uint32_t url)
79 +static void reset_dump_ctx(const char *url)
80 {
80 - dump_ctx.url = url;
81 + strbuf_reset(&dump_ctx.url);
82 + if (url)
83 + strbuf_addstr(&dump_ctx.url, url);
84 dump_ctx.version = 1;
82 - dump_ctx.uuid = ~0;
85 + strbuf_reset(&dump_ctx.uuid);
86 }
87
88 static void init_keys(void)
@@ -114,7 +117,9 @@ static void handle_property(uint32_t key, const char *val, uint32_t len,
117 strbuf_reset(&rev_ctx.log);
118 strbuf_add(&rev_ctx.log, val, len);
119 } else if (key == keys.svn_author) {
117 - rev_ctx.author = pool_intern(val);
120 + strbuf_reset(&rev_ctx.author);
121 + if (val)
122 + strbuf_add(&rev_ctx.author, val, len);
123 } else if (key == keys.svn_date) {
124 if (!val)
125 die("invalid dump: unsets svn:date");
@@ -274,8 +279,9 @@ static void handle_node(void)
279 static void handle_revision(void)
280 {
281 if (rev_ctx.revision)
277 - repo_commit(rev_ctx.revision, rev_ctx.author, rev_ctx.log.buf,
278 - dump_ctx.uuid, dump_ctx.url, rev_ctx.timestamp);
282 + repo_commit(rev_ctx.revision, rev_ctx.author.buf,
283 + rev_ctx.log.buf, dump_ctx.uuid.buf, dump_ctx.url.buf,
284 + rev_ctx.timestamp);
285 }
286
287 void svndump_read(const char *url)
@@ -286,7 +292,7 @@ void svndump_read(const char *url)
292 uint32_t len;
293 uint32_t key;
294
289 - reset_dump_ctx(pool_intern(url));
295 + reset_dump_ctx(url);
296 while ((t = buffer_read_line(&input))) {
297 val = strstr(t, ": ");
298 if (!val)
@@ -301,7 +307,8 @@ void svndump_read(const char *url)
307 die("expected svn dump format version <= 3, found %"PRIu32,
308 dump_ctx.version);
309 } else if (key == keys.uuid) {
304 - dump_ctx.uuid = pool_intern(val);
310 + strbuf_reset(&dump_ctx.uuid);
311 + strbuf_addstr(&dump_ctx.uuid, val);
312 } else if (key == keys.revision_number) {
313 if (active_ctx == NODE_CTX)
314 handle_node();
@@ -378,8 +385,11 @@ int svndump_init(const char *filename)
385 if (buffer_init(&input, filename))
386 return error("cannot open %s: %s", filename, strerror(errno));
387 repo_init();
388 + strbuf_init(&dump_ctx.uuid, 4096);
389 + strbuf_init(&dump_ctx.url, 4096);
390 strbuf_init(&rev_ctx.log, 4096);
382 - reset_dump_ctx(~0);
391 + strbuf_init(&rev_ctx.author, 4096);
392 + reset_dump_ctx(NULL);
393 reset_rev_ctx(0);
394 reset_node_ctx(NULL);
395 init_keys();
@@ -389,7 +399,7 @@ int svndump_init(const char *filename)
399 void svndump_deinit(void)
400 {
401 repo_reset();
392 - reset_dump_ctx(~0);
402 + reset_dump_ctx(NULL);
403 reset_rev_ctx(0);
404 reset_node_ctx(NULL);
405 strbuf_release(&rev_ctx.log);
@@ -403,7 +413,8 @@ void svndump_reset(void)
413 {
414 buffer_reset(&input);
415 repo_reset();
406 - reset_dump_ctx(~0);
407 - reset_rev_ctx(0);
408 - reset_node_ctx(NULL);
416 + strbuf_release(&dump_ctx.uuid);
417 + strbuf_release(&dump_ctx.url);
418 + strbuf_release(&rev_ctx.log);
419 + strbuf_release(&rev_ctx.author);
420 }