From: Sverre Rabbelier <srabbelier@gmail.com>
To: Junio C Hamano <gitster@pobox.com>,
"Shawn O. Pearce" <spearce@spearce.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Git List <git@vger.kernel.org>,
Ian Clatworthy <ian.cla
Cc: Sverre Rabbelier <srabbelier@gmail.com>
Subject: [PATCH v7 5/6] fast-import: add option command
Date: Sun, 6 Sep 2009 16:35:47 +0200 [thread overview]
Message-ID: <1252247748-14507-6-git-send-email-srabbelier@gmail.com> (raw)
In-Reply-To: <1252247748-14507-5-git-send-email-srabbelier@gmail.com>
This allows the frontend to specify any of the supported options as
long as no non-option command has been given. This way the
user does not have to include any frontend-specific options, but
instead she can rely on the frontend to tell fast-import what it
needs.
Also factor out parsing of argv and have it execute when we reach the
first non-option command, or after all commands have been read and
no non-option command has been encountered.
Non-git options and unrecognised git options are ignored, although
unrecognised options on the commandline still result in an error.
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
Fixed a few style errors pointed out by Junio and ignore
unrecognised git options.
Documentation/git-fast-import.txt | 24 +++++++++++
fast-import.c | 81 ++++++++++++++++++++++++++++++------
2 files changed, 91 insertions(+), 14 deletions(-)
diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt
index 1e293f2..f1c94b4 100644
--- a/Documentation/git-fast-import.txt
+++ b/Documentation/git-fast-import.txt
@@ -307,6 +307,11 @@ and control the current import process. More detailed discussion
Require that fast-import supports the specified feature, or
abort if it does not.
+`option`::
+ Specify any of the options listed under OPTIONS to change
+ fast-import's behavior to suit the frontend's needs. This command
+ is optional and is not needed to perform an import.
+
`commit`
~~~~~~~~
Create or update a branch with a new commit, recording one logical
@@ -829,6 +834,25 @@ it does not.
The <feature> part of the command may be any string matching
[a-zA-Z-] and should be understood by a version of fast-import.
+`option`
+~~~~~~~~
+Processes the specified option so that git fast-import behaves in a
+way that suits the frontend's needs.
+Note that options specified by the frontend are overridden by any
+options the user may specify to git fast-import itself.
+
+....
+ 'option' SP <option> LF
+....
+
+The `<option>` part of the command may contain any of the options
+listed in the OPTIONS section, without the leading '--' and is
+treated in the same way.
+
+Option commands must be the first commands on the input (not counting
+feature commands), to give an option command after any non-option
+command is an error.
+
Crash Reports
-------------
If fast-import is supplied invalid input it will terminate with a
diff --git a/fast-import.c b/fast-import.c
index 9bf06a4..dcfb8fa 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -292,6 +292,8 @@ static unsigned long branch_load_count;
static int failure;
static FILE *pack_edges;
static unsigned int show_stats = 1;
+static int global_argc;
+static const char **global_argv;
/* Memory pools */
static size_t mem_pool_alloc = 2*1024*1024 - sizeof(struct mem_pool);
@@ -349,6 +351,10 @@ static struct recent_command *rc_free;
static unsigned int cmd_save = 100;
static uintmax_t next_mark;
static struct strbuf new_data = STRBUF_INIT;
+static int options_enabled;
+static int seen_non_option_command;
+
+static void parse_argv(void);
static void write_branch_report(FILE *rpt, struct branch *b)
{
@@ -1700,6 +1706,12 @@ static int read_next_command(void)
if (stdin_eof)
return EOF;
+ if (!seen_non_option_command
+ && prefixcmp(command_buf.buf, "feature ")
+ && prefixcmp(command_buf.buf, "option ")) {
+ parse_argv();
+ }
+
rc = rc_free;
if (rc)
rc_free = rc->next;
@@ -2423,7 +2435,7 @@ static void option_export_pack_edges(const char *edges)
die_errno("Cannot open '%s'", edges);
}
-static void parse_one_option(const char *option)
+static void parse_one_option(const char *option, int optional)
{
if (!prefixcmp(option, "date-format=")) {
option_date_format(option + 12);
@@ -2445,7 +2457,7 @@ static void parse_one_option(const char *option)
show_stats = 0;
} else if (!prefixcmp(option, "stats")) {
show_stats = 1;
- } else {
+ } else if (!optional) {
die("Unsupported option: %s", option);
}
}
@@ -2456,11 +2468,32 @@ static void parse_feature(void)
if (!prefixcmp(feature, "date-format=")) {
option_date_format(feature + 12);
+ } else if (!strcmp("git-options", feature)) {
+ options_enabled = 1;
} else {
die("This version of fast-import does not support feature %s.", feature);
}
}
+static void parse_option(void)
+{
+ char *option = command_buf.buf + 11;
+
+ if (!options_enabled)
+ die("Got option command '%s' before options feature'", option);
+
+ if (seen_non_option_command)
+ die("Got option command '%s' after non-option command", option);
+
+ /* ignore unknown options, instead of erroring */
+ parse_one_option(option, 1);
+}
+
+static void parse_nongit_option(void)
+{
+ /* do nothing */
+}
+
static int git_pack_config(const char *k, const char *v, void *cb)
{
if (!strcmp(k, "pack.depth")) {
@@ -2485,6 +2518,27 @@ static int git_pack_config(const char *k, const char *v, void *cb)
static const char fast_import_usage[] =
"git fast-import [--date-format=f] [--max-pack-size=n] [--depth=n] [--active-branches=n] [--export-marks=marks.file]";
+static void parse_argv(void)
+{
+ unsigned int i;
+
+ for (i = 1; i < global_argc; i++) {
+ const char *a = global_argv[i];
+
+ if (*a != '-' || !strcmp(a, "--"))
+ break;
+
+ /* error on unknown options */
+ parse_one_option(a + 2, 0);
+ }
+ if (i != global_argc)
+ usage(fast_import_usage);
+
+ seen_non_option_command = 1;
+ if (input_file)
+ read_marks();
+}
+
int main(int argc, const char **argv)
{
unsigned int i;
@@ -2503,18 +2557,8 @@ int main(int argc, const char **argv)
avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
marks = pool_calloc(1, sizeof(struct mark_set));
- for (i = 1; i < argc; i++) {
- const char *a = argv[i];
-
- if (*a != '-' || !strcmp(a, "--"))
- break;
-
- parse_one_option(a + 2);
- }
- if (i != argc)
- usage(fast_import_usage);
- if (input_file)
- read_marks();
+ global_argc = argc;
+ global_argv = argv;
rc_free = pool_alloc(cmd_save * sizeof(*rc_free));
for (i = 0; i < (cmd_save - 1); i++)
@@ -2539,9 +2583,18 @@ int main(int argc, const char **argv)
parse_progress();
else if (!prefixcmp(command_buf.buf, "feature "))
parse_feature();
+ else if (!prefixcmp(command_buf.buf, "option git "))
+ parse_option();
+ else if (!prefixcmp(command_buf.buf, "option "))
+ parse_nongit_option();
else
die("Unsupported command: %s", command_buf.buf);
}
+
+ /* argv hasn't been parsed yet, do so */
+ if (!seen_non_option_command)
+ parse_argv();
+
end_packfile();
dump_branches();
--
1.6.4.16.g72c66.dirty
next prev parent reply other threads:[~2009-09-06 14:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-06 14:35 [PATCH v7 0/6] fast-import: add new feature and option command Sverre Rabbelier
2009-09-06 14:35 ` [PATCH v7 1/6] fast-import: put option parsing code in separate functions Sverre Rabbelier
2009-09-06 14:35 ` [PATCH v7 2/6] fast-import: put marks reading in it's own function Sverre Rabbelier
2009-09-06 14:35 ` [PATCH v7 3/6] fast-import: add feature command Sverre Rabbelier
2009-09-06 14:35 ` [PATCH v7 4/6] fast-import: test the new " Sverre Rabbelier
2009-09-06 14:35 ` Sverre Rabbelier [this message]
2009-09-06 14:35 ` [PATCH v7 6/6] fast-import: test the new option command Sverre Rabbelier
2009-09-12 19:04 ` [PATCH v7 5/6] fast-import: add " Shawn O. Pearce
2009-09-12 19:40 ` Sverre Rabbelier
2009-09-12 18:52 ` [PATCH v7 4/6] fast-import: test the new feature command Shawn O. Pearce
2009-09-12 19:31 ` Sverre Rabbelier
2009-09-13 13:20 ` Miklos Vajna
2009-09-12 18:51 ` [PATCH v7 3/6] fast-import: add " Shawn O. Pearce
2009-09-12 19:43 ` Sverre Rabbelier
2009-09-12 18:47 ` [PATCH v7 2/6] fast-import: put marks reading in it's own function Shawn O. Pearce
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=1252247748-14507-6-git-send-email-srabbelier@gmail.com \
--to=srabbelier@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=spearce@spearce.org \
/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).