From: Dmitry Ivankov <divanorama@gmail.com>
To: git@vger.kernel.org
Cc: Jonathan Nieder <jrnieder@gmail.com>,
David Barr <davidbarr@google.com>,
Ramkumar Ramachandra <artagnon@gmail.com>,
Dmitry Ivankov <divanorama@gmail.com>
Subject: [PATCH v2 06/11] vcs-svn: move commit parameters logic to svndump.c
Date: Wed, 13 Jul 2011 18:21:08 +0600 [thread overview]
Message-ID: <1310559673-5026-7-git-send-email-divanorama@gmail.com> (raw)
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 = ∅
- 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
next prev parent reply other threads:[~2011-07-13 12:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-13 12:21 [PATCH v2 00/11] vcs-svn,svn-fe add a couple of options Dmitry Ivankov
2011-07-13 12:21 ` [PATCH v2 01/11] svn-fe: add man target to Makefile Dmitry Ivankov
2011-07-24 12:52 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 02/11] test-svn-fe: use parse-options Dmitry Ivankov
2011-07-24 13:04 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 03/11] svn-fe: add EXTLIBS needed for parse-options Dmitry Ivankov
2011-07-24 13:14 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 04/11] svn-fe: add usage and unpositional arguments versions Dmitry Ivankov
2011-07-24 13:25 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 05/11] vcs-svn: move url parameter from _read to _init Dmitry Ivankov
2011-07-24 13:40 ` Jonathan Nieder
2011-07-13 12:21 ` Dmitry Ivankov [this message]
2011-07-24 13:58 ` [PATCH v2 06/11] vcs-svn: move commit parameters logic to svndump.c Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 07/11] vcs-svn,svn-fe: allow to specify dump destination ref Dmitry Ivankov
2011-07-25 8:57 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 08/11] vcs-svn,svn-fe: convert REPORT_FILENO to an option Dmitry Ivankov
2011-07-25 21:26 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 09/11] vcs-svn,svn-fe: allow to disable 'progress' lines Dmitry Ivankov
2011-07-13 12:21 ` [PATCH v2 10/11] vcs-svn,svn-fe: add --incremental option Dmitry Ivankov
2011-07-25 21:35 ` Jonathan Nieder
2011-07-13 12:21 ` [PATCH v2 11/11] vcs-svn,svn-fe: add an option to write svnrev notes Dmitry Ivankov
2011-07-25 21:39 ` Jonathan Nieder
2011-07-28 6:03 ` Dmitry Ivankov
2011-07-28 10:27 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1310559673-5026-7-git-send-email-divanorama@gmail.com \
--to=divanorama@gmail.com \
--cc=artagnon@gmail.com \
--cc=davidbarr@google.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).