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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Michele Ballabio
Date: Monday, March 24, 2008 - 5:31 am

On Sunday 23 March 2008, Johannes Schindelin wrote:

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.


Uhm, probably, yes. See the patch below.


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

--
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
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 2/2] builtin-prune.c: fix object parsing and us ..., Johannes Schindelin, (Sun Mar 23, 3:21 pm)
Re: [PATCH 2/2] builtin-prune.c: fix object parsing and us ..., Michele Ballabio, (Mon Mar 24, 5:31 am)
Re: [PATCH 2/2] builtin-prune.c: fix object parsing and us ..., Johannes Schindelin, (Mon Mar 24, 6:13 am)
Re: [PATCH 3/2] parse-options.c: introduce OPT_DATE, Johannes Schindelin, (Mon Mar 24, 6:59 am)
[PATCH 3/2] parse-options.c: introduce OPT_DATE, Michele Ballabio, (Mon Mar 24, 7:02 am)
Re: [PATCH 3/2] parse-options.c: introduce OPT_DATE, Michele Ballabio, (Mon Mar 24, 9:25 am)
Re: [PATCH 3/2] parse-options.c: introduce OPT_DATE, Johannes Schindelin, (Mon Mar 24, 1:03 pm)
Re: [PATCH 3/2] parse-options.c: introduce OPT_DATE, Junio C Hamano, (Mon Mar 24, 1:10 pm)
Re: [PATCH 3/2] parse-options.c: introduce OPT_DATE, Michele Ballabio, (Mon Mar 24, 2:18 pm)