From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: Romain GARBAGE <romain.garbage@inria.fr>
Cc: 68405@debbugs.gnu.org, "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#68405] [PATCH v4] guix: download: Add support for git repositories.
Date: Fri, 19 Jan 2024 22:23:01 -0500 [thread overview]
Message-ID: <87v87ohene.fsf@gmail.com> (raw)
In-Reply-To: <20240119102417.17155-1-romain.garbage@inria.fr> (Romain GARBAGE's message of "Fri, 19 Jan 2024 11:19:23 +0100")
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
next prev parent reply other threads:[~2024-01-20 3:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-12 15:12 [bug#68405] [PATCH v2] guix: download: Add support for git repositories Romain GARBAGE
2024-01-12 15:57 ` Ludovic Courtès
2024-01-19 4:16 ` Maxim Cournoyer
2024-01-19 8:53 ` Romain Garbage
2024-01-19 10:19 ` [bug#68405] [PATCH v4] " Romain GARBAGE
2024-01-20 3:23 ` Maxim Cournoyer [this message]
2024-01-22 10:39 ` Romain Garbage
2024-01-22 10:32 ` [bug#68405] [PATCH v5] " Romain GARBAGE
2024-01-23 14:06 ` bug#68405: bug#68499: [PATCH v3] " Maxim Cournoyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v87ohene.fsf@gmail.com \
--to=maxim.cournoyer@gmail.com \
--cc=68405@debbugs.gnu.org \
--cc=ludo@gnu.org \
--cc=romain.garbage@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.