All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Jonathan Nieder <jrnieder@gmail.com>,
	David Barr <david.barr@cordelta.com>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/3] vcs-svn: Refactor dump_export code into dispatch table
Date: Tue,  1 Feb 2011 19:56:43 +0530	[thread overview]
Message-ID: <1296570403-9082-4-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1296570403-9082-1-git-send-email-artagnon@gmail.com>

Suggested-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 vcs-svn/dump_export.c |   89 +++++++++++++++++++++++++------------------------
 vcs-svn/dump_export.h |    6 ++-
 2 files changed, 49 insertions(+), 46 deletions(-)

diff --git a/vcs-svn/dump_export.c b/vcs-svn/dump_export.c
index 2b23f77..a8331fd 100644
--- a/vcs-svn/dump_export.c
+++ b/vcs-svn/dump_export.c
@@ -11,6 +11,48 @@
 
 static struct strbuf props;
 
+typedef void state_fn(void);
+
+static void Kfile   (void) { printf("Node-kind: file\n"); }
+static void Kdir    (void) { printf("Node-kind: dir\n"); }
+static void Achange (void) { printf("Node-action: change\n"); }
+static void Aadd    (void) { printf("Node-action: add\n"); }
+static void Adelete (void) { printf("Node-action: delete\n"); }
+static void Areplace(void) { printf("Node-action: replace\n"); }
+static void Pexec   (void) { strbuf_addf(&props, "K 14\nsvn:executable\nV 1\n*\n"); }
+static void Psym    (void) { strbuf_addf(&props, "K 11\nsvn:special\nV 1\n*\n"); }
+static void Pend    (void) { strbuf_add(&props, "PROPS-END\n", 10); }
+
+static void Nchange (void) { Kfile(); Achange(); }
+static void Nadd    (void) { Kfile(); Aadd(); }
+static void Nreplace(void) { Kfile(); Areplace(); }
+static void Echange (void) { Pexec(); Pend(); Kfile(); Achange(); }
+static void Eadd    (void) { Pexec(); Pend(); Kfile(); Aadd(); }
+static void Ereplace(void) { Pexec(); Pend(); Kfile(); Areplace(); }
+static void Schange (void) { Psym(); Pend(); Kfile(); Achange(); }
+static void Sadd    (void) { Psym(); Pend(); Kfile(); Aadd(); }
+static void Sreplace(void) { Psym(); Pend(); Kfile(); Areplace(); }
+static void Dchange (void) { Kdir(); Achange(); }
+static void Dadd    (void) { Kdir(); Aadd(); }
+static void Dreplace(void) { Kdir(); Areplace(); }
+
+static state_fn *const dispatch_table[NODE_KIND_COUNT][NODE_ACTION_COUNT] = {
+	/* NODE_KIND_UNKNOWN */
+	{abort, abort, abort, Adelete, abort},
+	/* NODE_KIND_NORMAL */
+	{abort, Nchange, Nadd, Adelete, Nreplace},
+	/* NODE_KIND_EXECUTABLE */
+	{abort, Echange, Eadd, Adelete, Ereplace},
+	/* NODE_KIND_SYMLINK */
+	{abort, Schange, Sadd, Adelete, Sreplace},
+	/* NODE_KIND_GITLINK */
+	{abort, abort, abort, abort, abort},
+	/* NODE_KIND_DIR */
+	{abort, Dchange, Dadd, Adelete, Dreplace},
+	/* NODE_KIND_SUBDIR */
+	{abort, abort, abort, abort, abort}
+};
+
 void dump_export_begin_rev(int revision, const char *revprops,
 			int prop_len)
 {
@@ -24,56 +66,15 @@ void dump_export_node(const char *path, enum node_kind kind,
 		enum node_action action, unsigned long text_len,
 		unsigned long copyfrom_rev, const char *copyfrom_path)
 {
-	int dump_props = 1; /* Boolean */
 	strbuf_reset(&props);
 	printf("Node-path: %s\n", path);
-	switch (kind) {
-	case NODE_KIND_NORMAL:
-		printf("Node-kind: file\n");
-		break;
-	case NODE_KIND_EXECUTABLE:
-		printf("Node-kind: file\n");
-		strbuf_addf(&props, "K 14\nsvn:executable\nV 1\n*\n");
-		break;
-	case NODE_KIND_SYMLINK:
-		printf("Node-kind: file\n");
-		strbuf_addf(&props, "K 11\nsvn:special\nV 1\n*\n");
-		break;
-	case NODE_KIND_GITLINK:
-		printf("Node-kind: file\n");
-		break;
-	case NODE_KIND_DIR:
-		printf("Node-kind: dir\n");
-		break;
-	case NODE_KIND_SUBDIR:
-		die("Unsupported: subdirectory");
-	default:
-		break;
-	}
-	strbuf_add(&props, "PROPS-END\n", 10);
+	dispatch_table[kind][action]();
 
-	switch (action) {
-	case NODE_ACTION_CHANGE:
-		printf("Node-action: change\n");
-		break;
-	case NODE_ACTION_ADD:
-		printf("Node-action: add\n");
-		break;
-	case NODE_ACTION_REPLACE:
-		printf("Node-action: replace\n");
-		break;
-	case NODE_ACTION_DELETE:
-		printf("Node-action: delete\n");
-		dump_props = 0;
-		break;
-	default:
-		break;
-	}
 	if (copyfrom_rev != SVN_INVALID_REV) {
 		printf("Node-copyfrom-rev: %lu\n", copyfrom_rev);
 		printf("Node-copyfrom-path: %s\n", copyfrom_path);
 	}
-	if (dump_props) {
+	if (props.len) {
 		printf("Prop-delta: false\n");
 		printf("Prop-content-length: %lu\n", props.len);
 	}
@@ -81,7 +82,7 @@ void dump_export_node(const char *path, enum node_kind kind,
 		printf("Text-delta: false\n");		
 		printf("Text-content-length: %lu\n", text_len);
 	}
-	if (text_len || dump_props) {
+	if (text_len || props.len) {
 		printf("Content-length: %lu\n\n", text_len + props.len);
 		printf("%s", props.buf);
 	}
diff --git a/vcs-svn/dump_export.h b/vcs-svn/dump_export.h
index e9f51a3..8265170 100644
--- a/vcs-svn/dump_export.h
+++ b/vcs-svn/dump_export.h
@@ -9,7 +9,8 @@ enum node_action {
 	NODE_ACTION_CHANGE,
 	NODE_ACTION_ADD,
 	NODE_ACTION_DELETE,
-	NODE_ACTION_REPLACE
+	NODE_ACTION_REPLACE,
+	NODE_ACTION_COUNT
 };
 
 enum node_kind {
@@ -19,7 +20,8 @@ enum node_kind {
 	NODE_KIND_SYMLINK,
 	NODE_KIND_GITLINK,
 	NODE_KIND_DIR,           /* SVN-specific */
-	NODE_KIND_SUBDIR
+	NODE_KIND_SUBDIR,
+	NODE_KIND_COUNT
 };
 
 void dump_export_begin_rev(int revision, const char *revprops, int prop_len);
-- 
1.7.4.rc1.7.g2cf08.dirty

  parent reply	other threads:[~2011-02-01 14:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-01 14:26 [PATCH v3 0/3] Towards a Git-to-SVN bridge Ramkumar Ramachandra
2011-02-01 14:26 ` [PATCH 1/3] vcs-svn: Introduce svnload, a dumpfile producer Ramkumar Ramachandra
2011-02-01 14:46   ` Erik Faye-Lund
2011-02-02  2:53     ` Ramkumar Ramachandra
2011-02-02 12:43       ` Erik Faye-Lund
2011-02-01 14:26 ` [PATCH 2/3] t9010-svn-fi: Add tests for svn-fi Ramkumar Ramachandra
2011-02-01 18:58   ` Jonathan Nieder
2011-02-02  2:49     ` Ramkumar Ramachandra
2011-02-02  3:18       ` Jonathan Nieder
2011-02-01 14:26 ` Ramkumar Ramachandra [this message]
2011-02-01 17:42   ` [PATCH 3/3] vcs-svn: Refactor dump_export code into dispatch table Jonathan Nieder
2011-02-01 21:29     ` Junio C Hamano
2011-02-02  2:56     ` Ramkumar Ramachandra

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=1296570403-9082-4-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=david.barr@cordelta.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=srabbelier@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.