Re: [PATCH 1/2] builtin/reflog.c: use parse-options for expire subcommand
- From
René Scharfe <l.s.r@web.de>
- Date
- Jan 2, 2022, 09:00 UTC
- Message-ID
- <602b2039-8d74-8063-9757-e67ba5db1141@web.de>
- In-Reply-To
- <9D4E4253-6EBE-4AA7-86A5-413A732C6E38@gmail.com>
Am 01.01.22 um 20:09 schrieb John Cai:
Show 26 quoted lines
>
>
>> On Jan 1, 2022, at 3:16 AM, René Scharfe <l.s.r@web.de> wrote:
>>
>> The problem is that the default value can vary between reflogs and we
>> only know which ones are to be expired after option parsing, right?
>
> That’s a good point. Does it matter that the default value varies between reflogs?
>
> Would something like this suffice?
>
> - for (i = 1; i < argc; i++) {
> - const char *arg = argv[i];
> - if (starts_with(arg, "--expire=")) {
> - explicit_expiry |= EXPIRE_TOTAL;
> - } else if (starts_with(arg, "--expire-unreachable=")) {
> - explicit_expiry |= EXPIRE_UNREACH;
> - }
> - }
> -
> argc = parse_options(argc, argv, prefix, options, reflog_expire_usage, 0);
>
> + if (cb.cmd.expire_total != default_reflog_expire)
> + explicit_expiry |= EXPIRE_TOTAL;
> + if (cb.cmd.expire_unreachable != default_reflog_expire_unreachable)
> + explicit_expiry |= EXPIRE_UNREACH;This would ignore --expire and -expire-unreachable options with the value of default_reflog_expire and default_reflog_expire_unreachable, respectively. E.g. "git reflog expire --expire=90.days.ago refs/stash" would not expire anything.
René