From: John Cai via GitGitGadget Date: Thu, 06 Jan 2022 19:06:21 GMT Subject: [PATCH v5] builtin/reflog.c: use parse-options api for expire, delete subcommands Message-ID: In-Reply-To: From: John Cai Switching out manual arg parsing for the parse-options API for the expire and delete subcommands. Move explicit_expiry flag into cmd_reflog_expire_cb struct so callbacks can set both the value of the timestamp as well as the explicit_expiry flag. Signed-off-by: "John Cai" --- reflog.c: switch to use parse-options API Switch out manual argv parsing for the reflog expire subcommand to use the parse-options API. This reduces code redundancy by consolidating option parsing logic. NOTE: this patch was based off of next. I know now that I should base it off of master. But practically, nothing in master touched reflog.c except for ab/reflog-prep changes since v4: * fixed indentation of option blocks * adjusted error message for invalid timestamps changes since v3: * fixed indentation changes since v2: * got rid of parse_opt_expiry_date helper based on feedback from Junio. Just call parse_expiry_date directly in the callbacks, and don't worry about unset, as we can just set the PARSE_OPT_NONEG flag for --expire and --expire-unreachable since the original code didn't support a negated version of those flags anyway. The documentation also explicitly states to use "never" as the argument. * fix places where we set int i inside a for loop construct. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1175%2Fjohn-cai%2Fjc%2Freflog-switch-to-option-parse-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1175/john-cai/jc/reflog-switch-to-option-parse-v5 Pull-Request: https://github.com/git/git/pull/1175 Range-diff vs v4: 1: 0efdf3d2cb1 ! 1: 9bb4de0f543 builtin/reflog.c: use parse-options api for expire, delete subcommands @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + struct cmd_reflog_expire_cb *cmd = opt->value; + + if (parse_expiry_date(arg, &cmd->expire_unreachable)) -+ die(_("malformed expiration date '%s'"), arg); ++ die(_("invalid timestamp '%s' given to '--%s'"), ++ arg, opt->long_name); + + cmd->explicit_expiry |= EXPIRE_UNREACH; + return 0; @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + struct cmd_reflog_expire_cb *cmd = opt->value; + + if (parse_expiry_date(arg, &cmd->expire_total)) -+ die(_("malformed expiration date '%s'"), arg); ++ die(_("invalid timestamp '%s' given to '--%s'"), ++ arg, opt->long_name); + + cmd->explicit_expiry |= EXPIRE_TOTAL; + return 0; @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + const struct option options[] = { + OPT_BIT(0, "dry-run", &flags, N_("do not actually prune any entries"), + EXPIRE_REFLOGS_DRY_RUN), -+ OPT_BIT(0, "rewrite", &flags, ++ OPT_BIT(0, "rewrite", &flags, + N_("rewrite the old SHA1 with the new SHA1 of the entry that now precedes it"), + EXPIRE_REFLOGS_REWRITE), + OPT_BIT(0, "updateref", &flags, @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + EXPIRE_REFLOGS_UPDATE_REF), + OPT_BOOL(0, "verbose", &verbose, N_("print extra information on screen.")), + OPT_CALLBACK_F(0, "expire", &cmd, N_("timestamp"), -+ N_("prune entries older than the specified time"), -+ PARSE_OPT_NONEG, -+ expire_total_callback), ++ N_("prune entries older than the specified time"), ++ PARSE_OPT_NONEG, ++ expire_total_callback), + OPT_CALLBACK_F(0, "expire-unreachable", &cmd, N_("timestamp"), -+ N_("prune entries older than