git.fiddlerwoaroof.com
repository.lisp
4cc1ee49
 (in-package :fwoar.cl-git)
 
 (defun root-of (repo)
   (typecase repo
     (repository (root repo))
     ((or pathname string) (namestring
                            (truename repo)))))
 
ee4281cb
 (defun packed-ref (repo id)
744c84b5
   (multiple-value-bind (pack offset sha) (find-object-in-pack-files repo id)
ee4281cb
     (when pack
       (make-instance 'packed-ref
744c84b5
                      :hash sha
ee4281cb
                      :repo repo
                      :offset offset
                      :pack pack))))
 
15785ea0
 (defgeneric ref (repo id)
   (:documentation "Given a REPOsitory and a ref ID return the ref-id object.")
   (:method ((repo git-repository) (id string))
744c84b5
     (or (alexandria:when-let ((object-file (loose-object repo id)))
           (make-instance 'loose-ref
                          :repo repo
                          :hash (concatenate 'string
                                             (subseq id 0 2)
                                             (pathname-name object-file))
                          :file object-file))
         (packed-ref repo id))))
216c17e7
 
489818ad
 (defvar *ref-intern-table*
   (make-hash-table :test 'equal #+sbcl :weakness #+sbcl :key-and-value))
 
216c17e7
 (defun ensure-ref (thing &optional (repo *git-repository*))
   (typecase thing
     (git-ref thing)
489818ad
     (t (alexandria:when-let ((maybe-result (ref repo thing)))
          (alexandria:ensure-gethash (component :hash maybe-result)
                                     *ref-intern-table*
                                     maybe-result)))))
216c17e7
 
 (defun ensure-repository (thing)
c672c979
   (repository thing))