Suggested-by: Jonathan Nieder <jrnieder@xxxxxxxxx> Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html