git.fiddlerwoaroof.com
porcelain.lisp
991d0162
 (in-package :fwoar.cl-git)
 
 (defvar *git-repository* nil
   "The git repository path for porcelain commands to operate on.")
 (defvar *git-encoding* :utf-8
   "The encoding to use when parsing git objects")
 
e623be68
 (defun git:in-repository (root)
   (setf *git-repository*
         (truename root)))
 
ad9b8a82
 (defun git:show-repository ()
   *git-repository*)
 
0b3ed859
 (defmacro git:git (&rest commands)
   `(uiop:nest ,@(reverse
                  (mapcar (serapeum:op (case (car _1)
                                         ((<<=) (list* 'mapcan
                                                       (list 'quote
                                                             (intern (symbol-name (cadadr _1))
                                                                     :git))
                                                       (cddr _1)))
e98a5866
                                         ((map) (list* 'mapcar (cdr _1)))
                                         ((unwrap) `(uiop:nest (car)
                                                               (mapcar ,@(cdr _1))))
0b3ed859
                                         (t (cons (intern (symbol-name (car _1))
                                                          :git)
                                                  (cdr _1)))))
                          commands))))
 
e623be68
 (defun git:show (object)
   (babel:octets-to-string
0b3ed859
    (coerce (extract-object (repository *git-repository*)
                            object)
            '(vector serapeum:octet))
e623be68
    :encoding *git-encoding*))
 
5cb25684
 (defun git:contents (object)
   (git:show object))
 
 (defstruct (tree-entry (:type vector))
   te-name te-mode te-id)
 
 (defun git:tree (commit)
   (cadr (fw.lu:v-assoc "tree"
                        (nth-value 1 (parse-commit commit))
                        :test 'equal)))
 
 (defun git::filter-tree (name-pattern tree)
   #+lispworks
   (declare (notinline serapeum:string-prefix-p))
   (let* ((lines (fwoar.string-utils:split #\newline tree))
          (columns (map 'list
                        (serapeum:op
                          (coerce (fwoar.string-utils:split #\tab _)
                                  'simple-vector))
                        lines)))
     (remove-if-not (serapeum:op
                      (serapeum:string-prefix-p name-pattern _))
                    columns
                    :key #'tree-entry-te-name)))
 
e623be68
 (defun git:branch (&optional (branch "master"))
0b3ed859
   #+lispworks
   (declare (notinline serapeum:assocadr))
e623be68
   (let ((branches (branches (repository *git-repository*))))
     (nth-value 0 (serapeum:assocadr branch branches
                                     :test 'equal))))
 
 (defun git:branches ()
   (branches (repository *git-repository*)))
 
 (defun git:commit-parents (commit)
   (map 'list #'cadr
        (remove-if-not (serapeum:op
                         (string= "parent" _))
                       (nth-value 1
                                  (fwoar.cl-git::parse-commit
                                   (git:show commit)))
                       :key #'car)))