git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] builtin-prune.c: fix object parsing and use parse_options()

From
Michele Ballabio <barra_cuda@katamail.com>
Date
Mar 24, 2008, 12:31 UTC
Message-ID
<200803241331.17986.barra_cuda@katamail.com>
In-Reply-To
<alpine.LSU.1.00.0803232319130.4353@racer.site>
On Sunday 23 March 2008, Johannes Schindelin wrote:
Show 14 quoted lines
> 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.

Show 8 quoted lines
> > +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
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 3 of 22 in “builtin-prune.c: fix object parsing and use parse_options()”
  1. 2/2 builtin-prune.c: fix object parsing and use parse_options()Michele Ballabio, Mar 23, 2008
  2. Johannes SchindelinMar 23, 2008
  3. Michele BallabioMar 24, 2008
  4. Johannes SchindelinMar 24, 2008
  5. 3/2 parse-options.c: introduce OPT_DATEMichele Ballabio, Mar 24, 2008
  6. Johannes SchindelinMar 24, 2008
  7. Michele BallabioMar 24, 2008
  8. Johannes SchindelinMar 24, 2008
  9. Junio C HamanoMar 24, 2008
  10. Michele BallabioMar 24, 2008
  11. Junio C HamanoMar 25, 2008
  12. 1/5 parse-options.c: introduce OPT_DATEJunio C Hamano, Mar 25, 2008
  13. 2/5 test_must_fail: 129 is a valid error code from usage()Junio C Hamano, Mar 25, 2008
  14. Johannes SchindelinMar 25, 2008
  15. Johannes SixtMar 25, 2008
  16. Johannes SchindelinMar 25, 2008
  17. 3/5 Add tests for git-pruneJunio C Hamano, Mar 25, 2008
  18. 4/5 builtin-prune.c: use parse_options()Junio C Hamano, Mar 25, 2008
  19. 5/5 builtin-prune: protect objects listed on the command lineJunio C Hamano, Mar 25, 2008
  20. Junio C HamanoMar 27, 2008
  21. Johannes SchindelinMar 27, 2008
  22. Michele BallabioMar 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.