[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
09/09: git: 'switch-to-ref' accepts short commit IDs.
From: |
Ludovic Courtès |
Subject: |
09/09: git: 'switch-to-ref' accepts short commit IDs. |
Date: |
Sat, 17 Mar 2018 19:02:38 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 95bd9f65a8ee64d17707a76aebc8720bbd961b68
Author: Ludovic Courtès <address@hidden>
Date: Sat Mar 17 23:59:18 2018 +0100
git: 'switch-to-ref' accepts short commit IDs.
Fixes <https://bugs.gnu.org/30716>.
Reported by Björn Höfling <address@hidden>.
* guix/git.scm (switch-to-ref): When REF is a commit, check the length
of COMMIT and use 'object-lookup-prefix' if available.
---
guix/git.scm | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/guix/git.scm b/guix/git.scm
index fc41e2a..d31c35f 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 Mathieu Othacehe <address@hidden>
+;;; Copyright © 2018 Ludovic Courtès <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -27,6 +28,8 @@
#:use-module (rnrs bytevectors)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-35)
#:export (%repository-cache-directory
latest-repository-commit))
@@ -94,17 +97,32 @@ create the store directory name."
(define (switch-to-ref repository ref)
"Switch to REPOSITORY's branch, commit or tag specified by REF."
- (let* ((oid (match ref
- (('branch . branch)
- (reference-target
- (branch-lookup repository branch BRANCH-REMOTE)))
- (('commit . commit)
- (string->oid commit))
- (('tag . tag)
- (reference-name->oid repository
- (string-append "refs/tags/" tag)))))
- (obj (object-lookup repository oid)))
- (reset repository obj RESET_HARD)))
+ (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)))))
+
+ (reset repository obj RESET_HARD))
(define* (latest-repository-commit store url
#:key
- branch master updated (5983b78 -> 95bd9f6), Ludovic Courtès, 2018/03/17
- 02/09: services: openssh: Add 'accepted-environment' field., Ludovic Courtès, 2018/03/17
- 03/09: import: elpa: use https in download URLs, Ludovic Courtès, 2018/03/17
- 04/09: import: elpa: Fix typos in documentation strings, Ludovic Courtès, 2018/03/17
- 06/09: gnu: datamash: Update to 1.3., Ludovic Courtès, 2018/03/17
- 07/09: gnu: nss-mdns: Adjust Avahi socket file name., Ludovic Courtès, 2018/03/17
- 05/09: gnu: fvwm: Add '.desktop' file., Ludovic Courtès, 2018/03/17
- 08/09: gnu: guile-git: Update to 2bb9fbb., Ludovic Courtès, 2018/03/17
- 01/09: gnu: java-simple-xml: Fix java8 test failures., Ludovic Courtès, 2018/03/17
- 09/09: git: 'switch-to-ref' accepts short commit IDs.,
Ludovic Courtès <=