paco pkg: allow a commit id to be used in a GitHub reference

Allow a commit id in place of a branch or tag.
This commit is contained in:
Matthew Flatt 2013-09-01 09:13:40 -06:00
parent 61e6279c49
commit 62f7731c36
3 changed files with 50 additions and 40 deletions

View File

@ -189,11 +189,11 @@ URLs is:
@inset{@exec{git://github.com/}@nonterm{user}@exec{/}@nonterm{repo}@; @inset{@exec{git://github.com/}@nonterm{user}@exec{/}@nonterm{repo}@;
@optional{@exec{.git}}@optional{@exec{/}}@optional{@exec{?path=}@nonterm{path}}@; @optional{@exec{.git}}@optional{@exec{/}}@optional{@exec{?path=}@nonterm{path}}@;
@optional{@exec{#}@nonterm{tag}}} @optional{@exec{#}@nonterm{rev}}}
where @nonterm{path} can contain multiple @litchar{/}-separated where @nonterm{path} can contain multiple @litchar{/}-separated
elements to form a path within the repository, and defaults to the elements to form a path within the repository, and defaults to the
empty path. The @nonterm{tag} can be a branch or tag, and it empty path. The @nonterm{rev} can be a branch, tag, or commit, and it
defaults to @exec{master}. defaults to @exec{master}.
For example, @filepath{git://github.com/game/tic-tac-toe#master} For example, @filepath{git://github.com/game/tic-tac-toe#master}
@ -202,12 +202,13 @@ is a GitHub package source.
For backward compatibility, an older format is also supported: For backward compatibility, an older format is also supported:
@inset{@exec{github://github.com/}@nonterm{user}@exec{/}@nonterm{repo}@; @inset{@exec{github://github.com/}@nonterm{user}@exec{/}@nonterm{repo}@;
@exec{/}@nonterm{tag}@optional{@exec{/}@nonterm{path}}} @exec{/}@nonterm{rev}@optional{@exec{/}@nonterm{path}}}
The @exec{zip}-formatted archive for the repository (generated by The @exec{zip}-formatted archive for the repository (generated by
GitHub for every branch and tag) is used as a remote URL archive path, GitHub for any commit) is used as a remote URL archive path. The
except the @tech{checksum} is the hash identifying the branch (or @tech{checksum} is the hash identifying @nonterm{rev} if @nonterm{rev}
tag). is a branch or tag, otherwise @nonterm{rev} itself serves as the
@tech{checksum}.
A package source is inferred to be a GitHub reference when it A package source is inferred to be a GitHub reference when it
starts with @litchar{git://} or @litchar{github://}; a package source that is otherwise starts with @litchar{git://} or @litchar{github://}; a package source that is otherwise

View File

@ -30,6 +30,10 @@
"remote/github with tag" "remote/github with tag"
"git://github.com/mflatt/pkg-test?path=pkg-test1/#hundred" "git://github.com/mflatt/pkg-test?path=pkg-test1/#hundred"
$ "racket -l racket/base -l pkg-test1/number -e '(number)'" =stdout> "100\n") $ "racket -l racket/base -l pkg-test1/number -e '(number)'" =stdout> "100\n")
(shelly-install
"remote/github with commit"
"git://github.com/mflatt/pkg-test?path=pkg-test1/#f9b4eef22"
$ "racket -l racket/base -l pkg-test1/number -e '(number)'" =stdout> "100\n")
(shelly-install (shelly-install
"remote/github with checksum" "remote/github with checksum"
"--checksum f9b4eef22cdd9ab88b254cb027fc1ebe7fb596fd git://github.com/mflatt/pkg-test?path=pkg-test1" "--checksum f9b4eef22cdd9ab88b254cb027fc1ebe7fb596fd git://github.com/mflatt/pkg-test?path=pkg-test1"

View File

@ -76,40 +76,45 @@
[(or "github" "git") [(or "github" "git")
(match-define (list* user repo branch path) (match-define (list* user repo branch path)
(split-github-url pkg-url)) (split-github-url pkg-url))
(for/or ([kind '("branches" "tags")]) (or
(define api-u (for/or ([kind '("branches" "tags")])
(url "https" #f "api.github.com" #f #t (define api-u
(map (λ (x) (path/param x empty)) (url "https" #f "api.github.com" #f #t
(list "repos" user repo kind)) (map (λ (x) (path/param x empty))
(append query (list "repos" user repo kind))
(if (and (github-client_id) (append query
(github-client_secret)) (if (and (github-client_id)
(list (cons 'client_id (github-client_id)) (github-client_secret))
(cons 'client_secret (github-client_secret))) (list (cons 'client_id (github-client_id))
empty)) (cons 'client_secret (github-client_secret)))
#f)) empty))
(download-printf "Querying GitHub ~a\n" kind) #f))
(log-pkg-debug "Querying GitHub at ~a" (url->string api-u)) (download-printf "Querying GitHub ~a\n" kind)
(define api-bs (log-pkg-debug "Querying GitHub at ~a" (url->string api-u))
(call/input-url+200 (define api-bs
api-u port->bytes (call/input-url+200
#:headers (list (format "User-Agent: raco-pkg/~a" (version))))) api-u port->bytes
(unless api-bs #:headers (list (format "User-Agent: raco-pkg/~a" (version)))))
(error 'package-url->checksum (unless api-bs
"could not connect to GitHub\n URL: ~a" (error 'package-url->checksum
(url->string api-u))) "could not connect to GitHub\n URL: ~a"
(define branches (url->string api-u)))
(read-json (open-input-bytes api-bs))) (define branches
(unless (and (list? branches) (read-json (open-input-bytes api-bs)))
(andmap hash? branches) (unless (and (list? branches)
(andmap (λ (b) (hash-has-key? b 'name)) branches) (andmap hash? branches)
(andmap (λ (b) (hash-has-key? b 'commit)) branches)) (andmap (λ (b) (hash-has-key? b 'name)) branches)
(error 'package-url->checksum (andmap (λ (b) (hash-has-key? b 'commit)) branches))
"Invalid response from Github: ~e" (error 'package-url->checksum
api-bs)) "Invalid response from Github: ~e"
(for/or ([b (in-list branches)]) api-bs))
(and (equal? (hash-ref b 'name) branch) (for/or ([b (in-list branches)])
(hash-ref (hash-ref b 'commit) 'sha))))] (and (equal? (hash-ref b 'name) branch)
(hash-ref (hash-ref b 'commit) 'sha))))
;; no matching branch/tag found, so if `branch' matches the
;; syntax of a commit id, then assume that it refers to a commit
(and (regexp-match? #rx"[a-f0-9]+" branch)
branch))]
[_ [_
(define u (string-append pkg-url-str ".CHECKSUM")) (define u (string-append pkg-url-str ".CHECKSUM"))
(download-printf "Downloading checksum for ~a\n" pkg-name) (download-printf "Downloading checksum for ~a\n" pkg-name)