Subject: Re: bug#65352: Fix time-machine and network

From: Ludovic Courtès <[email-masked]>
Date: Wed, 13 Sep 2023 22:16:25 +0200

Hi,

Simon Tournier <[email-masked]> skribis:

> Follow-up of 756e336fa008c2469b4a7317ad5c641ed48f25d6 fixing the issue.
>
> * guix/git/scm (reference-available?): Address case by case to determine
> whether the reference exists in the local Git checkout.

[...]

>  (define (reference-available? repository ref)
>    "Return true if REF, a reference such as '(commit . \"cabba9e\"), is
>  definitely available in REPOSITORY, false otherwise."
> -  ;; Note: this must not rely on 'resolve-reference', as that procedure always
> -  ;; resolves the references for branch names such as master.  The semantic we
> -  ;; want here is that unless the reference is exact (e.g. a commit), the
> -  ;; reference should not be considered available, as it could have changed on
> -  ;; the remote.
>    (match ref
> -    ((or ('commit . commit)
> -         ('tag-or-commit . (? commit-id? commit)))
> -     (let ((len (string-length commit))
> -           (oid (string->oid commit)))
> -       (false-if-git-not-found
> -        (->bool (if (< len 40)
> -                    (object-lookup-prefix repository oid len OBJ-COMMIT)
> -                    (commit-lookup repository oid))))))
> +    (('commit . (? commit-id? commit))
> +     (let ((oid (string->oid commit)))
> +       (->bool (commit-lookup repository oid))))
> +    ((or ('tag . str)
> +         ('tag-or-commit . str))
> +     (false-if-git-not-found
> +      (->bool (resolve-reference repository ref))))

IIUC, the differences compared to what we had are:

  1. 'tag references are now handled on the fast path
     (‘reference-available?’ can return #t);

  2. short commit strings are now always on the slow path
     (‘reference-available?’ always returns #f).

Is that correct?

It would be nice to have #1 without #2.

>      (_
> +     ;; For the others REF as branch or symref, the REF cannot be available

“For other values of REF such as branch or symref, the target is by
definition unavailable locally.”

Thanks,
Ludo’.