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

[PATCH v2 1/2] parse-options.h: add parse_opt_expiry_date helper

From
John Cai via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 3, 2022, 15:20 UTC
Message-ID
<bcd74559c2474451687c81e97834b13a859d2191.1641223223.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1175.v2.git.git.1641223223.gitgitgadget@gmail.com>
From: John Cai <johncai86@gmail.com>

Extract the logic in parse_opt_expiry_date_cb into a helper parse_opt_expiry_date. This is to prepare for the following commit where we need to parse an expiry date that gets passed into a callback function in opt->value as part of a struct.

The next commit will utilize this helper in a callback function that aims to wrap the functionality in parse_opt_expiry_date_cb.

Signed-off-by: "John Cai" <johncai86@gmail.com>
---
 parse-options-cb.c | 7 ++++++-
 parse-options.h    | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 3c811e1e4a7..3edb88a54d8 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -34,10 +34,15 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
 
 int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
 			     int unset)
+{
+	return parse_opt_expiry_date((timestamp_t *)opt->value, arg, unset);
+}
+
+int parse_opt_expiry_date(timestamp_t *t, const char *arg, int unset)
 {
 	if (unset)
 		arg = "never";
-	if (parse_expiry_date(arg, (timestamp_t *)opt->value))
+	if (parse_expiry_date(arg, t))
 		die(_("malformed expiration date '%s'"), arg);
 	return 0;
 }
diff --git a/parse-options.h b/parse-options.h
index 275fb440818..0a15bac8619 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -301,6 +301,7 @@ enum parse_opt_result parse_opt_unknown_cb(struct parse_opt_ctx_t *ctx,
 					   const char *, int);
 int parse_opt_passthru(const struct option *, const char *, int);
 int parse_opt_passthru_argv(const struct option *, const char *, int);
+int parse_opt_expiry_date(timestamp_t *, const char *, int);
 
 #define OPT__VERBOSE(var, h)  OPT_COUNTUP('v', "verbose", (var), (h))
 #define OPT__QUIET(var, h)    OPT_COUNTUP('q', "quiet",   (var), (h))
-- 
gitgitgadget
Previous: John Cai via GitGitGadgetNext: Junio C Hamano
Message 9 of 19 in “reflog.c: switch to use parse-options API”
  1. 0/2 reflog.c: switch to use parse-options APIJohn Cai via GitGitGadget, Dec 31, 2021
  2. 1/2 builtin/reflog.c: use parse-options for expire subcommandJohn Cai via GitGitGadget, Dec 31, 2021
  3. John CaiJan 1, 2022
  4. René ScharfeJan 1, 2022
  5. John CaiJan 1, 2022
  6. René ScharfeJan 2, 2022
  7. 2/2 builtin/reflog.c: switch to use parse-options API for delete subcommandJohn Cai via GitGitGadget, Dec 31, 2021
  8. 0/2 reflog.c: switch to use parse-options APIJohn Cai via GitGitGadget, Jan 3, 2022
  9. 1/2 parse-options.h: add parse_opt_expiry_date helperJohn Cai via GitGitGadget, Jan 3, 2022
  10. Junio C HamanoJan 4, 2022
  11. 2/2 builtin/reflog.c: switch to use parse-options API for delete subcommandJohn Cai via GitGitGadget, Jan 3, 2022
  12. Junio C HamanoJan 4, 2022
  13. builtin/reflog.c: use parse-options api for expire, delete subcommandsJohn Cai via GitGitGadget, Jan 4, 2022
  14. Junio C HamanoJan 4, 2022
  15. builtin/reflog.c: use parse-options api for expire, delete subcommandsJohn Cai via GitGitGadget, Jan 5, 2022
  16. Junio C HamanoJan 5, 2022
  17. builtin/reflog.c: use parse-options api for expire, delete subcommandsJohn Cai via GitGitGadget, Jan 6, 2022
  18. Junio C HamanoJan 6, 2022
  19. John CaiJan 6, 2022

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.