All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: git@vger.kernel.org
Cc: torvalds@linux-foundation.org, gitster@pobox.com, peff@peff.net,
	Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 3/6] revisions: parse_revisions refactor.
Date: Tue,  8 Jul 2008 11:56:01 +0200	[thread overview]
Message-ID: <1215510964-16664-4-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <1215510964-16664-3-git-send-email-madcoder@debian.org>

Reorder parse_revisions so that it works more like a parse-opt based
parser would: use two pass, the first filtering out options that the
revision parser understands, and remember if we saw a "--", and then
parse revision arguments.

Once everyone is using a parse-opt parser, it will be possible to simplify
parse_revisions further. The first pass is a NOOP for incremental
parse-opt based parsers.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 revision.c |   63 ++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/revision.c b/revision.c
index a3792c9..87f89a2 100644
--- a/revision.c
+++ b/revision.c
@@ -1250,30 +1250,44 @@ int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
  */
 int parse_revisions(int argc, const char **argv, struct rev_info *revs)
 {
-	int i, flags, seen_dashdash;
-	const char **unrecognized = argv + 1;
-	int left = 1;
+	int i, left, flags;
+	int seen_dashdash = 0;
 
-	/* First, search for "--" */
-	seen_dashdash = 0;
-	for (i = 1; i < argc; i++) {
+	/* First, filter out revision options and look for "--" */
+	for (left = i = 1; i < argc; i++) {
 		const char *arg = argv[i];
-		if (strcmp(arg, "--"))
+		int opts;
+
+		if (arg[0] != '-') {
+			argv[left++] = arg;
 			continue;
-		argv[i] = NULL;
-		argc = i;
-		if (argv[i + 1])
-			revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
-		seen_dashdash = 1;
-		break;
+		}
+
+		if (!strcmp(arg, "--")) {
+			seen_dashdash = left;
+			memcpy(argv + left, argv + i, sizeof(*argv) * (argc - i));
+			left += argc - i;
+			break;
+		}
+
+		opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv);
+		if (opts > 0) {
+			i += opts - 1;
+			continue;
+		}
+		if (opts < 0)
+			exit(128);
+		argv[left++] = arg;
 	}
+	argv[left] = NULL;
+	argc = left;
 
+	/* Second, parse revisions arguments */
 	flags = 0;
-	for (i = 1; i < argc; i++) {
+	for (left = i = 1; i < argc; i++) {
 		const char *arg = argv[i];
-		if (*arg == '-') {
-			int opts;
 
+		if (*arg == '-') {
 			if (!strcmp(arg, "--all")) {
 				handle_refs(revs, flags, for_each_ref);
 				continue;
@@ -1306,16 +1320,15 @@ int parse_revisions(int argc, const char **argv, struct rev_info *revs)
 				revs->no_walk = 0;
 				continue;
 			}
-
-			opts = handle_revision_opt(revs, argc - i, argv + i, NULL, NULL);
-			if (opts > 0) {
-				i += opts - 1;
-				continue;
+			if (i == seen_dashdash) {
+				argv[i] = NULL;
+				argc = i;
+				if (argv[i + 1])
+					revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
+				break;
 			}
-			if (opts < 0)
-				exit(128);
-			*unrecognized++ = arg;
-			left++;
+
+			argv[left++] = arg;
 			continue;
 		}
 
-- 
1.5.6.2.352.g416a6

  reply	other threads:[~2008-07-08  9:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08  9:55 Migration of builtin-blame to parse-option Pierre Habouzit
2008-07-08  9:55 ` [PATCH 1/6] revisions: refactor init_revisions and setup_revisions Pierre Habouzit
2008-07-08  9:56   ` [PATCH 2/6] revisions: split the pure option parsing out from parse_revisions Pierre Habouzit
2008-07-08  9:56     ` Pierre Habouzit [this message]
2008-07-08  9:56       ` [PATCH 4/6] revisions: split handle_revision_args " Pierre Habouzit
2008-07-08  9:56         ` [PATCH 5/6] git-blame: migrate to incremental parse-option [1/2] Pierre Habouzit
2008-07-08  9:56           ` [PATCH 6/6] git-blame: migrate to incremental parse-option [2/2] Pierre Habouzit
2008-07-08 10:51     ` [PATCH 2/6] revisions: split the pure option parsing out from parse_revisions Johannes Sixt
2008-07-08 11:00       ` Pierre Habouzit
2008-07-08 11:25         ` Pierre Habouzit
2008-07-08 10:59   ` [PATCH 1/6] revisions: refactor init_revisions and setup_revisions Johannes Schindelin
2008-07-08 11:06     ` Pierre Habouzit
2008-07-08 11:43       ` Johannes Schindelin
2008-07-08 12:48         ` Pierre Habouzit
2008-07-08 10:02 ` Migration of builtin-blame to parse-option Pierre Habouzit

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=1215510964-16664-4-git-send-email-madcoder@debian.org \
    --to=madcoder@debian.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=torvalds@linux-foundation.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 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.