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)))))
 
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
067909ff
     (fwoar.cl-git.ref: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))