diff --git a/pkgs/racket-pkgs/racket-doc/pkg/scribblings/pkg.scrbl b/pkgs/racket-pkgs/racket-doc/pkg/scribblings/pkg.scrbl index 8d65088173..f36c2029c3 100644 --- a/pkgs/racket-pkgs/racket-doc/pkg/scribblings/pkg.scrbl +++ b/pkgs/racket-pkgs/racket-doc/pkg/scribblings/pkg.scrbl @@ -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 diff --git a/pkgs/racket-pkgs/racket-test/tests/pkg/tests-network.rkt b/pkgs/racket-pkgs/racket-test/tests/pkg/tests-network.rkt index daa3818b7e..afc2dcb4a5 100644 --- a/pkgs/racket-pkgs/racket-test/tests/pkg/tests-network.rkt +++ b/pkgs/racket-pkgs/racket-test/tests/pkg/tests-network.rkt @@ -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" diff --git a/racket/collects/pkg/util.rkt b/racket/collects/pkg/util.rkt index 8197d32327..b8ffd071ed 100644 --- a/racket/collects/pkg/util.rkt +++ b/racket/collects/pkg/util.rkt @@ -76,40 +76,45 @@ [(or "github" "git") (match-define (list* user repo branch path) (split-github-url pkg-url)) - (for/or ([kind '("branches" "tags")]) - (define api-u - (url "https" #f "api.github.com" #f #t - (map (λ (x) (path/param x empty)) - (list "repos" user repo kind)) - (append query - (if (and (github-client_id) - (github-client_secret)) - (list (cons 'client_id (github-client_id)) - (cons 'client_secret (github-client_secret))) - empty)) - #f)) - (download-printf "Querying GitHub ~a\n" kind) - (log-pkg-debug "Querying GitHub at ~a" (url->string api-u)) - (define api-bs - (call/input-url+200 - api-u port->bytes - #:headers (list (format "User-Agent: raco-pkg/~a" (version))))) - (unless api-bs - (error 'package-url->checksum - "could not connect to GitHub\n URL: ~a" - (url->string api-u))) - (define branches - (read-json (open-input-bytes api-bs))) - (unless (and (list? branches) - (andmap hash? branches) - (andmap (λ (b) (hash-has-key? b 'name)) branches) - (andmap (λ (b) (hash-has-key? b 'commit)) branches)) - (error 'package-url->checksum - "Invalid response from Github: ~e" - api-bs)) - (for/or ([b (in-list branches)]) - (and (equal? (hash-ref b 'name) branch) - (hash-ref (hash-ref b 'commit) 'sha))))] + (or + (for/or ([kind '("branches" "tags")]) + (define api-u + (url "https" #f "api.github.com" #f #t + (map (λ (x) (path/param x empty)) + (list "repos" user repo kind)) + (append query + (if (and (github-client_id) + (github-client_secret)) + (list (cons 'client_id (github-client_id)) + (cons 'client_secret (github-client_secret))) + empty)) + #f)) + (download-printf "Querying GitHub ~a\n" kind) + (log-pkg-debug "Querying GitHub at ~a" (url->string api-u)) + (define api-bs + (call/input-url+200 + api-u port->bytes + #:headers (list (format "User-Agent: raco-pkg/~a" (version))))) + (unless api-bs + (error 'package-url->checksum + "could not connect to GitHub\n URL: ~a" + (url->string api-u))) + (define branches + (read-json (open-input-bytes api-bs))) + (unless (and (list? branches) + (andmap hash? branches) + (andmap (λ (b) (hash-has-key? b 'name)) branches) + (andmap (λ (b) (hash-has-key? b 'commit)) branches)) + (error 'package-url->checksum + "Invalid response from Github: ~e" + api-bs)) + (for/or ([b (in-list branches)]) + (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")) (download-printf "Downloading checksum for ~a\n" pkg-name)