Create a note for every imported commit containing svn metadata

To provide metadata from svn dumps for further processing, e.g. branch detection, attach a note to each imported commit that stores additional information. The notes are currently hard-coded in refs/notes/svn/revs. Currently the following lines from the svn dump are directly accumulated in the note. This can be refined as needed. - "Revision-number" - "Node-path" - "Node-kind" - "Node-action" - "Node-copyfrom-path" - "Node-copyfrom-rev" Signed-off-by: Florian Achleitner <florian.achleitner.2.6.31@gmail.com> Acked-by: David Michael Barr <b@rr-dav.id.au> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Florian Achleitner committed Sep 19, 2012 at 17:21 UTC a9a55613cb9b92e0dd65f8c4554fd7b562377a6e
3 files changed +33 -4
vcs-svn/fast_export.c
+12 -2
@@ -3,8 +3,7 @@
3 * See LICENSE for details.
4 */
5
6 -#include "git-compat-util.h"
7 -#include "strbuf.h"
6 +#include "cache.h"
7 #include "quote.h"
8 #include "fast_export.h"
9 #include "repo_tree.h"
@@ -68,6 +67,17 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
67 putchar('\n');
68 }
69
70 +void fast_export_begin_note(uint32_t revision, const char *author,
71 + const char *log, unsigned long timestamp)
72 +{
73 + size_t loglen = strlen(log);
74 + printf("commit refs/notes/svn/revs\n");
75 + printf("committer %s <%s@%s> %ld +0000\n", author, author, "local", timestamp);
76 + printf("data %"PRIuMAX"\n", (uintmax_t)loglen);
77 + fwrite(log, loglen, 1, stdout);
78 + fputc('\n', stdout);
79 +}
80 +
81 void fast_export_note(const char *committish, const char *dataref)
82 {
83 printf("N %s %s\n", dataref, committish);
vcs-svn/fast_export.h
+2
@@ -10,6 +10,8 @@ void fast_export_deinit(void);
10 void fast_export_delete(const char *path);
11 void fast_export_modify(const char *path, uint32_t mode, const char *dataref);
12 void fast_export_note(const char *committish, const char *dataref);
13 +void fast_export_begin_note(uint32_t revision, const char *author,
14 + const char *log, unsigned long timestamp);
15 void fast_export_begin_commit(uint32_t revision, const char *author,
16 const struct strbuf *log, const char *uuid,
17 const char *url, unsigned long timestamp, const char *local_ref);
vcs-svn/svndump.c
+19 -2
@@ -48,7 +48,7 @@ static struct {
48 static struct {
49 uint32_t revision;
50 unsigned long timestamp;
51 - struct strbuf log, author;
51 + struct strbuf log, author, note;
52 } rev_ctx;
53
54 static struct {
@@ -77,6 +77,7 @@ static void reset_rev_ctx(uint32_t revision)
77 rev_ctx.timestamp = 0;
78 strbuf_reset(&rev_ctx.log);
79 strbuf_reset(&rev_ctx.author);
80 + strbuf_reset(&rev_ctx.note);
81 }
82
83 static void reset_dump_ctx(const char *url)
@@ -310,8 +311,15 @@ static void begin_revision(const char *remote_ref)
311
312 static void end_revision(void)
313 {
313 - if (rev_ctx.revision)
314 + struct strbuf mark = STRBUF_INIT;
315 + if (rev_ctx.revision) {
316 fast_export_end_commit(rev_ctx.revision);
317 + fast_export_begin_note(rev_ctx.revision, "remote-svn",
318 + "Note created by remote-svn.", rev_ctx.timestamp);
319 + strbuf_addf(&mark, ":%"PRIu32, rev_ctx.revision);
320 + fast_export_note(mark.buf, "inline");
321 + fast_export_buf_to_data(&rev_ctx.note);
322 + }
323 }
324
325 void svndump_read(const char *url, const char *local_ref)
@@ -358,6 +366,7 @@ void svndump_read(const char *url, const char *local_ref)
366 end_revision();
367 active_ctx = REV_CTX;
368 reset_rev_ctx(atoi(val));
369 + strbuf_addf(&rev_ctx.note, "%s\n", t);
370 break;
371 case sizeof("Node-path"):
372 if (constcmp(t, "Node-"))
@@ -369,10 +378,12 @@ void svndump_read(const char *url, const char *local_ref)
378 begin_revision(local_ref);
379 active_ctx = NODE_CTX;
380 reset_node_ctx(val);
381 + strbuf_addf(&rev_ctx.note, "%s\n", t);
382 break;
383 }
384 if (constcmp(t + strlen("Node-"), "kind"))
385 continue;
386 + strbuf_addf(&rev_ctx.note, "%s\n", t);
387 if (!strcmp(val, "dir"))
388 node_ctx.type = REPO_MODE_DIR;
389 else if (!strcmp(val, "file"))
@@ -383,6 +394,7 @@ void svndump_read(const char *url, const char *local_ref)
394 case sizeof("Node-action"):
395 if (constcmp(t, "Node-action"))
396 continue;
397 + strbuf_addf(&rev_ctx.note, "%s\n", t);
398 if (!strcmp(val, "delete")) {
399 node_ctx.action = NODEACT_DELETE;
400 } else if (!strcmp(val, "add")) {
@@ -401,11 +413,13 @@ void svndump_read(const char *url, const char *local_ref)
413 continue;
414 strbuf_reset(&node_ctx.src);
415 strbuf_addstr(&node_ctx.src, val);
416 + strbuf_addf(&rev_ctx.note, "%s\n", t);
417 break;
418 case sizeof("Node-copyfrom-rev"):
419 if (constcmp(t, "Node-copyfrom-rev"))
420 continue;
421 node_ctx.srcRev = atoi(val);
422 + strbuf_addf(&rev_ctx.note, "%s\n", t);
423 break;
424 case sizeof("Text-content-length"):
425 if (constcmp(t, "Text") && constcmp(t, "Prop"))
@@ -475,6 +489,7 @@ static void init(int report_fd)
489 strbuf_init(&dump_ctx.url, 4096);
490 strbuf_init(&rev_ctx.log, 4096);
491 strbuf_init(&rev_ctx.author, 4096);
492 + strbuf_init(&rev_ctx.note, 4096);
493 strbuf_init(&node_ctx.src, 4096);
494 strbuf_init(&node_ctx.dst, 4096);
495 reset_dump_ctx(NULL);
@@ -506,6 +521,8 @@ void svndump_deinit(void)
521 reset_rev_ctx(0);
522 reset_node_ctx(NULL);
523 strbuf_release(&rev_ctx.log);
524 + strbuf_release(&rev_ctx.author);
525 + strbuf_release(&rev_ctx.note);
526 strbuf_release(&node_ctx.src);
527 strbuf_release(&node_ctx.dst);
528 if (buffer_deinit(&input))