Package: guix-patches;
Reported by: Romain GARBAGE <romain.garbage <at> inria.fr>
Date: Fri, 12 Jan 2024 15:16:01 UTC
Severity: normal
Tags: patch
Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Bug is archived. No further changes may be made.
View this message in rfc822 format
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Romain GARBAGE <romain.garbage <at> inria.fr> Cc: 68405 <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org> Subject: [bug#68405] [PATCH v4] guix: download: Add support for git repositories. Date: Fri, 19 Jan 2024 22:23:01 -0500
Hello! Romain GARBAGE <romain.garbage <at> 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 <at> gmail> -- Thanks, Maxim
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.