2017-05-05 11:01:50 +02:00
|
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
|
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
|
2018-03-17 23:59:18 +01:00
|
|
|
|
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
|
2017-05-05 11:01:50 +02:00
|
|
|
|
;;;
|
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
|
;;; your option) any later version.
|
|
|
|
|
;;;
|
|
|
|
|
;;; GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
|
;;;
|
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
(define-module (guix git)
|
|
|
|
|
#:use-module (git)
|
|
|
|
|
#:use-module (git object)
|
|
|
|
|
#:use-module (guix base32)
|
Switch to Guile-Gcrypt.
This removes (guix hash) and (guix pk-crypto), which now live as part of
Guile-Gcrypt (version 0.1.0.)
* guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm,
tests/hash.scm, tests/pk-crypto.scm: Remove.
* configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and
LIBGCRYPT_LIBDIR assignments.
* m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove.
* README: Add Guile-Gcrypt to the dependencies; move libgcrypt as
"required unless --disable-daemon".
* doc/guix.texi (Requirements): Likewise.
* gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm,
guix/git.scm, guix/http-client.scm, guix/import/cpan.scm,
guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm,
guix/import/gnu.scm, guix/import/hackage.scm,
guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm,
guix/pki.scm, guix/scripts/archive.scm,
guix/scripts/authenticate.scm, guix/scripts/download.scm,
guix/scripts/hash.scm, guix/scripts/pack.scm,
guix/scripts/publish.scm, guix/scripts/refresh.scm,
guix/scripts/substitute.scm, guix/store.scm,
guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm,
tests/builders.scm, tests/challenge.scm, tests/cpan.scm,
tests/crate.scm, tests/derivations.scm, tests/gem.scm,
tests/nar.scm, tests/opam.scm, tests/pki.scm,
tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm,
tests/store.scm, tests/substitute.scm: Adjust imports.
* gnu/system/vm.scm: Likewise.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(expression->derivation-in-linux-vm)[config]: Remove.
(iso9660-image)[config]: Remove.
(qemu-image)[config]: Remove.
(system-docker-image)[config]: Remove.
* guix/scripts/pack.scm: Adjust imports.
(guile-sqlite3&co): Rename to...
(gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT.
(self-contained-tarball)[build]: Call 'make-config.scm' without
#:libgcrypt argument.
(squashfs-image)[libgcrypt]: Remove.
[build]: Call 'make-config.scm' without #:libgcrypt.
(docker-image)[config, json]: Remove.
[build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from
the imported modules.
* guix/self.scm (specification->package): Remove "libgcrypt", add
"guile-gcrypt".
(compiled-guix): Remove #:libgcrypt.
[guile-gcrypt]: New variable.
[dependencies]: Add it.
[*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call.
Add #:extensions.
[*config*]: Remove #:libgcrypt from 'make-config.scm' call.
(%dependency-variables): Remove %libgcrypt.
(make-config.scm): Remove #:libgcrypt.
* build-aux/build-self.scm (guile-gcrypt): New variable.
(make-config.scm): Remove #:libgcrypt.
(build-program)[fake-gcrypt-hash]: New variable.
Add (gcrypt hash) to the imported modules. Adjust load path
assignments.
* gnu/packages/package-management.scm (guix)[propagated-inputs]: Add
GUILE-GCRYPT.
[arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search
path.
2018-08-31 17:07:07 +02:00
|
|
|
|
#:use-module (gcrypt hash)
|
2017-11-06 18:05:09 +01:00
|
|
|
|
#:use-module ((guix build utils) #:select (mkdir-p))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
#:use-module (guix store)
|
|
|
|
|
#:use-module (guix utils)
|
2018-11-27 14:50:48 +01:00
|
|
|
|
#:use-module (guix records)
|
|
|
|
|
#:use-module (guix gexp)
|
2017-05-05 11:01:50 +02:00
|
|
|
|
#:use-module (rnrs bytevectors)
|
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
|
#:use-module (srfi srfi-1)
|
2018-04-02 23:11:07 +02:00
|
|
|
|
#:use-module (srfi srfi-11)
|
2018-03-17 23:59:18 +01:00
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
|
#:use-module (srfi srfi-35)
|
2017-05-05 11:01:50 +02:00
|
|
|
|
#:export (%repository-cache-directory
|
2018-04-02 23:11:07 +02:00
|
|
|
|
update-cached-checkout
|
2018-11-27 14:50:48 +01:00
|
|
|
|
latest-repository-commit
|
|
|
|
|
|
|
|
|
|
git-checkout
|
|
|
|
|
git-checkout?
|
|
|
|
|
git-checkout-url
|
|
|
|
|
git-checkout-branch))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
|
|
|
|
|
(define %repository-cache-directory
|
2018-09-17 22:02:31 +02:00
|
|
|
|
(make-parameter (string-append (cache-directory #:ensure? #f)
|
|
|
|
|
"/checkouts")))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
|
|
|
|
|
(define-syntax-rule (with-libgit2 thunk ...)
|
2017-07-01 12:14:05 +02:00
|
|
|
|
(begin
|
|
|
|
|
;; XXX: The right thing to do would be to call (libgit2-shutdown) here,
|
|
|
|
|
;; but pointer finalizers used in guile-git may be called after shutdown,
|
|
|
|
|
;; resulting in a segfault. Hence, let's skip shutdown call for now.
|
|
|
|
|
(libgit2-init!)
|
|
|
|
|
thunk ...))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
|
|
|
|
|
(define* (url-cache-directory url
|
|
|
|
|
#:optional (cache-directory
|
|
|
|
|
(%repository-cache-directory)))
|
|
|
|
|
"Return the directory associated to URL in %repository-cache-directory."
|
|
|
|
|
(string-append
|
|
|
|
|
cache-directory "/"
|
|
|
|
|
(bytevector->base32-string (sha256 (string->utf8 url)))))
|
|
|
|
|
|
|
|
|
|
(define (clone* url directory)
|
|
|
|
|
"Clone git repository at URL into DIRECTORY. Upon failure,
|
|
|
|
|
make sure no empty directory is left behind."
|
|
|
|
|
(with-throw-handler #t
|
|
|
|
|
(lambda ()
|
|
|
|
|
(mkdir-p directory)
|
2017-11-10 12:59:55 +01:00
|
|
|
|
|
|
|
|
|
;; Note: Explicitly pass options to work around the invalid default
|
|
|
|
|
;; value in Guile-Git: <https://bugs.gnu.org/29238>.
|
2017-11-11 18:38:27 +01:00
|
|
|
|
(if (module-defined? (resolve-interface '(git))
|
|
|
|
|
'clone-init-options)
|
|
|
|
|
(clone url directory (clone-init-options))
|
|
|
|
|
(clone url directory)))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
(lambda _
|
|
|
|
|
(false-if-exception (rmdir directory)))))
|
|
|
|
|
|
|
|
|
|
(define (url+commit->name url sha1)
|
|
|
|
|
"Return the string \"<REPO-NAME>-<SHA1:7>\" where REPO-NAME is the name of
|
|
|
|
|
the git repository, extracted from URL and SHA1:7 the seven first digits
|
|
|
|
|
of SHA1 string."
|
|
|
|
|
(string-append
|
|
|
|
|
(string-replace-substring
|
|
|
|
|
(last (string-split url #\/)) ".git" "")
|
|
|
|
|
"-" (string-take sha1 7)))
|
|
|
|
|
|
|
|
|
|
(define (switch-to-ref repository ref)
|
2018-04-02 23:11:07 +02:00
|
|
|
|
"Switch to REPOSITORY's branch, commit or tag specified by REF. Return the
|
|
|
|
|
OID (roughly the commit hash) corresponding to REF."
|
2018-03-17 23:59:18 +01:00
|
|
|
|
(define obj
|
|
|
|
|
(match ref
|
|
|
|
|
(('branch . branch)
|
|
|
|
|
(let ((oid (reference-target
|
|
|
|
|
(branch-lookup repository branch BRANCH-REMOTE))))
|
|
|
|
|
(object-lookup repository oid)))
|
|
|
|
|
(('commit . commit)
|
|
|
|
|
(let ((len (string-length commit)))
|
|
|
|
|
;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, so we
|
|
|
|
|
;; can't be sure it's available. Furthermore, 'string->oid' used to
|
|
|
|
|
;; read out-of-bounds when passed a string shorter than 40 chars,
|
|
|
|
|
;; which is why we delay calls to it below.
|
|
|
|
|
(if (< len 40)
|
|
|
|
|
(if (module-defined? (resolve-interface '(git object))
|
|
|
|
|
'object-lookup-prefix)
|
|
|
|
|
(object-lookup-prefix repository (string->oid commit) len)
|
|
|
|
|
(raise (condition
|
|
|
|
|
(&message
|
|
|
|
|
(message "long Git object ID is required")))))
|
|
|
|
|
(object-lookup repository (string->oid commit)))))
|
|
|
|
|
(('tag . tag)
|
|
|
|
|
(let ((oid (reference-name->oid repository
|
|
|
|
|
(string-append "refs/tags/" tag))))
|
|
|
|
|
(object-lookup repository oid)))))
|
|
|
|
|
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(reset repository obj RESET_HARD)
|
|
|
|
|
(object-id obj))
|
|
|
|
|
|
|
|
|
|
(define* (update-cached-checkout url
|
|
|
|
|
#:key
|
2018-09-05 23:31:51 +02:00
|
|
|
|
(ref '(branch . "master"))
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(cache-directory
|
2018-07-08 12:15:41 +02:00
|
|
|
|
(url-cache-directory
|
|
|
|
|
url (%repository-cache-directory))))
|
2018-04-02 23:11:07 +02:00
|
|
|
|
"Update the cached checkout of URL to REF in CACHE-DIRECTORY. Return two
|
|
|
|
|
values: the cache directory name, and the SHA1 commit (a string) corresponding
|
|
|
|
|
to REF.
|
|
|
|
|
|
|
|
|
|
REF is pair whose key is [branch | commit | tag] and value the associated
|
|
|
|
|
data, respectively [<branch name> | <sha1> | <tag name>]."
|
2018-09-05 23:31:51 +02:00
|
|
|
|
(define canonical-ref
|
|
|
|
|
;; We used to require callers to specify "origin/" for each branch, which
|
|
|
|
|
;; made little sense since the cache should be transparent to them. So
|
|
|
|
|
;; here we append "origin/" if it's missing and otherwise keep it.
|
|
|
|
|
(match ref
|
|
|
|
|
(('branch . branch)
|
|
|
|
|
`(branch . ,(if (string-prefix? "origin/" branch)
|
|
|
|
|
branch
|
|
|
|
|
(string-append "origin/" branch))))
|
|
|
|
|
(_ ref)))
|
|
|
|
|
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(with-libgit2
|
2018-07-08 12:15:41 +02:00
|
|
|
|
(let* ((cache-exists? (openable-repository? cache-directory))
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(repository (if cache-exists?
|
2018-07-08 12:15:41 +02:00
|
|
|
|
(repository-open cache-directory)
|
|
|
|
|
(clone* url cache-directory))))
|
2018-04-02 23:11:07 +02:00
|
|
|
|
;; Only fetch remote if it has not been cloned just before.
|
|
|
|
|
(when cache-exists?
|
|
|
|
|
(remote-fetch (remote-lookup repository "origin")))
|
2018-09-05 23:31:51 +02:00
|
|
|
|
(let ((oid (switch-to-ref repository canonical-ref)))
|
2018-04-02 23:11:07 +02:00
|
|
|
|
|
|
|
|
|
;; Reclaim file descriptors and memory mappings associated with
|
|
|
|
|
;; REPOSITORY as soon as possible.
|
|
|
|
|
(when (module-defined? (resolve-interface '(git repository))
|
|
|
|
|
'repository-close!)
|
|
|
|
|
(repository-close! repository))
|
|
|
|
|
|
2018-07-08 12:15:41 +02:00
|
|
|
|
(values cache-directory (oid->string oid))))))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
|
|
|
|
|
(define* (latest-repository-commit store url
|
|
|
|
|
#:key
|
2018-11-27 14:48:32 +01:00
|
|
|
|
(log-port (%make-void-port "w"))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
(cache-directory
|
|
|
|
|
(%repository-cache-directory))
|
2018-09-05 23:31:51 +02:00
|
|
|
|
(ref '(branch . "master")))
|
2017-05-05 11:01:50 +02:00
|
|
|
|
"Return two values: the content of the git repository at URL copied into a
|
|
|
|
|
store directory and the sha1 of the top level commit in this directory. The
|
|
|
|
|
reference to be checkout, once the repository is fetched, is specified by REF.
|
|
|
|
|
REF is pair whose key is [branch | commit | tag] and value the associated
|
|
|
|
|
data, respectively [<branch name> | <sha1> | <tag name>].
|
|
|
|
|
|
|
|
|
|
Git repositories are kept in the cache directory specified by
|
2018-11-27 14:48:32 +01:00
|
|
|
|
%repository-cache-directory parameter.
|
|
|
|
|
|
|
|
|
|
Log progress and checkout info to LOG-PORT."
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(define (dot-git? file stat)
|
|
|
|
|
(and (string=? (basename file) ".git")
|
|
|
|
|
(eq? 'directory (stat:type stat))))
|
2018-03-26 00:12:52 +02:00
|
|
|
|
|
2018-11-27 14:48:32 +01:00
|
|
|
|
(format log-port "updating checkout of '~a'...~%" url)
|
2018-07-08 12:15:41 +02:00
|
|
|
|
(let*-values
|
|
|
|
|
(((checkout commit)
|
|
|
|
|
(update-cached-checkout url
|
|
|
|
|
#:ref ref
|
|
|
|
|
#:cache-directory
|
|
|
|
|
(url-cache-directory url cache-directory)))
|
|
|
|
|
((name)
|
|
|
|
|
(url+commit->name url commit)))
|
2018-11-27 14:48:32 +01:00
|
|
|
|
(format log-port "retrieved commit ~a~%" commit)
|
2018-04-02 23:11:07 +02:00
|
|
|
|
(values (add-to-store store name #t "sha256" checkout
|
|
|
|
|
#:select? (negate dot-git?))
|
|
|
|
|
commit)))
|
2018-11-27 14:50:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;
|
|
|
|
|
;;; Checkouts.
|
|
|
|
|
;;;
|
|
|
|
|
|
|
|
|
|
;; Representation of the "latest" checkout of a branch.
|
|
|
|
|
(define-record-type* <git-checkout>
|
|
|
|
|
git-checkout make-git-checkout
|
|
|
|
|
git-checkout?
|
|
|
|
|
(url git-checkout-url)
|
|
|
|
|
(branch git-checkout-branch (default "master")))
|
|
|
|
|
|
|
|
|
|
(define latest-repository-commit*
|
|
|
|
|
(store-lift latest-repository-commit))
|
|
|
|
|
|
|
|
|
|
(define-gexp-compiler (git-checkout-compiler (checkout <git-checkout>)
|
|
|
|
|
system target)
|
|
|
|
|
;; "Compile" CHECKOUT by updating the local checkout and adding it to the
|
|
|
|
|
;; store.
|
|
|
|
|
(match checkout
|
|
|
|
|
(($ <git-checkout> url branch)
|
|
|
|
|
(latest-repository-commit* url
|
|
|
|
|
#:ref `(branch . ,branch)
|
|
|
|
|
#:log-port (current-error-port)))))
|