Skip to content

Commit a9a5561

Browse files
flyingflogitster
authored andcommitted
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 <[email protected]> Acked-by: David Michael Barr <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c23953 commit a9a5561

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

vcs-svn/fast_export.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* See LICENSE for details.
44
*/
55

6-
#include "git-compat-util.h"
7-
#include "strbuf.h"
6+
#include "cache.h"
87
#include "quote.h"
98
#include "fast_export.h"
109
#include "repo_tree.h"
@@ -68,6 +67,17 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
6867
putchar('\n');
6968
}
7069

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+
7181
void fast_export_note(const char *committish, const char *dataref)
7282
{
7383
printf("N %s %s\n", dataref, committish);

vcs-svn/fast_export.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ void fast_export_deinit(void);
1010
void fast_export_delete(const char *path);
1111
void fast_export_modify(const char *path, uint32_t mode, const char *dataref);
1212
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);
1315
void fast_export_begin_commit(uint32_t revision, const char *author,
1416
const struct strbuf *log, const char *uuid,
1517
const char *url, unsigned long timestamp, const char *local_ref);

vcs-svn/svndump.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static struct {
4848
static struct {
4949
uint32_t revision;
5050
unsigned long timestamp;
51-
struct strbuf log, author;
51+
struct strbuf log, author, note;
5252
} rev_ctx;
5353

5454
static struct {
@@ -77,6 +77,7 @@ static void reset_rev_ctx(uint32_t revision)
7777
rev_ctx.timestamp = 0;
7878
strbuf_reset(&rev_ctx.log);
7979
strbuf_reset(&rev_ctx.author);
80+
strbuf_reset(&rev_ctx.note);
8081
}
8182

8283
static void reset_dump_ctx(const char *url)
@@ -310,8 +311,15 @@ static void begin_revision(const char *remote_ref)
310311

311312
static void end_revision(void)
312313
{
313-
if (rev_ctx.revision)
314+
struct strbuf mark = STRBUF_INIT;
315+
if (rev_ctx.revision) {
314316
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+
}
315323
}
316324

317325
void svndump_read(const char *url, const char *local_ref)
@@ -358,6 +366,7 @@ void svndump_read(const char *url, const char *local_ref)
358366
end_revision();
359367
active_ctx = REV_CTX;
360368
reset_rev_ctx(atoi(val));
369+
strbuf_addf(&rev_ctx.note, "%s\n", t);
361370
break;
362371
case sizeof("Node-path"):
363372
if (constcmp(t, "Node-"))
@@ -369,10 +378,12 @@ void svndump_read(const char *url, const char *local_ref)
369378
begin_revision(local_ref);
370379
active_ctx = NODE_CTX;
371380
reset_node_ctx(val);
381+
strbuf_addf(&rev_ctx.note, "%s\n", t);
372382
break;
373383
}
374384
if (constcmp(t + strlen("Node-"), "kind"))
375385
continue;
386+
strbuf_addf(&rev_ctx.note, "%s\n", t);
376387
if (!strcmp(val, "dir"))
377388
node_ctx.type = REPO_MODE_DIR;
378389
else if (!strcmp(val, "file"))
@@ -383,6 +394,7 @@ void svndump_read(const char *url, const char *local_ref)
383394
case sizeof("Node-action"):
384395
if (constcmp(t, "Node-action"))
385396
continue;
397+
strbuf_addf(&rev_ctx.note, "%s\n", t);
386398
if (!strcmp(val, "delete")) {
387399
node_ctx.action = NODEACT_DELETE;
388400
} else if (!strcmp(val, "add")) {
@@ -401,11 +413,13 @@ void svndump_read(const char *url, const char *local_ref)
401413
continue;
402414
strbuf_reset(&node_ctx.src);
403415
strbuf_addstr(&node_ctx.src, val);
416+
strbuf_addf(&rev_ctx.note, "%s\n", t);
404417
break;
405418
case sizeof("Node-copyfrom-rev"):
406419
if (constcmp(t, "Node-copyfrom-rev"))
407420
continue;
408421
node_ctx.srcRev = atoi(val);
422+
strbuf_addf(&rev_ctx.note, "%s\n", t);
409423
break;
410424
case sizeof("Text-content-length"):
411425
if (constcmp(t, "Text") && constcmp(t, "Prop"))
@@ -475,6 +489,7 @@ static void init(int report_fd)
475489
strbuf_init(&dump_ctx.url, 4096);
476490
strbuf_init(&rev_ctx.log, 4096);
477491
strbuf_init(&rev_ctx.author, 4096);
492+
strbuf_init(&rev_ctx.note, 4096);
478493
strbuf_init(&node_ctx.src, 4096);
479494
strbuf_init(&node_ctx.dst, 4096);
480495
reset_dump_ctx(NULL);
@@ -506,6 +521,8 @@ void svndump_deinit(void)
506521
reset_rev_ctx(0);
507522
reset_node_ctx(NULL);
508523
strbuf_release(&rev_ctx.log);
524+
strbuf_release(&rev_ctx.author);
525+
strbuf_release(&rev_ctx.note);
509526
strbuf_release(&node_ctx.src);
510527
strbuf_release(&node_ctx.dst);
511528
if (buffer_deinit(&input))

0 commit comments

Comments
 (0)