git.fiddlerwoaroof.com
Browse code

feat: clean up porcelain, update README

Ed Langley authored on 08/05/2020 07:17:21
Showing 2 changed files
... ...
@@ -11,7 +11,7 @@
11 11
    as a thin "porcelain" interface for manipulating git objects.
12 12
 
13 13
 ** Installation
14
-   
14
+
15 15
    #+BEGIN_SRC sh
16 16
      % git clone https://github.com/fiddlerwoaroof/fwoar.lisputils.git "$HOME/quicklisp/local-projects/fwoar-lisputils"
17 17
      % git clone https://github.com/fiddlerwoaroof/cl-git.git "$HOME/quicklisp/local-projects/cl-git"
... ...
@@ -23,73 +23,73 @@
23 23
 
24 24
 *** Get the commit id of the master branch for a specific repository:
25 25
 
26
-    #+BEGIN_SRC lisp :exports both
26
+    #+BEGIN_SRC lisp :exports both :results verbatim
27 27
       (git:in-repository "~/quicklisp/local-projects/cl-git")
28 28
       (git:git (branch "master")) ;; the argument to branch defaults to "master"
29
-    #+END_SRC 
29
+    #+END_SRC
30 30
 
31 31
     #+RESULTS:
32
-    : 821ddf96c37e65ccc9a0f4bfe2b8ac6e255a2cb6
32
+    : #<LOOSE-REF 4d4ea31 of ~/git_repos/cl-git/>
33
+
33 34
 
34
-    
35 35
 *** Show the commit message
36 36
 
37
-    #+BEGIN_SRC lisp :exports both
37
+    #+BEGIN_SRC lisp :exports both :results verbatim
38 38
       (git:in-repository "~/quicklisp/local-projects/cl-git")
39 39
       (git:git (branch "master") ;; the argument to branch defaults to "master"
40
-               (show))
41
-    #+END_SRC 
40
+               (component :message))
41
+    #+END_SRC
42 42
 
43 43
     #+RESULTS:
44
-    : tree a7cbe10af08aed7b24b633649db6dc4cec011a3f
45
-    : parent 077088c8c359489ed1f6d8e441ec76438076542e
46
-    : author Ed Langley <el-github@elangley.org> 1562896534 -0700
47
-    : committer Ed Langley <el-github@elangley.org> 1562896534 -0700
48
-    : 
49
-    : Add README, polish porcelain
44
+    : doc: Complete installation instruction
50 45
 
51 46
 *** Show the messages of the commit's parent
52 47
 
53
-    #+BEGIN_SRC lisp :exports both
48
+    #+BEGIN_SRC lisp :exports both :results verbatim
54 49
       (git:in-repository "~/quicklisp/local-projects/cl-git")
55 50
       (git:git (branch "master") ;; the argument to branch defaults to "master"
56
-               (commit-parents) 
57
-               (map 'git:show)
58
-               (<<= 'identity))
59
-    #+END_SRC 
51
+               (commit-parents))
52
+    #+END_SRC
60 53
 
61 54
     #+RESULTS:
62
-    : tree e70a61be268cbaa6a7825295fbe54beaa3c59c71
63
-    : parent e1f7c67a8774d65bb941eeb2b41f71f333fa1a94
64
-    : author Ed Langley <el-github@elangley.org> 1562893971 -0700
65
-    : committer Ed Langley <el-github@elangley.org> 1562893971 -0700
66
-    : 
67
-    : (bump)
55
+    : (("7df80f061ae5bf6177a1c0888d085281be2801e1"))
68 56
 
69 57
 *** Show the files in a commit
70 58
 
71
-    #+BEGIN_SRC lisp :exports both
59
+    #+BEGIN_SRC lisp :exports both :results table :hlines yes
72 60
       (git:in-repository "~/quicklisp/local-projects/cl-git")
73 61
       (list* #("name" "mode" "hash")
74 62
              (git:git (branch "master")
75
-                      (contents)
76
-                      (tree)
77
-                      (contents)
78
-                      (filter-tree ".*.lisp")))
63
+                      (component :tree :entries)
64
+                      (map (juxt (component :name)
65
+                                 (component :mode)
66
+                                 (component :hash)))))
79 67
     #+END_SRC
80 68
 
81 69
     #+RESULTS:
82 70
     | name           |   mode | hash                                     |
71
+    | .gitignore     | 100644 | 8a9fe9f77149f74fed5c05388be8e5ffd4a31678 |
72
+    | .projectile    | 100644 | e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 |
73
+    | LICENSE        | 100644 | 0306819e780fa57dc3bf6b99a0a059670b605ae0 |
74
+    | README.org     | 100644 | a52be677adeda194bcdfdd12740f00535b6b0997 |
83 75
     | branch.lisp    | 100644 | e06b66967fa4fa005ccf00dcbc7d839b22259593 |
84
-    | extract.lisp   | 100644 | e69272bd90575f4dc99801a06287531bf2d09017 |
85
-    | git.lisp       | 100644 | 6e4821d169fc505dd2b598d4bf4bdfc512ea6ebd |
86
-    | graph.lisp     | 100644 | a4220a28d4800e38b8b8f85db0d97afc8b889293 |
87
-    | model.lisp     | 100644 | dbfe85d03296435b4a33ef3dc26456080e3f0263 |
76
+    | cl-git.asd     | 100644 | 9db42f61f21e11529b9bc1c52ee118c03d663c04 |
77
+    | extract.lisp   | 100644 | cf8e6e10786a26ffcd6a3e0fdb97abdf1c9f0345 |
78
+    | git.lisp       | 100644 | c516dfc248544509c3ae58e3a8c2ab81c225aa9c |
79
+    | graph.lisp     | 100644 | 31576396aff0fff28f69e0ef84571c0dc8cc43ec |
80
+    | model.lisp     | 100644 | fb265bb344fee602dc175d1d5eac6bdc2d013a10 |
88 81
     | package.lisp   | 100644 | d2818bb88b8ec5235a8ae91309f31ba58d941d42 |
89
-    | porcelain.lisp | 100644 | c1b83741c4dc3104f1686c20b143300db0a0e258 |
82
+    | porcelain.lisp | 100644 | 0673dcbe10b945d561a9c3c485fe28aab12b257c |
90 83
     | undelta.lisp   | 100644 | ae0a070133d1a14d6e940a0f790f40b37e885b22 |
91 84
     | util.lisp      | 100644 | 87c2b9b2dfaa1fbf66b3fe88d3a925593886b159 |
92
-    
93
-** Not Implemented Yet:
94 85
 
95
-- Delta refs
86
+** Partially Implemented:
87
+
88
+*** Delta refs
89
+    Git uses a [[https://git-scm.com/docs/pack-format#_deltified_representation][delta calculation]] routine to compress some of the blobs
90
+    in a pack file. This delta stores a reference to a base object and
91
+    a sequence of commands for transforming the base object into the
92
+    new object. My plan to support this is to first just extract the
93
+    commands from the pack file and store them as a [[file:delta.lisp::(defclass delta () ((%repository :initarg :repository :reader repository) (%base :initarg :base :reader base) (%commands :initarg :commands :reader commands)))][delta object]]. When
94
+    this works adequately, I'll write an interpreter to do the actual
95
+    merge.
... ...
@@ -9,6 +9,10 @@
9 9
   (setf *git-repository*
10 10
         (truename root)))
11 11
 
12
+(defmacro git:with-repository ((root) &body body)
13
+  `(let ((*git-repository* (truename ,root)))
14
+     ,@body))
15
+
12 16
 (defun git:show-repository ()
13 17
   *git-repository*)
14 18
 
... ...
@@ -24,22 +28,49 @@
24 28
                              (list (case (in-git-package (car _1))
25 29
                                      (git::unwrap `(uiop:nest (car)
26 30
                                                               (mapcar ,@(cdr _1))))
27
-                                     (t (cons (in-git-package (car _1)) 
31
+                                     (t (cons (in-git-package (car _1))
28 32
                                               (cdr _1)))))))
29 33
                          commands))))
30 34
 
35
+(defun git::ensure-ref (it)
36
+  (ensure-ref it))
37
+
31 38
 (defun git::<<= (fun &rest args)
32 39
   (apply #'mapcan fun args))
33 40
 
34
-(defun git::map (fun &rest args)
35
-  (apply #'mapcar fun args))
41
+(defmacro git::map (fun list)
42
+  (alexandria:once-only (list)
43
+    (alexandria:with-gensyms (it)
44
+      `(mapcar ,(if (consp fun)
45
+                    `(lambda (,it)
46
+                       (,(in-git-package (car fun))
47
+                        ,@(cdr fun)
48
+                        ,it))
49
+                    `',(in-git-package fun))
50
+               ,list))))
51
+
52
+(defmacro git::juxt (&rest args)
53
+  (let ((funs (butlast args))
54
+        (arg (car (last args))))
55
+    (alexandria:once-only (arg)
56
+      `(list ,@(mapcar (lambda (f)
57
+                         `(,@(alexandria:ensure-list f) ,arg))
58
+                       funs)))))
59
+
60
+(defun git::filter (fun &rest args)
61
+  (apply #'remove-if-not fun args))
62
+
63
+(defun ensure-ref (thing &optional (repo (repository *git-repository*)))
64
+  (typecase thing
65
+    (git-ref thing)
66
+    (t (ref repo thing))))
67
+
68
+(defun git::object (thing)
69
+  (extract-object thing))
36 70
 
37 71
 (defun git:show (object)
38
-  (babel:octets-to-string
39
-   (coerce (extract-object-next (object (repository *git-repository*)
40
-                                        object))
41
-           '(vector serapeum:octet))
42
-   :encoding *git-encoding*))
72
+  (extract-object
73
+   object))
43 74
 
44 75
 (defun git:contents (object)
45 76
   (git:show object))
... ...
@@ -47,10 +78,14 @@
47 78
 (defstruct (tree-entry (:type vector))
48 79
   te-name te-mode te-id)
49 80
 
50
-(defun git:tree (commit)
51
-  (cadr (fw.lu:v-assoc "tree"
52
-                       (nth-value 1 (parse-commit commit))
53
-                       :test 'equal)))
81
+(defun git:component (&rest args)
82
+  (let ((component-list (butlast args))
83
+        (target (car (last args))))
84
+    (fwoar.cl-git::component component-list target)))
85
+
86
+(defun git:tree (commit-object)
87
+  (component :tree
88
+             commit-object))
54 89
 
55 90
 (defun git::filter-tree (name-pattern tree)
56 91
   #+lispworks
... ...
@@ -70,20 +105,15 @@
70 105
   #+lispworks
71 106
   (declare (notinline serapeum:assocadr))
72 107
   (let ((branches (branches (repository *git-repository*))))
73
-    (nth-value 0 (serapeum:assocadr (etypecase branch
74
-                                      (string branch)
75
-                                      (keyword (string-downcase branch)))
76
-                                    branches
77
-                                    :test 'equal))))
108
+    (ref (repository *git-repository*)
109
+         (serapeum:assocadr (etypecase branch
110
+                              (string branch)
111
+                              (keyword (string-downcase branch)))
112
+                            branches
113
+                            :test 'equal))))
78 114
 
79 115
 (defun git:branches ()
80 116
   (branches (repository *git-repository*)))
81 117
 
82 118
 (defun git:commit-parents (commit)
83
-  (map 'list #'cadr
84
-       (remove-if-not (serapeum:op
85
-                        (string= "parent" _))
86
-                      (nth-value 1
87
-                                 (fwoar.cl-git::parse-commit
88
-                                  (git:show commit)))
89
-                      :key #'car)))
119
+  (mapcar 'cdr (component :parents commit)))