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

Re: Silly "git gc" UI issue.

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 19, 2018, 02:16 UTC
Message-ID
<xmqqfu3seyad.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<xmqqmuy0ez8b.fsf@gitster-ct.c.googlers.com>

A few commands that parse --expire=<time> command line option behaves silly when given nonsense input. For example

    $ git prune --no-expire
    Segmentation falut
    $ git prune --expire=npw; echo $?
    129
Both come from parse_opt_expiry_date_cb().

The former is because the function is not prepared to see arg==NULL (for "--no-expire", it is a norm; "--expire" at the end of the command line could be made to pass NULL, if it is told that the argument is optional, but we don't so we do not have to worry about that case).

The latter is because it does not check the value returned from the underlying parse_expiry_date().

This seems to be a recent regression introduced while we attempted to avoid spewing the entire usage message when given a correct option but with an invalid value at 3bb0923f ("parse-options: do not show usage upon invalid option value", 2018-03-22).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I do not expect this to be the final version (not just it lacks
   tests, but I haven't even run existing tests with the change
   yet), but I think I diagnosed the root cause correctly, at least.
 parse-options-cb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c
index c6679cb2cd..872627eafe 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -38,7 +38,11 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
 int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
 			     int unset)
 {
-	return parse_expiry_date(arg, (timestamp_t *)opt->value);
+	if (unset)
+		arg = "never";
+	if (parse_expiry_date(arg, (timestamp_t *)opt->value))
+		die("malformed expiration date '%s'", arg);
+	return 0;
 }
 
 int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
Previous: Junio C HamanoNext: Linus Torvalds
Message 4 of 14 in “Silly "git gc" UI issue.”
  1. Linus TorvaldsApr 19, 2018
  2. Junio C HamanoApr 19, 2018
  3. Junio C HamanoApr 19, 2018
  4. Junio C HamanoApr 19, 2018
  5. Linus TorvaldsApr 19, 2018
  6. Junio C HamanoApr 19, 2018
  7. Junio C HamanoApr 19, 2018
  8. Simon RuderichApr 20, 2018
  9. Junio C HamanoApr 21, 2018
  10. Christian CouderApr 21, 2018
  11. Junio C HamanoApr 23, 2018
  12. Linus TorvaldsApr 19, 2018
  13. Simon RuderichApr 19, 2018
  14. Junio C HamanoApr 20, 2018

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.