Re: [PATCH v2 08/24] Extract function should_expire_reflog_ent()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 12, 2014 at 12:56 AM, Michael Haggerty <mhagger@xxxxxxxxxxxx> wrote:
> Extract from expire_reflog_ent() a function that is solely responsible
> for deciding whether a reflog entry should be expired. By separating
> this "business logic" from the mechanics of actually expiring entries,
> we are working towards the goal of encapsulating reflog expiry within
> the refs API, with policy decided by a callback function passed to it
> by its caller.
>
> Signed-off-by: Michael Haggerty <mhagger@xxxxxxxxxxxx>

Reviewed-by: Stefan Beller <sbeller@xxxxxxxxxx>

> ---
>  builtin/reflog.c | 70 +++++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 42 insertions(+), 28 deletions(-)
>
> diff --git a/builtin/reflog.c b/builtin/reflog.c
> index ba5b3d3..06ce8b1 100644
> --- a/builtin/reflog.c
> +++ b/builtin/reflog.c
> @@ -288,51 +288,65 @@ static int unreachable(struct expire_reflog_cb *cb, struct commit *commit, unsig
>         return !(commit->object.flags & REACHABLE);
>  }
>
> -static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
> -               const char *email, unsigned long timestamp, int tz,
> -               const char *message, void *cb_data)
> +/*
> + * Return true iff the specified reflog entry should be expired.
> + */
> +static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
> +                                   const char *email, unsigned long timestamp, int tz,
> +                                   const char *message, void *cb_data)
>  {
>         struct expire_reflog_cb *cb = cb_data;
>         struct commit *old, *new;
>
>         if (timestamp < cb->cmd->expire_total)
> -               goto prune;
> -
> -       if (cb->cmd->rewrite)
> -               osha1 = cb->last_kept_sha1;
> +               return 1;
>
>         old = new = NULL;
>         if (cb->cmd->stalefix &&
>             (!keep_entry(&old, osha1) || !keep_entry(&new, nsha1)))
> -               goto prune;
> +               return 1;
>
>         if (timestamp < cb->cmd->expire_unreachable) {
>                 if (cb->unreachable_expire_kind == UE_ALWAYS)
> -                       goto prune;
> +                       return 1;
>                 if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1))
> -                       goto prune;
> +                       return 1;
>         }
>
>         if (cb->cmd->recno && --(cb->cmd->recno) == 0)
> -               goto prune;
> -
> -       if (cb->newlog) {
> -               char sign = (tz < 0) ? '-' : '+';
> -               int zone = (tz < 0) ? (-tz) : tz;
> -               fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s",
> -                       sha1_to_hex(osha1), sha1_to_hex(nsha1),
> -                       email, timestamp, sign, zone,
> -                       message);
> -               hashcpy(cb->last_kept_sha1, nsha1);
> -       }
> -       if (cb->cmd->verbose)
> -               printf("keep %s", message);
> +               return 1;
> +
>         return 0;
> - prune:
> -       if (!cb->newlog)
> -               printf("would prune %s", message);
> -       else if (cb->cmd->verbose)
> -               printf("prune %s", message);
> +}
> +
> +static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
> +               const char *email, unsigned long timestamp, int tz,
> +               const char *message, void *cb_data)
> +{
> +       struct expire_reflog_cb *cb = cb_data;
> +
> +       if (cb->cmd->rewrite)
> +               osha1 = cb->last_kept_sha1;
> +
> +       if (should_expire_reflog_ent(osha1, nsha1, email, timestamp, tz,
> +                                    message, cb_data)) {
> +               if (!cb->newlog)
> +                       printf("would prune %s", message);
> +               else if (cb->cmd->verbose)
> +                       printf("prune %s", message);
> +       } else {
> +               if (cb->newlog) {
> +                       char sign = (tz < 0) ? '-' : '+';
> +                       int zone = (tz < 0) ? (-tz) : tz;
> +                       fprintf(cb->newlog, "%s %s %s %lu %c%04d\t%s",
> +                               sha1_to_hex(osha1), sha1_to_hex(nsha1),
> +                               email, timestamp, sign, zone,
> +                               message);
> +                       hashcpy(cb->last_kept_sha1, nsha1);
> +               }
> +               if (cb->cmd->verbose)
> +                       printf("keep %s", message);
> +       }
>         return 0;
>  }
>
> --
> 2.1.3
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]