From: René Scharfe Date: Sun, 02 Jan 2022 09:00:34 GMT Subject: Re: [PATCH 1/2] builtin/reflog.c: use parse-options for expire subcommand 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: > > >> On Jan 1, 2022, at 3:16 AM, René Scharfe 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é