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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
| Greg KH | [RFC] kobject and kset core changes and cleanups |
| david | Re: [PATCH 0/2] Kexec jump: The first step to kexec base hibernation |
| Greg Kroah-Hartman | [PATCH 004/196] Chinese: add translation of SubmittingPatches |
| Michael-Luke Jones | JFFS2 using 'private' zlib header (was [RFC] LZO de/compression support - take 6) |
git: | |
| Francis Moreau | Track /etc directory using Git |
| Shawn O. Pearce | libgit2 - a true git library |
| Jon Smirl | ! [rejected] master -> master (non-fast forward) |
| Alexander Gladysh | [Q] Encrypted GIT? |
| Nuno Magalhães | Can't scp, ssh is slow to authenticate. |
| GVG GVG | ssh_exchange_identification: Connection closed by remote host |
| Christopher Bianchi | How can i boot a bsd.rd from windows 2000 ? |
| Richard Stallman | Real men don't attack straw men |
| Eric W. Biederman | [PATCH 0/10] sysfs network namespace support |
| John P Poet | Realtek 8111C transmit timed out |
| KOSAKI Motohiro | [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin" |
| Jarek Poplawski | [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
