Re: [PATCH v2 5/7] reflog: exit early if there's no work to do
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Mar 15, 2019, 10:01 UTC
- Message-ID
- <CACsJy8C-zyh6Vea1hqciDHhKk+UvS5qFb1F2SfU15yWniy53Hw@mail.gmail.com>
- In-Reply-To
- <20190314123439.4347-6-avarab@gmail.com>
On Thu, Mar 14, 2019 at 7:35 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
Show 27 quoted lines
>
> When gc.reflogExpire and gc.reflogExpireUnreachable are set to "never"
> and --stale-fix isn't in effect (covered by the first part of the "if"
> statement being modified here) we can exit early without pointlessly
> looping over all the reflogs.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> builtin/reflog.c | 7 +++++++
> t/t1410-reflog.sh | 4 +++-
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index 4d3430900d..d95c77ca0e 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -606,6 +606,13 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)
> mark_reachable_objects(&cb.cmd.revs, 0, 0, NULL);
> if (flags & EXPIRE_REFLOGS_VERBOSE)
> putchar('\n');
> + } else if (!cb.cmd.expire_total && !cb.cmd.expire_unreachable) {
> + /*
> + * If we're not expiring anything and not dropping
> + * stale entries, there's no point in even opening the
> + * reflogs, since we're guaranteed to do nothing.
> + */I'm checking should_expire_reflog_ent(). With both of these being zero, we skip most of the "return 1;" except the last one cb->cmd.recno, added in 552cecc214 (Teach "git reflog" a subcommand to delete single entries, 2007-10-17). Will this shortcut affect that use case (I haven't spent time understanding that commit yet, gotta run soon)?
> + return 0; > }
-- Duy