git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 06/11] vcs-svn: move commit parameters logic to svndump.c

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Jul 13, 2011, 12:21 UTC
Message-ID
<1310559673-5026-7-git-send-email-divanorama@gmail.com>
In-Reply-To
<1310559673-5026-1-git-send-email-divanorama@gmail.com>

fast_export.c had logic to set up commit ref, author name, email, parent commit, import mark and git-svn-id: line based on both it's own state (current import batch history) and the arguments passed.

Lift the decision on these parameters to the caller. This way it is easier to customize them. Move progress lines generation to the caller for the same reason.

Now fast_export doesn't have any internal state except the files set up in fast_export_init, so it doesn't rely on being passed commits sequentially and to one and the same branch. It operates just on a current commit. Which makes it possible to generate an incremental stream (if stream's first commit parent is set up properly by the caller) or maybe to generate a stream for multiple svn branches.

Also progress lines generation is lifted up to svndump.o. So further progress indication enhancements won't need to change fast_export.o api.

Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 vcs-svn/fast_export.c |   44 ++++++++++++++------------------------------
 vcs-svn/fast_export.h |    8 +++++---
 vcs-svn/svndump.c     |   30 ++++++++++++++++++++++++++----
 3 files changed, 45 insertions(+), 37 deletions(-)
diff --git a/vcs-svn/fast_export.c b/vcs-svn/fast_export.c
index 19d7c34..04001b8 100644
--- a/vcs-svn/fast_export.c
+++ b/vcs-svn/fast_export.c
@@ -13,9 +13,6 @@
 #include "sliding_window.h"
 #include "line_buffer.h"
 
-#define MAX_GITSVN_LINE_LEN 4096
-
-static uint32_t first_commit_done;
 static struct line_buffer postimage = LINE_BUFFER_INIT;
 static struct line_buffer report_buffer = LINE_BUFFER_INIT;
 
@@ -31,7 +28,6 @@ static int init_postimage(void)
 
 void fast_export_init(int fd)
 {
-	first_commit_done = 0;
 	if (buffer_fdinit(&report_buffer, fd))
 		die_errno("cannot read from file descriptor %d", fd);
 }
@@ -73,42 +69,30 @@ void fast_export_modify(const char *path, uint32_t mode, const char *dataref)
 	putchar('\n');
 }
 
-static char gitsvnline[MAX_GITSVN_LINE_LEN];
-void fast_export_begin_commit(uint32_t revision, const char *author,
-			const struct strbuf *log,
-			const char *uuid, const char *url,
-			unsigned long timestamp)
+void fast_export_begin_commit(uint32_t set_mark, const char *committer_name,
+			const char *committer_login, const char *committer_domain,
+			const struct strbuf *log, const char *gitsvnline,
+			unsigned long timestamp, uint32_t from_mark,
+			const char *dst_ref)
 {
-	static const struct strbuf empty = STRBUF_INIT;
-	if (!log)
-		log = &empty;
-	if (*uuid && *url) {
-		snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
-				"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
-				 url, revision, uuid);
-	} else {
-		*gitsvnline = '\0';
-	}
-	printf("commit refs/heads/master\n");
-	printf("mark :%"PRIu32"\n", revision);
+	if (!gitsvnline)
+		gitsvnline = "";
+	printf("commit %s\n", dst_ref);
+	if (set_mark)
+		printf("mark :%"PRIu32"\n", set_mark);
 	printf("committer %s <%s@%s> %ld +0000\n",
-		   *author ? author : "nobody",
-		   *author ? author : "nobody",
-		   *uuid ? uuid : "local", timestamp);
+		committer_name, committer_login, committer_domain,
+		timestamp);
 	printf("data %"PRIuMAX"\n",
 		(uintmax_t) (log->len + strlen(gitsvnline)));
 	fwrite(log->buf, log->len, 1, stdout);
 	printf("%s\n", gitsvnline);
-	if (!first_commit_done) {
-		if (revision > 1)
-			printf("from :%"PRIu32"\n", revision - 1);
-		first_commit_done = 1;
-	}
+	if (from_mark)
+		printf("from :%"PRIu32"\n", from_mark);
 }
 
 void fast_export_end_commit(uint32_t revision)
 {
-	printf("progress Imported commit %"PRIu32".\n\n", revision);
 }
 
 static void ls_from_rev(uint32_t rev, const char *path)
diff --git a/vcs-svn/fast_export.h b/vcs-svn/fast_export.h
index 43d05b6..6c1c2be 100644
--- a/vcs-svn/fast_export.h
+++ b/vcs-svn/fast_export.h
@@ -10,9 +10,11 @@ void fast_export_reset(void);
 
 void fast_export_delete(const char *path);
 void fast_export_modify(const char *path, uint32_t mode, const char *dataref);
-void fast_export_begin_commit(uint32_t revision, const char *author,
-			const struct strbuf *log, const char *uuid,
-			const char *url, unsigned long timestamp);
+void fast_export_begin_commit(uint32_t set_mark, const char *committer_name,
+			const char *committer_login, const char *committer_domain,
+			const struct strbuf *log, const char *gitsvnline,
+			unsigned long timestamp, uint32_t from_mark,
+			const char *dst_ref);
 void fast_export_end_commit(uint32_t revision);
 void fast_export_data(uint32_t mode, uint32_t len, struct line_buffer *input);
 void fast_export_blob_delta(uint32_t mode,
diff --git a/vcs-svn/svndump.c b/vcs-svn/svndump.c
index 60cccad..c58262a 100644
--- a/vcs-svn/svndump.c
+++ b/vcs-svn/svndump.c
@@ -37,6 +37,8 @@
 #define LENGTH_UNKNOWN (~0)
 #define DATE_RFC2822_LEN 31
 
+#define MAX_GITSVN_LINE_LEN 4096
+
 static struct line_buffer input = LINE_BUFFER_INIT;
 
 static struct {
@@ -54,6 +56,7 @@ static struct {
 static struct {
 	uint32_t version;
 	struct strbuf uuid, url;
+	int first_commit_done;
 } dump_ctx;
 
 static void reset_node_ctx(char *fname)
@@ -86,6 +89,7 @@ static void reset_dump_ctx(const char *url)
 		strbuf_addstr(&dump_ctx.url, url);
 	dump_ctx.version = 1;
 	strbuf_reset(&dump_ctx.uuid);
+	dump_ctx.first_commit_done = 0;
 }
 
 static void handle_property(const struct strbuf *key_buf,
@@ -299,19 +303,37 @@ static void handle_node(void)
 				node_ctx.textLength, &input);
 }
 
+static char gitsvnline[MAX_GITSVN_LINE_LEN];
 static void begin_revision(void)
 {
+	int from_mark;
+	const char *author;
+	const char *domain;
 	if (!rev_ctx.revision)	/* revision 0 gets no git commit. */
 		return;
-	fast_export_begin_commit(rev_ctx.revision, rev_ctx.author.buf,
-		&rev_ctx.log, dump_ctx.uuid.buf, dump_ctx.url.buf,
-		rev_ctx.timestamp);
+	if (*dump_ctx.uuid.buf && *dump_ctx.url.buf) {
+		snprintf(gitsvnline, MAX_GITSVN_LINE_LEN,
+				"\n\ngit-svn-id: %s@%"PRIu32" %s\n",
+				 dump_ctx.url.buf, rev_ctx.revision, dump_ctx.uuid.buf);
+	} else {
+		*gitsvnline = 0;
+	}
+	from_mark = dump_ctx.first_commit_done ? rev_ctx.revision - 1 : 0;
+	author = *rev_ctx.author.buf ? rev_ctx.author.buf : "nobody";
+	domain = *dump_ctx.uuid.buf ? dump_ctx.uuid.buf : "local";
+
+	fast_export_begin_commit(rev_ctx.revision, author, author, domain,
+		&rev_ctx.log, gitsvnline, rev_ctx.timestamp,
+		from_mark);
 }
 
 static void end_revision(void)
 {
-	if (rev_ctx.revision)
+	if (rev_ctx.revision) {
 		fast_export_end_commit(rev_ctx.revision);
+		printf("progress Imported commit %"PRIu32".\n\n", rev_ctx.revision);
+		dump_ctx.first_commit_done = 1;
+	}
 }
 
 void svndump_read(void)
-- 
1.7.3.4
Previous: Jonathan NiederNext: Jonathan Nieder
Message 12 of 24 in “vcs-svn,svn-fe add a couple of options”
  1. 00/11 vcs-svn,svn-fe add a couple of optionsDmitry Ivankov, Jul 13, 2011
  2. 01/11 svn-fe: add man target to MakefileDmitry Ivankov, Jul 13, 2011
  3. Jonathan NiederJul 24, 2011
  4. 02/11 test-svn-fe: use parse-optionsDmitry Ivankov, Jul 13, 2011
  5. Jonathan NiederJul 24, 2011
  6. 03/11 svn-fe: add EXTLIBS needed for parse-optionsDmitry Ivankov, Jul 13, 2011
  7. Jonathan NiederJul 24, 2011
  8. 04/11 svn-fe: add usage and unpositional arguments versionsDmitry Ivankov, Jul 13, 2011
  9. Jonathan NiederJul 24, 2011
  10. 05/11 vcs-svn: move url parameter from _read to _initDmitry Ivankov, Jul 13, 2011
  11. Jonathan NiederJul 24, 2011
  12. 06/11 vcs-svn: move commit parameters logic to svndump.cDmitry Ivankov, Jul 13, 2011
  13. Jonathan NiederJul 24, 2011
  14. 07/11 vcs-svn,svn-fe: allow to specify dump destination refDmitry Ivankov, Jul 13, 2011
  15. Jonathan NiederJul 25, 2011
  16. 08/11 vcs-svn,svn-fe: convert REPORT_FILENO to an optionDmitry Ivankov, Jul 13, 2011
  17. Jonathan NiederJul 25, 2011
  18. 09/11 vcs-svn,svn-fe: allow to disable 'progress' linesDmitry Ivankov, Jul 13, 2011
  19. 10/11 vcs-svn,svn-fe: add --incremental optionDmitry Ivankov, Jul 13, 2011
  20. Jonathan NiederJul 25, 2011
  21. 11/11 vcs-svn,svn-fe: add an option to write svnrev notesDmitry Ivankov, Jul 13, 2011
  22. Jonathan NiederJul 25, 2011
  23. Dmitry IvankovJul 28, 2011
  24. Jonathan NiederJul 28, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.