diff --git a/repo.lisp b/repo.lisp
index 63b465a..a0e9d99 100644
--- a/repo.lisp
+++ b/repo.lisp
@@ -9,18 +9,18 @@
(defpackage :repo
(:use :common-lisp)
(:export #:boot
- #:clear-repos
- #:find-repo
+ #:clear-repos
+ #:find-repo
#:git
#:github
- #:install
- #:manifest
- #:*manifest*
- #:repo
- #:*repo-dir*
- #:*repos*
- #:svn
- #:update))
+ #:install
+ #:manifest
+ #:*manifest*
+ #:repo
+ #:*repo-dir*
+ #:*repos*
+ #:svn
+ #:update))
(defpackage :repo-user
(:use :common-lisp :repo))
@@ -35,56 +35,56 @@
(defun string-starts-with (x string)
(let ((lx (length x))
- (ls (length string)))
+ (ls (length string)))
(when (and (>= ls lx)
- (string= x string :end2 lx))
+ (string= x string :end2 lx))
lx)))
(defun string-ends-with (x string)
(let* ((lx (length x))
- (ls (length string))
- (dl (- ls lx)))
+ (ls (length string))
+ (dl (- ls lx)))
(when (and (>= ls lx)
- (string= x string :start2 dl))
+ (string= x string :start2 dl))
dl)))
(defun string-split (s x)
(let ((p (search s x)))
(if p
- (cons (subseq x 0 p)
- (string-split s (subseq x (+ (length s) p))))
- (cons x nil))))
+ (cons (subseq x 0 p)
+ (string-split s (subseq x (+ (length s) p))))
+ (cons x nil))))
(defun first-line (x)
(let ((newline (position #\Newline x)))
(if newline
- (subseq x 0 newline)
- x)))
+ (subseq x 0 newline)
+ x)))
(defun dirname (x)
(let ((slash (position #\/ x :from-end t
- :end (or (string-ends-with "/" x) (length x)))))
+ :end (or (string-ends-with "/" x) (length x)))))
(cond ((null slash) "")
- ((= 0 slash) "/")
- (t (subseq x 0 slash)))))
+ ((= 0 slash) "/")
+ (t (subseq x 0 slash)))))
(defun basename (x)
(let* ((end (or (string-ends-with "/" x) (length x)))
- (slash (position #\/ x :from-end t :end end)))
+ (slash (position #\/ x :from-end t :end end)))
(cond ((null slash) (subseq x 0 end))
- (t (subseq x (1+ slash) end)))))
+ (t (subseq x (1+ slash) end)))))
(defun probe-dir (x)
(probe-file (format nil "~A/" x)))
(defun str (&rest parts)
(labels ((to-str (x)
- (typecase x
- (string x)
- (null "")
- (cons (apply 'str x))
- (pathname (namestring x))
- (t (prin1-to-string x)))))
+ (typecase x
+ (string x)
+ (null "")
+ (cons (apply 'str x))
+ (pathname (namestring x))
+ (t (prin1-to-string x)))))
(apply 'concatenate 'string (mapcar #'to-str parts))))
(defun kw (x)
@@ -102,22 +102,22 @@
(defun run-program (cmd &rest args)
(format t "~&$ ~A~{ ~A~}~%" cmd args)
(let ((out (make-string-output-stream))
- (err (make-string-output-stream)))
+ (err (make-string-output-stream)))
(let* ((process (sb-ext:run-program cmd args
- :output out
- :error err
- :external-format :utf-8))
- (exit-code (sb-ext:process-exit-code process)))
+ :output out
+ :error err
+ :external-format :utf-8))
+ (exit-code (sb-ext:process-exit-code process)))
(close out)
(close err)
(let ((out (get-output-stream-string out))
- (err (get-output-stream-string err)))
- (format t "~&~A~&" out)
- (format t "~&~A~&" err)
- (unless (= 0 exit-code)
- (with-simple-restart (continue "Ignore command error")
- (error "~&$ ~A~{ ~A~}~%~A" cmd args err)))
- (values out err exit-code)))))
+ (err (get-output-stream-string err)))
+ (format t "~&~A~&" out)
+ (format t "~&~A~&" err)
+ (unless (= 0 exit-code)
+ (with-simple-restart (continue "Ignore command error")
+ (error "~&$ ~A~{ ~A~}~%~A" cmd args err)))
+ (values out err exit-code)))))
#-windows
(defun sh (&rest parts)
@@ -137,28 +137,28 @@
(defun sh-quote (x)
(if (sh-need-quote x)
(with-output-to-string (out)
- (write-char #\" out)
- (dotimes (i (length x))
- (let ((c (char x i)))
- (when (find c *sh-quoted-chars*)
- (write-char #\\ out))
- (write-char c out)))
- (write-char #\" out))
+ (write-char #\" out)
+ (dotimes (i (length x))
+ (let ((c (char x i)))
+ (when (find c *sh-quoted-chars*)
+ (write-char #\\ out))
+ (write-char c out)))
+ (write-char #\" out))
x))
(defun sh-quote-dir (x)
(let ((home (string-starts-with "~/" x)))
(if home
- (str "~/" (sh-quote (subseq x home)))
- (sh-quote x))))
+ (str "~/" (sh-quote (subseq x home)))
+ (sh-quote x))))
;; property list functions
(defun plist-merge (to add &rest more-lists)
(cond
((endp add) (if (endp more-lists)
- to
- (plist-merge to (first more-lists) (rest more-lists))))
+ to
+ (plist-merge to (first more-lists) (rest more-lists))))
((endp (rest add)) (error "Incomplete property list"))
(t (setf (getf to (first add)) (first (rest add)))
(plist-merge to (rest (rest add))))))
@@ -174,27 +174,27 @@
(defclass repo ()
((dir :initarg :dir
- :reader repo-dir
- :type string)
+ :reader repo-dir
+ :type string)
(name :initarg :name
- :reader repo-name
- :type string)
+ :reader repo-name
+ :type string)
(head :initarg :head
- :initform nil
- :reader repo-head
- :type string)
+ :initform nil
+ :reader repo-head
+ :type string)
(uri :initarg :uri
- :reader repo-uri
- :type string)
+ :reader repo-uri
+ :type string)
(url :initarg :url
- :reader repo-url
- :type string)
+ :reader repo-url
+ :type string)
(local-dir :initarg :local-dir
- :reader repo-local-dir
- :type pathname)
+ :reader repo-local-dir
+ :type pathname)
(packages :initarg :packages
- :reader repo-packages
- :type list)))
+ :reader repo-packages
+ :type list)))
(defgeneric repo-asd (repo &optional package))
(defgeneric repo-dir/name (repo))
@@ -211,12 +211,12 @@
(declare (ignore initargs))
(with-slots (dir name packages) repo
(setf (slot-value repo 'local-dir)
- (format nil "~A/~A/~A" *repo-dir* dir name))
+ (format nil "~A/~A/~A" *repo-dir* dir name))
(unless (slot-boundp repo 'packages)
(setf packages (list name)))))
(defmethod repo-asd ((repo repo) &optional
- (package (first (repo-packages repo))))
+ (package (first (repo-packages repo))))
(str (translate-home (repo-local-dir repo)) "/"
(string-downcase package) ".asd"))
@@ -236,8 +236,8 @@
(defvar *git*
#+unix (or (probe-file "/usr/bin/git")
- (probe-file "/usr/local/bin/git")
- (first-line (sh "which git"))))
+ (probe-file "/usr/local/bin/git")
+ (first-line (sh "which git"))))
(defun $git (&rest args)
(apply 'run-program *git* args))
@@ -253,13 +253,13 @@
(defmethod $git-checkout ((repo git-repo))
(let ((local (repo-local-dir repo))
- (head (repo-head repo)))
+ (head (repo-head repo)))
($git "-C" (translate-home local) "checkout" (str head))
nil))
(defmethod $git-clone ((repo git-repo))
(let ((local (repo-local-dir repo))
- (url (repo-url repo)))
+ (url (repo-url repo)))
(when (probe-dir local)
(error "git clone: not overwriting existing local directory~&~S" local))
(let ((parent (dirname local)))
@@ -291,17 +291,17 @@
(defun git-repo-uri-handler (uri)
(let ((uri (first (string-split "#" uri))))
(let ((start (or (string-starts-with "git://" uri)
- (string-starts-with "http://" uri)
- (string-starts-with "https://" uri))))
+ (string-starts-with "http://" uri)
+ (string-starts-with "https://" uri))))
(when start
- (let* ((dot (search ".git" uri :from-end t))
- (slash (position #\/ uri :end dot :from-end t))
- (slash2 (position #\/ uri :end slash :from-end t))
- (dir (subseq uri (1+ slash2) slash))
- (name (subseq uri (1+ slash) dot)))
- `(git-repo :dir ,dir :name ,name
- :uri ,uri
- :url ,uri))))))
+ (let* ((dot (search ".git" uri :from-end t))
+ (slash (position #\/ uri :end dot :from-end t))
+ (slash2 (position #\/ uri :end slash :from-end t))
+ (dir (subseq uri (1+ slash2) slash))
+ (name (subseq uri (1+ slash) dot)))
+ `(git-repo :dir ,dir :name ,name
+ :uri ,uri
+ :url ,uri))))))
(defun git (url &rest initargs)
(or (repo-by-url url)
@@ -330,20 +330,20 @@
(defun github-repo-uri-handler (uri)
(let ((uri (first (string-split "#" uri))))
(let ((start (or (string-starts-with "github:" uri)
- (string-starts-with "git://github.com/" uri)
- (string-starts-with "http://github.com/" uri)
- (string-starts-with "https://github.com/" uri))))
+ (string-starts-with "git://github.com/" uri)
+ (string-starts-with "http://github.com/" uri)
+ (string-starts-with "https://github.com/" uri))))
(when start
- (let* ((slash (or (position #\/ uri :start start)
- (error "Invalid repo uri ~S" uri)))
- (dot (or (string-ends-with ".git/" uri)
- (string-ends-with ".git" uri)
- (string-ends-with "/" uri)))
- (user (subseq uri start slash))
- (name (subseq uri (1+ slash) dot)))
- `(github-repo :dir ,user :name ,name
- :uri ,(github-uri user name)
- :url ,(github-url user name)))))))
+ (let* ((slash (or (position #\/ uri :start start)
+ (error "Invalid repo uri ~S" uri)))
+ (dot (or (string-ends-with ".git/" uri)
+ (string-ends-with ".git" uri)
+ (string-ends-with "/" uri)))
+ (user (subseq uri start slash))
+ (name (subseq uri (1+ slash) dot)))
+ `(github-repo :dir ,user :name ,name
+ :uri ,(github-uri user name)
+ :url ,(github-url user name)))))))
(defun github (user name &rest initargs)
(let ((uri (github-uri user name)))
@@ -360,8 +360,8 @@
(defvar *svn*
#+unix (or (probe-file "/usr/bin/svn")
- (probe-file "/usr/local/bin/svn")
- (first-line (sh "which svn"))))
+ (probe-file "/usr/local/bin/svn")
+ (first-line (sh "which svn"))))
(defun $svn (&rest args)
(apply 'run-program *svn* args))
@@ -375,7 +375,7 @@
(defmethod $svn-checkout ((repo svn-repo))
(let ((local (repo-local-dir repo))
- (url (repo-url repo)))
+ (url (repo-url repo)))
(when (probe-dir local)
(error "svn checkout: not overwriting existing local directory~&~S" local))
(let ((parent (dirname local)))
@@ -401,11 +401,11 @@
(defun svn (url dir/name &rest initargs)
(or (repo-by-url url)
(let ((repo (apply #'make-instance 'svn-repo
- :dir (dirname dir/name)
- :name (basename dir/name)
- :url url :uri url
- :head (basename url)
- initargs)))
+ :dir (dirname dir/name)
+ :name (basename dir/name)
+ :url url :uri url
+ :head (basename url)
+ initargs)))
(push repo *repos*)
repo)))
@@ -421,9 +421,9 @@
(defun find-repo (uri)
(let ((uri (string uri)))
(or (find uri *repos* :key 'repo-uri :test 'string=)
- (if (position #\/ uri)
- (find uri *repos* :key 'repo-dir/name :test 'string-equal)
- (find uri *repos* :key 'repo-name :test 'string-equal)))))
+ (if (position #\/ uri)
+ (find uri *repos* :key 'repo-dir/name :test 'string-equal)
+ (find uri *repos* :key 'repo-name :test 'string-equal)))))
(defun find-repo-by-package (x)
(find x *repos* :test #'repo-package-p))
@@ -437,24 +437,24 @@
(setq uri (symbol-name uri)))
(destructuring-bind (uri &rest packages) (string-split " " uri)
(or (find-repo uri)
- (when (stringp uri)
- (labels ((do-handlers (handlers)
- (when handlers
- (or (funcall (first handlers) uri)
- (do-handlers (rest handlers))))))
- (let ((spec (do-handlers *repo-uri-handlers*)))
- (when spec
- (let* ((class (first spec))
- (initargs (rest spec))
- (uri (getf initargs :uri))
- (kw (kw (getf initargs :name)))
- (initargs (plist-merge initargs
- `(:packages ,(or packages
- `(,kw))))))
- (or (find-repo uri)
- (let ((repo (apply 'make-instance class initargs)))
- (push repo *repos*)
- repo))))))))))
+ (when (stringp uri)
+ (labels ((do-handlers (handlers)
+ (when handlers
+ (or (funcall (first handlers) uri)
+ (do-handlers (rest handlers))))))
+ (let ((spec (do-handlers *repo-uri-handlers*)))
+ (when spec
+ (let* ((class (first spec))
+ (initargs (rest spec))
+ (uri (getf initargs :uri))
+ (kw (kw (getf initargs :name)))
+ (initargs (plist-merge initargs
+ `(:packages ,(or packages
+ `(,kw))))))
+ (or (find-repo uri)
+ (let ((repo (apply 'make-instance class initargs)))
+ (push repo *repos*)
+ repo))))))))))
(defun repo-or-die (x)
(or (repo x)
@@ -480,14 +480,14 @@
(defclass manifest ()
((write-date :initarg :write-date
- :accessor manifest-write-date
- :type rational)
+ :accessor manifest-write-date
+ :type rational)
(dir :initarg :dir
- :reader manifest-dir
- :type string)
+ :reader manifest-dir
+ :type string)
(repos :initarg :repos
- :accessor manifest-repos
- :type list)))
+ :accessor manifest-repos
+ :type list)))
(defgeneric manifest-file (manifest))
(defgeneric reload-manifest (manifest))
@@ -496,46 +496,46 @@
(defmethod print-object ((obj manifest) stream)
(print-unreadable-object (obj stream :type t :identity t)
(format stream "~S ~A repos"
- (manifest-file obj)
- (length (manifest-repos obj)))))
+ (manifest-file obj)
+ (length (manifest-repos obj)))))
(defmethod manifest-file ((manifest manifest))
(str (manifest-dir manifest) "/repo.manifest"))
(defun manifest-from-file (pathname)
(let ((*repos* nil)
- (write-date (file-write-date pathname)))
+ (write-date (file-write-date pathname)))
(load pathname)
(make-instance 'manifest
- :write-date write-date
- :dir (dirname pathname)
- :repos *repos*)))
+ :write-date write-date
+ :dir (dirname pathname)
+ :repos *repos*)))
(defmethod reload-manifest ((manifest manifest))
(let* ((pathname (manifest-file manifest))
- (*repos* nil)
- (write-date (file-write-date pathname)))
+ (*repos* nil)
+ (write-date (file-write-date pathname)))
(load pathname)
(setf (manifest-write-date manifest) write-date
- (manifest-repos manifest) *repos*))
+ (manifest-repos manifest) *repos*))
manifest)
(defmethod maybe-reload-manifest ((manifest manifest))
(if (< (manifest-write-date manifest)
- (file-write-date (manifest-file manifest)))
+ (file-write-date (manifest-file manifest)))
(reload-manifest manifest)
manifest))
(defmethod install ((manifest manifest))
(let ((manifest (maybe-reload-manifest manifest)))
(let ((*repo-dir* (manifest-dir manifest))
- (*repos* (manifest-repos manifest)))
+ (*repos* (manifest-repos manifest)))
(install *repos*))))
(defmethod update ((manifest manifest))
(let ((manifest (maybe-reload-manifest manifest)))
(let ((*repo-dir* (manifest-dir manifest))
- (*repos* (manifest-repos manifest)))
+ (*repos* (manifest-repos manifest)))
(update *repos*))))
;; manifest uri handlers
@@ -548,9 +548,9 @@
(let ((end (string-ends-with "/repo.manifest" x)))
(when end
(let* ((*repo-dir* (subseq x 0 end))
- (manifest (str *repo-dir* "/repo.manifest")))
- (when (probe-file manifest)
- (manifest-from-file manifest))))))
+ (manifest (str *repo-dir* "/repo.manifest")))
+ (when (probe-file manifest)
+ (manifest-from-file manifest))))))
(defvar *manifest-uri-handlers*
'(local-manifest-uri-handler))
@@ -558,9 +558,9 @@
(defun manifest (uri)
"Load manifest from uri"
(labels ((do-handlers (handlers)
- (unless (endp handlers)
- (or (funcall (first handlers) uri)
- (do-handlers (rest handlers))))))
+ (unless (endp handlers)
+ (or (funcall (first handlers) uri)
+ (do-handlers (rest handlers))))))
(do-handlers *manifest-uri-handlers*)))
(defun manifest-or-die (uri)
@@ -612,7 +612,7 @@
(maybe-reload-manifest *manifest*))
(setq *repos* (manifest-repos *manifest*))
(let ((repo (or (find-repo-by-package x)
- (repo x))))
+ (repo x))))
(when repo
(install repo)
(pathname (repo-asd repo x)))))
@@ -625,4 +625,4 @@
(setq *manifest* (manifest manifest-file))
(setq *repos* (manifest-repos *manifest*))
(when (find-package :asdf)
- (pushnew 'sysdef asdf:*system-definition-search-functions*)))))
+ (pushnew 'sysdef asdf:*system-definition-search-functions*)))))