From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Pierre Habouzit <madcoder@debian.org>
Cc: Shawn Bohrer <shawn.bohrer@gmail.com>,
git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 3/2] Use parse-options in builtin-clean
Date: Sun, 4 Nov 2007 20:24:31 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.64.0711042023440.4362@racer.site> (raw)
In-Reply-To: <20071104194129.GA4207@artemis.corp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
On Sun, 4 Nov 2007, Pierre Habouzit wrote:
> On Sun, Nov 04, 2007 at 07:02:21PM +0000, Shawn Bohrer wrote:
>
> > + for (i = 1; i < argc; i++) {
> > + const char *arg = argv[i];
> > [...]
>
> Please, parse-options.c is now in next, please use it.
Something like this?
builtin-clean.c | 71 ++++++++++++++++++++----------------------------------
1 files changed, 26 insertions(+), 45 deletions(-)
diff --git a/builtin-clean.c b/builtin-clean.c
index 4141eb4..d6fc2ad 100644
--- a/builtin-clean.c
+++ b/builtin-clean.c
@@ -9,81 +9,62 @@
#include "builtin.h"
#include "cache.h"
#include "dir.h"
+#include "parse-options.h"
-static int disabled = 1;
+static int force = 0;
static int show_only = 0;
static int remove_directories = 0;
static int quiet = 0;
static int ignored = 0;
static int ignored_only = 0;
-static const char builtin_clean_usage[] =
-"git-clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...";
+static const char *const builtin_clean_usage[] = {
+ "git-clean [-d] [-f] [-n] [-q] [-x | -X] [--] <paths>...",
+ NULL
+};
static int git_clean_config(const char *var, const char *value)
{
if (!strcmp(var, "clean.requireforce")) {
- disabled = git_config_bool(var, value);
+ force = !git_config_bool(var, value);
}
return 0;
}
int cmd_clean(int argc, const char **argv, const char *prefix)
{
- int i, j;
+ int j;
struct strbuf directory;
struct dir_struct dir;
const char *path = ".";
const char *base = "";
int baselen = 0;
static const char **pathspec;
+ struct option options[] = {
+ OPT__QUIET(&quiet),
+ OPT__DRY_RUN(&show_only),
+ OPT_BOOLEAN('f', NULL, &force, "force"),
+ OPT_BOOLEAN('d', NULL, &remove_directories,
+ "remove whole directories"),
+ OPT_BOOLEAN('x', NULL, &ignored, "remove ignored files, too"),
+ OPT_BOOLEAN('X', NULL, &ignored_only,
+ "remove only ignored files"),
+ OPT_END()
+ };
- memset(&dir, 0, sizeof(dir));
git_config(git_clean_config);
+ argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
-
- if (arg[0] != '-')
- break;
- if (!strcmp(arg, "--")) {
- i++;
- break;
- }
- if (!strcmp(arg, "-n")) {
- show_only = 1;
- disabled = 0;
- continue;
- }
- if (!strcmp(arg, "-f")) {
- disabled = 0;
- continue;
- }
- if (!strcmp(arg, "-d")) {
- remove_directories = 1;
- continue;
- }
- if (!strcmp(arg, "-q")) {
- quiet = 1;
- continue;
- }
- if (!strcmp(arg, "-x")) {
- ignored = 1;
- continue;
- }
- if (!strcmp(arg, "-X")) {
- ignored_only = 1;
- dir.show_ignored =1;
- dir.exclude_per_dir = ".gitignore";
- continue;
- }
- usage(builtin_clean_usage);
+ memset(&dir, 0, sizeof(dir));
+ if (ignored_only) {
+ dir.show_ignored =1;
+ dir.exclude_per_dir = ".gitignore";
}
if (ignored && ignored_only)
die("-x and -X cannot be used together");
- if (disabled)
+ if (!show_only && !force)
die("clean.requireForce set and -n or -f not given; refusing to clean");
dir.show_other_directories = 1;
@@ -96,7 +77,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
}
}
- pathspec = get_pathspec(prefix, argv + i);
+ pathspec = get_pathspec(prefix, argv);
read_cache();
read_directory(&dir, path, base, baselen, pathspec);
strbuf_init(&directory, 0);
--
1.5.3.5.1549.g91a3
next prev parent reply other threads:[~2007-11-04 20:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-04 19:02 [RFC] Second attempt at making git-clean a builtin Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Add more tests for git-clean Shawn Bohrer
2007-11-04 19:02 ` [PATCH] Make git-clean a builtin Shawn Bohrer
2007-11-04 19:41 ` Pierre Habouzit
2007-11-04 20:24 ` Johannes Schindelin [this message]
2007-11-04 21:16 ` [PATCH 3/2] Use parse-options in builtin-clean Pierre Habouzit
2007-11-05 21:14 ` [PATCH] Make git-clean a builtin Junio C Hamano
2007-11-05 22:10 ` Carlos Rica
2007-11-05 23:54 ` Junio C Hamano
2007-11-06 5:05 ` Shawn Bohrer
2007-11-06 5:30 ` Junio C Hamano
2007-11-04 23:35 ` [PATCH] Add more tests for git-clean Junio C Hamano
2007-11-04 23:46 ` Pierre Habouzit
2007-11-05 0:17 ` Junio C Hamano
2007-11-04 23:49 ` Johannes Schindelin
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=Pine.LNX.4.64.0711042023440.4362@racer.site \
--to=johannes.schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madcoder@debian.org \
--cc=shawn.bohrer@gmail.com \
/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).