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}@;
@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
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}.
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:
@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
GitHub for every branch and tag) is used as a remote URL archive path,
except the @tech{checksum} is the hash identifying the branch (or
tag).
GitHub for any commit) is used as a remote URL archive path. The
@tech{checksum} is the hash identifying @nonterm{rev} if @nonterm{rev}
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
starts with @litchar{git://} or @litchar{github://}; a package source that is otherwise

View File

@ -30,6 +30,10 @@
"remote/github with tag"
"git://github.com/mflatt/pkg-test?path=pkg-test1/#hundred"
$ "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
"remote/github with checksum"
"--checksum f9b4eef22cdd9ab88b254cb027fc1ebe7fb596fd git://github.com/mflatt/pkg-test?path=pkg-test1"

View File

@ -76,6 +76,7 @@
[(or "github" "git")
(match-define (list* user repo branch path)
(split-github-url pkg-url))
(or
(for/or ([kind '("branches" "tags")])
(define api-u
(url "https" #f "api.github.com" #f #t
@ -109,7 +110,11 @@
api-bs))
(for/or ([b (in-list branches)])
(and (equal? (hash-ref b 'name) branch)
(hash-ref (hash-ref b 'commit) 'sha))))]
(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"))
(download-printf "Downloading checksum for ~a\n" pkg-name)