guix-patches
[Top][All Lists]
Advanced

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

[bug#68405] [PATCH v4] guix: download: Add support for git repositories.


From: Maxim Cournoyer
Subject: [bug#68405] [PATCH v4] guix: download: Add support for git repositories.
Date: Fri, 19 Jan 2024 22:23:01 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

Hello!

Romain GARBAGE <romain.garbage@inria.fr> writes:

> * guix/scripts/download.scm (git-download-to-store*): Add new variable.
> (copy-recursively-without-dot-git): New variable.
> (git-download-to-file): Add new variable.
> (show-help): Add 'git', 'commit', 'branch' and 'recursive'options
> help message.
> (%default-options): Add default value for 'git-reference' and
> 'recursive' options.
> (%options): Add 'git', 'commit', 'branch' and 'recursive' command
> line options.
> (guix-download) [hash]: Compute hash with 'file-hash*' instead of
> 'port-hash' from (gcrypt hash) module. This allows us to compute
> hashes for directories.
> * doc/guix.texi (Invoking guix-download): Add @item entries for
> `git', `commit', `branch' and `recursive' options. Add a paragraph in
> the introduction.
> * tests/guix-download.sh: New tests. Move variables and trap definition
> to the top of the file.
>
> Change-Id: Ic2c428dca4cfcb0d4714ed361a4c46609339140a

[...]

> +(define* (git-download-to-store* url
> +                                 reference
> +                                 recursive?
> +                                 #:key (verify-certificate? #t))
> +  "Download the git repository at URL to the store, checked out at REFERENCE.
> +URL must specify a protocol (i.e https:// or file://), REFERENCE must be a
> +pair argument as understood by 'latest-repository-commit'."
> +  ;; Ensure the URL string is properly formatted  when using the 'file'
> +  ;; protocol: URL is generated using 'uri->string', which returns
> +  ;; "file:/path/to/file" instead of "file:///path/to/file", which in turn
> +  ;; makes 'git-download-to-store' fail.
> +  (let* ((file? (string-prefix? "file:" url))
> +         (url (if (and file?
> +                        (not (string-prefix? "file:///" url)))
> +                   (string-append "file://" (string-drop url (string-length 
> "file:")))
> +                   url)))
> +    (with-store store
> +      ;; TODO: Verify certificate support and deactivation.
> +      (with-git-error-handling
> +       (latest-repository-commit store url #:recursive? recursive? #:ref 
> reference)))))

The above contains too long lines still :-).

> +
>  (define %default-options
>    ;; Alist of default option values.
>    `((format . ,bytevector->nix-base32-string)
>      (hash-algorithm . ,(hash-algorithm sha256))
>      (verify-certificate? . #t)
> +    (git-reference . #f)
> +    (recursive? . #f)
>      (download-proc . ,download-to-store*)))
>  
>  (define (show-help)
> @@ -97,6 +180,19 @@ (define (show-help)
>                           do not validate the certificate of HTTPS servers "))
>    (format #t (G_ "
>    -o, --output=FILE      download to FILE"))
> +  (format #t (G_ "
> +  -g, --git              download the default branch's latest commit of the
> +                         Git repository at URL"))
> +  (format #t (G_ "
> +      --commit=COMMIT-OR-TAG
> +                         download the given commit or tag of the Git
> +                         repository at URL"))
> +  (format #t (G_ "
> +      --branch=BRANCH    download the given branch of the Git repository
> +                         at URL"))
> +  (format #t (G_ "
> +  -r, --recursive        download a Git repository recursively"))
> +
>    (newline)
>    (display (G_ "
>    -h, --help             display this help and exit"))
> @@ -105,6 +201,13 @@ (define (show-help)
>    (newline)
>    (show-bug-report-information))
>  
> +(define (add-git-download-option result)
> +  (alist-cons 'download-proc
> +              ;; XXX: #:verify-certificate? currently ignored.
> +              (lambda* (url #:key verify-certificate? ref recursive?)
> +                (git-download-to-store* url ref recursive?))
> +              (alist-delete 'download result)))
> +
>  (define %options
>    ;; Specifications of the command-line options.
>    (list (option '(#\f "format") #t #f
> @@ -136,11 +239,36 @@ (define fmt-proc
>                    (alist-cons 'verify-certificate? #f result)))
>          (option '(#\o "output") #t #f
>                  (lambda (opt name arg result)
> -                  (alist-cons 'download-proc
> -                              (lambda* (url #:key verify-certificate?)
> -                                (download-to-file url arg))
> -                              (alist-delete 'download result))))
> -
> +                  (let* ((git
> +                          (assoc-ref result 'git-reference)))
> +                    (if git
> +                        (alist-cons 'download-proc
> +                                    (lambda* (url #:key verify-certificate? 
> ref recursive?)
> +                                      (git-download-to-file url arg 
> (assoc-ref result 'git-reference) recursive?))
> +                                    (alist-delete 'download result))
> +                        (alist-cons 'download-proc
> +                                    (lambda* (url #:key verify-certificate? 
> #:allow-other-keys)
> +                                      (download-to-file url arg))
> +                                    (alist-delete 'download result))))))

Here as well.

Otherwise, I've tested it with:

--8<---------------cut here---------------start------------->8---
./pre-inst-env guix download -gr 
https://git.jami.net/savoirfairelinux/jami-client-qt -o /tmp/jami
--8<---------------cut here---------------end--------------->8---

and it worked as advertised; very nice!

Some idea for the future: the --recurse option could take an optional
argument that'd be a comma-separated list of submodules to fetch, e.g.

--8<---------------cut here---------------start------------->8---
./pre-inst-env guix download --git \
  --recurse=daemon,3rdparty/SortFilterProxyModel \
  https://git.jami.net/savoirfairelinux/jami-client-qt -o /tmp/jami
--8<---------------cut here---------------end--------------->8---

and it'd recurse *only* the listed submodules.  This would be useful as
some projects contain submodules for windows or other platforms we do
not care about and they may be very large (heavy) to download.

The same idea could be implemented for our git-reference, where
recursive? could accept a git submodule names list.

But back to the current scope:

Reviewed-by: Maxim Cournoyer <maxim.cournoyer@gmail>

-- 
Thanks,
Maxim





reply via email to

[Prev in Thread] Current Thread [Next in Thread]