From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/4] git-init: inject some sanity to the option parser
Date: Sat, 28 Feb 2009 16:03:40 -0800 [thread overview]
Message-ID: <1235865822-14625-2-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1235865822-14625-1-git-send-email-gitster@pobox.com>
The parsing loop was a mess full of side effects.
This commit separates the loop that parses and understand the options
given, and the part that makes side effects based on given options.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-init-db.c | 35 ++++++++++++++++++++++++-----------
1 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/builtin-init-db.c b/builtin-init-db.c
index ee3911f..9628803 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -377,27 +377,40 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
const char *git_dir;
const char *template_dir = NULL;
unsigned int flags = 0;
+ const char *shared_given = NULL;
+ int bare_given = 0;
int i;
- for (i = 1; i < argc; i++, argv++) {
- const char *arg = argv[1];
+ /* Parse without side effects that is hard to undo or unparse */
+ for (i = 1; i < argc; i++) {
+ const char *arg = argv[i];
if (!prefixcmp(arg, "--template="))
- template_dir = arg+11;
- else if (!strcmp(arg, "--bare")) {
- static char git_dir[PATH_MAX+1];
- is_bare_repository_cfg = 1;
- setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir,
- sizeof(git_dir)), 0);
- } else if (!strcmp(arg, "--shared"))
- init_shared_repository = PERM_GROUP;
+ template_dir = arg + 11;
+ else if (!strcmp(arg, "--bare"))
+ bare_given = 1;
+ else if (!strcmp(arg, "--shared"))
+ shared_given = "";
else if (!prefixcmp(arg, "--shared="))
- init_shared_repository = git_config_perm("arg", arg+9);
+ shared_given = arg + 9;
else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet"))
flags |= INIT_DB_QUIET;
else
usage(init_db_usage);
}
+ if (bare_given) {
+ static char git_dir[PATH_MAX+1];
+ is_bare_repository_cfg = 1;
+ setenv(GIT_DIR_ENVIRONMENT,
+ getcwd(git_dir, sizeof(git_dir)), 0);
+ }
+
+ if (shared_given)
+ init_shared_repository =
+ ((!*shared_given)
+ ? PERM_GROUP
+ : git_config_perm("arg", shared_given));
+
/*
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
* without --bare. Catch the error early.
--
1.6.2.rc2.99.g9f3bb
next prev parent reply other threads:[~2009-03-01 0:05 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-01 0:03 [PATCH 1/4] Refactor list of environment variables to be sanitized Junio C Hamano
2009-03-01 0:03 ` Junio C Hamano [this message]
2009-03-01 0:03 ` [PATCH 3/4] Add init-serve, the remote side of "git init --remote=host:path" Junio C Hamano
2009-03-01 0:03 ` [PATCH 4/4] " Junio C Hamano
2009-03-01 3:16 ` [PATCH 3/4] Add init-serve, the remote side of " Jeff King
2009-03-01 5:54 ` Junio C Hamano
2009-03-01 10:00 ` Jeff King
2009-03-01 17:04 ` Shawn O. Pearce
2009-03-03 6:50 ` Subject: [PATCH] Push to create Junio C Hamano
2009-03-03 7:09 ` Jay Soffian
2009-03-03 7:09 ` Jeff King
2009-03-03 7:37 ` Jay Soffian
2009-03-03 7:39 ` Jay Soffian
2009-03-03 7:56 ` Junio C Hamano
2009-03-03 8:02 ` Jay Soffian
2009-03-03 8:04 ` Junio C Hamano
2009-03-03 8:04 ` Junio C Hamano
2009-03-03 8:16 ` Jay Soffian
2009-03-03 8:23 ` Jeff King
2009-03-03 19:57 ` Jay Soffian
2009-03-04 5:42 ` Jeff King
2009-03-04 6:35 ` Junio C Hamano
2009-03-04 13:06 ` Jay Soffian
2009-03-03 7:55 ` Junio C Hamano
2009-03-03 8:06 ` Jeff King
2009-03-03 8:22 ` Junio C Hamano
2009-03-03 8:27 ` Jeff King
2009-03-03 8:30 ` Junio C Hamano
2009-03-03 8:41 ` Jay Soffian
2009-03-03 9:23 ` Theodore Tso
2009-03-03 10:39 ` Johannes Schindelin
2009-03-04 17:58 ` Theodore Tso
2009-03-06 1:37 ` Miles Bader
2009-03-03 18:41 ` Shawn O. Pearce
2009-03-04 8:32 ` [RFC/PATCH 1/2] improve missing repository error message Jeff King
2009-03-04 9:19 ` Matthieu Moy
2009-03-04 10:35 ` Jeff King
2009-03-04 18:57 ` Shawn O. Pearce
2009-03-05 10:36 ` Jeff King
2009-03-04 8:42 ` [RFC/PATCH 2/2] make remote hangup warnings more friendly Jeff King
2009-03-04 19:04 ` Shawn O. Pearce
2009-03-05 10:45 ` Jeff King
2009-03-03 21:08 ` Subject: [PATCH] Push to create Daniel Barkalow
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=1235865822-14625-2-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.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.