Skip to content

Commit e4dee57

Browse files
committed
When making an archive, include full git submodules too
Making use of this requires using git checkouts instead of tarball fetches wherever possible.
1 parent 53ed840 commit e4dee57

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

upstream-git.lisp

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,61 @@
6363
(:method ((source git-at-commit-source))
6464
(format nil "~A" (commit source))))
6565

66+
(defstruct (submodule (:type vector))
67+
name
68+
path
69+
sha1)
70+
71+
(defun git-submodules (git-path)
72+
(loop for line in
73+
(run-output-lines "git" "-C" (truename git-path) "submodule"
74+
"--quiet"
75+
"foreach"
76+
"--recursive"
77+
"echo $name $sha1 $displaypath")
78+
for (name sha1 path) = (split-spaces line)
79+
collect (make-submodule :name name :path path :sha1 sha1)))
80+
81+
(defun full-git-archive (git-path target-ref prefix output-file)
82+
"Create a tarball archive in OUTPUT-FILE of the full contents of the
83+
git checkout GIT-PATH, including submodules. The repo is archived at
84+
TARGET-REF, e.g. 'HEAD'. "
85+
(run "git" "-C" (truename git-path)
86+
"submodule" "update" "--init" "--recursive")
87+
(let ((submodules (git-submodules git-path)))
88+
(in-temporary-directory prefix
89+
(let* ((temp-base *default-pathname-defaults*))
90+
(with-posix-cwd git-path
91+
(run "git" "archive"
92+
:format "tar"
93+
:prefix (format nil "~A/" prefix)
94+
"-o" (make-pathname :name (string-right-trim "/" prefix)
95+
:type "tar"
96+
:defaults temp-base)
97+
target-ref)
98+
(dolist (submodule submodules)
99+
(with-posix-cwd (submodule-path submodule)
100+
(let ((output (make-pathname :name (submodule-name submodule)
101+
:type "tar"
102+
:defaults temp-base)))
103+
(run "git" "archive"
104+
:format "tar"
105+
"-o" output
106+
:prefix (format nil "~A/~A/"
107+
prefix (submodule-path submodule))
108+
(submodule-sha1 submodule))))))
109+
;; Back in the temp directory
110+
(dolist (tarball (directory "*.tar"))
111+
(run "tar" "xf" tarball))
112+
(let ((combined "combined.tar")
113+
(combined-tgz "combined.tar.gz"))
114+
(run "tar" "cf" combined prefix)
115+
(run "gzip" "-vn9" "-S" ".gz" combined)
116+
(rename-file combined-tgz output-file))
117+
output-file))))
118+
66119
(defmethod make-release-tarball ((source git-source) output-file)
67120
(let ((prefix (release-tarball-prefix source))
68121
(checkout (ensure-source-cache source)))
69-
(in-temporary-directory prefix
70-
(let ((temptar (merge-pathnames "package.tar"))
71-
(tempgz (merge-pathnames "package.tar.gz")))
72-
(with-posix-cwd checkout
73-
(with-binary-run-output temptar
74-
(run "git" "archive" :format "tar" :prefix prefix
75-
(target-ref source)))
76-
(run "gzip" "-vn9" temptar)
77-
(copy tempgz output-file))))))
122+
(full-git-archive checkout (target-ref source) prefix output-file)))
78123

upstream-github.lisp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
:tag (githappy:jref json '(0 "name"))))))
2929

3030

31-
(defclass latest-github-release-source (http-source)
31+
(defclass latest-github-release-source (git-source)
3232
((release-url
3333
:initarg :release-url
3434
:accessor release-url)
3535
(release-tag
3636
:initarg :release-tag
37-
:accessor release-tag)))
37+
:accessor release-tag
38+
:reader tag-data
39+
:reader target-ref)))
3840

3941
(defclass latest-github-tag-source (latest-github-release-source)
4042
())
@@ -69,10 +71,7 @@
6971
(defmethod release-tarball-prefix ((source latest-github-release-source))
7072
(format nil "~A-~A/" (name source) (release-tag source)))
7173

72-
(defmethod create-source-cache ((source latest-github-release-source))
73-
(let ((cached (cache-object-file source)))
74-
(ensure-directories-exist cached)
75-
(curl (release-url source) cached)
76-
(repack cached (release-tarball-prefix source) cached)
77-
(probe-file cached)))
78-
74+
(defmethod parse-location ((source latest-github-release-source)
75+
location-string)
76+
(setf (location source) location-string)
77+
source)

0 commit comments

Comments
 (0)