git.fiddlerwoaroof.com
Browse code

Add README, polish porcelain

Ed Langley authored on 12/07/2019 01:55:34
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,71 @@
1
+* CL-GIT: the pure lisp interface to Git objects
2
+** Introduction
3
+
4
+   Git libraries for Common Lisp common in a couple forms. Some attempt
5
+   to wrap the libgit2 git library
6
+   (e.g. https://github.com/russell/cl-git).  Others wrap the git binary
7
+   in a subprocess (e.g. http://shinmera.github.io/legit/).  Such
8
+   libraries work well in cases where you control the environment but
9
+   not all lisp programs run in such circumstances.  This library, on the
10
+   contrary, attempts to implement parsers for git's file formats as well
11
+   as a thin "porcelain" interface for manipulating git objects.
12
+
13
+** Installation
14
+   
15
+   #+BEGIN_SRC sh
16
+     git clone https://github.com/fiddlerwoaroof/cl-git.git "$HOME/quicklisp/local-projects/cl-git"
17
+     sbcl --load "$HOME/quicklisp/setup.lisp"
18
+     CL-USER> (ql:quickload :cl-git)
19
+   #+END_SRC
20
+
21
+** Example usage
22
+
23
+*** Get the commit id of the master branch for a specific repository:
24
+
25
+    #+BEGIN_SRC lisp
26
+      (git:in-repository "~/quicklisp/local-projects/cl-git")
27
+      (git:git (branch "master")) ;; the argument to branch defaults to "master"
28
+    #+END_SRC 
29
+
30
+    #+RESULTS:
31
+    : 077088c8c359489ed1f6d8e441ec76438076542e
32
+
33
+    
34
+*** Show the commit message
35
+
36
+    #+BEGIN_SRC lisp
37
+      (git:in-repository "~/quicklisp/local-projects/cl-git")
38
+      (git:git (branch "master") ;; the argument to branch defaults to "master"
39
+               (show))
40
+    #+END_SRC 
41
+
42
+    #+RESULTS:
43
+    : tree e70a61be268cbaa6a7825295fbe54beaa3c59c71
44
+    : parent e1f7c67a8774d65bb941eeb2b41f71f333fa1a94
45
+    : author Ed Langley <el-github@elangley.org> 1562893971 -0700
46
+    : committer Ed Langley <el-github@elangley.org> 1562893971 -0700
47
+    : 
48
+    : (bump)
49
+
50
+*** Show the messages of the commit's parent
51
+
52
+    #+BEGIN_SRC lisp
53
+      (git:in-repository "~/quicklisp/local-projects/cl-git")
54
+      (git:git (branch "master") ;; the argument to branch defaults to "master"
55
+               (commit-parents) 
56
+               (map 'git:show)
57
+               (<<= 'identity))
58
+    #+END_SRC 
59
+
60
+    #+RESULTS:
61
+    : tree 9c8827bc556311dd4a71ec6ccc08860b1b415676
62
+    : parent ff33293b415cc1907a6071650d045b3dffd8e5c0
63
+    : author Ed Langley <el-github@elangley.org> 1558056528 -0700
64
+    : committer Ed Langley <el-github@elangley.org> 1558056528 -0700
65
+    : 
66
+    : Fix .asd
67
+
68
+    
69
+** Not Implemented Yet:
70
+
71
+- Delta refs
... ...
@@ -12,23 +12,26 @@
12 12
 (defun git:show-repository ()
13 13
   *git-repository*)
14 14
 
15
+(defun in-git-package (symbol)
16
+  (intern (symbol-name symbol)
17
+          :git))
18
+
15 19
 (defmacro git:git (&rest commands)
16 20
   `(uiop:nest ,@(reverse
17
-                 (mapcar (serapeum:op (typecase _1
21
+                 (mapcar (serapeum:op (format t "~&~s~%" (symbol-package (car _1)))
22
+                                      (typecase _1
18 23
                                         (string `(identity ,_1))
19 24
                                         (list (case (car _1)
20
-                                                ((<<=) (list* 'mapcan
21
-                                                              (list 'quote
22
-                                                                    (cadadr _1))
23
-                                                              (cddr _1)))
24 25
                                                 ((map) (list* 'mapcar (cdr _1)))
25 26
                                                 ((unwrap) `(uiop:nest (car)
26 27
                                                                       (mapcar ,@(cdr _1))))
27
-                                                (t (cons (intern (symbol-name (car _1))
28
-                                                                 :git)
28
+                                                (t (cons (in-git-package (car _1)) 
29 29
                                                          (cdr _1)))))))
30 30
                          commands))))
31 31
 
32
+(defun git::<<= (fun &rest args)
33
+  (apply #'mapcan fun args))
34
+
32 35
 (defun git:show (object)
33 36
   (babel:octets-to-string
34 37
    (coerce (extract-object (repository *git-repository*)
... ...
@@ -57,15 +60,18 @@
57 60
                                  'simple-vector))
58 61
                        lines)))
59 62
     (remove-if-not (serapeum:op
60
-                     (serapeum:string-prefix-p name-pattern _))
63
+                     (cl-ppcre:scan name-pattern _ ))
61 64
                    columns
62 65
                    :key #'tree-entry-te-name)))
63 66
 
64
-(defun git:branch (&optional (branch "master"))
67
+(defun git:branch (&optional (branch :master))
65 68
   #+lispworks
66 69
   (declare (notinline serapeum:assocadr))
67 70
   (let ((branches (branches (repository *git-repository*))))
68
-    (nth-value 0 (serapeum:assocadr branch branches
71
+    (nth-value 0 (serapeum:assocadr (etypecase branch
72
+                                      (string branch)
73
+                                      (keyword (string-downcase branch)))
74
+                                    branches
69 75
                                     :test 'equal))))
70 76
 
71 77
 (defun git:branches ()