From: Michele Ballabio <barra_cuda@katamail.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/2] builtin-prune.c: fix object parsing and use parse_options()
Date: Mon, 24 Mar 2008 13:31:17 +0100 [thread overview]
Message-ID: <200803241331.17986.barra_cuda@katamail.com> (raw)
In-Reply-To: <alpine.LSU.1.00.0803232319130.4353@racer.site>
On Sunday 23 March 2008, Johannes Schindelin wrote:
> On Sun, 23 Mar 2008, Michele Ballabio wrote:
>
> > -static const char prune_usage[] = "git-prune [-n]";
> > +static const char * const prune_usage[] = {
> > + "git-prune [-n] [--expire <time>] [--] [<head>...]",
> > + NULL
> > +};
>
> As you already use parse-options, should this not be rather
>
> static const char * const prune_usage[] = {
> "git-prune [options] [--] [<commit>...]",
>
> Hmm?
Ok, but the usage string is quite short anyway... and other commands
show a similar quite detailed usage string. Not that I care strongly
about this, though.
> > +static int parse_opt_expire(const struct option *opt, const char *arg,
> > + int unset)
> > +{
> > + expire = approxidate(arg);
> > + return 0;
> > +}
>
> This would probably be a good candidate to live in parse-options.[ch], no?
Uhm, probably, yes. See the patch below.
> But yes, the patch is good!
Thank you.
-- >8 --
parse-options.c: introduce callback function for approxidate()
There are quite a few places that will need to call approxidate(),
when they'll adopt the parse-options system, so this patch adds the
function parse_opt_approxidate_cb(), to be used within
OPT_CALLBACK, and converts the only user so far.
Signed-off-by: Michele Ballabio <barra_cuda@katamail.com>
---
builtin-prune.c | 9 +--------
parse-options.c | 7 +++++++
parse-options.h | 2 ++
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/builtin-prune.c b/builtin-prune.c
index 7b3e15d..a5d6fe5 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -125,13 +125,6 @@ static void remove_temporary_files(void)
closedir(dir);
}
-static int parse_opt_expire(const struct option *opt, const char *arg,
- int unset)
-{
- expire = approxidate(arg);
- return 0;
-}
-
int cmd_prune(int argc, const char **argv, const char *prefix)
{
struct rev_info revs;
@@ -141,7 +134,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
"do not remove, show only"),
OPT_CALLBACK(0, "expire", &expire, "time",
"expire objects older than <time>",
- parse_opt_expire),
+ parse_opt_approxidate_cb),
OPT_END()
};
diff --git a/parse-options.c b/parse-options.c
index 8e64316..6ec7fe8 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -409,3 +409,10 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
*(int *)(opt->value) = v;
return 0;
}
+
+int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
+ int unset)
+{
+ *(unsigned int *)(opt->value) = approxidate(arg);
+ return 0;
+}
diff --git a/parse-options.h b/parse-options.h
index 1af62b0..e6976ed 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -110,6 +110,8 @@ extern NORETURN void usage_with_options(const char * const *usagestr,
/*----- some often used options -----*/
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
+extern int parse_opt_approxidate_cb(const struct option *, const char *,
+ int);
#define OPT__VERBOSE(var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")
#define OPT__QUIET(var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")
--
1.5.4.3
next prev parent reply other threads:[~2008-03-24 12:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-23 20:50 [PATCH 2/2] builtin-prune.c: fix object parsing and use parse_options() Michele Ballabio
2008-03-23 22:21 ` Johannes Schindelin
2008-03-24 12:31 ` Michele Ballabio [this message]
2008-03-24 13:13 ` Johannes Schindelin
2008-03-24 14:02 ` [PATCH 3/2] parse-options.c: introduce OPT_DATE Michele Ballabio
2008-03-24 13:59 ` Johannes Schindelin
2008-03-24 16:25 ` Michele Ballabio
2008-03-24 20:03 ` Johannes Schindelin
2008-03-24 20:10 ` Junio C Hamano
2008-03-24 21:18 ` Michele Ballabio
2008-03-25 6:58 ` Junio C Hamano
2008-03-25 6:59 ` [PATCH 1/5] " Junio C Hamano
2008-03-25 6:59 ` [PATCH 2/5] test_must_fail: 129 is a valid error code from usage() Junio C Hamano
2008-03-25 10:01 ` Johannes Schindelin
2008-03-25 11:21 ` Johannes Sixt
2008-03-25 19:27 ` Johannes Schindelin
2008-03-25 6:59 ` [PATCH 3/5] Add tests for git-prune Junio C Hamano
2008-03-25 6:59 ` [PATCH 4/5] builtin-prune.c: use parse_options() Junio C Hamano
2008-03-25 6:59 ` [PATCH 5/5] builtin-prune: protect objects listed on the command line Junio C Hamano
2008-03-27 16:32 ` Junio C Hamano
2008-03-27 16:35 ` Johannes Schindelin
2008-03-27 21:11 ` Michele Ballabio
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=200803241331.17986.barra_cuda@katamail.com \
--to=barra_cuda@katamail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).