git.fiddlerwoaroof.com
Browse code

updates

Ed Langley authored on 05/05/2019 06:17:23
Showing 4 changed files
... ...
@@ -18,5 +18,6 @@
18 18
                :uiop)
19 19
   :components ((:file "package")
20 20
                (:file "util" :depends-on ("package"))
21
-               (:file "git" :depends-on ("package" "util"))
21
+               (:file "model" :depends-on ("package"))
22
+               (:file "git" :depends-on ("package" "util" "model"))
22 23
                (:file "porcelain" :depends-on ("package" "git"))))
... ...
@@ -1,48 +1,5 @@
1 1
 (in-package :fwoar.cl-git)
2 2
 
3
-(defparameter *object-data-lens*
4
-  (data-lens.lenses:make-alist-lens :object-data))
5
-
6
-(defclass pack ()
7
-  ((%pack :initarg :pack :reader pack-file)
8
-   (%index :initarg :index :reader index-file)))
9
-
10
-(defclass repository ()
11
-  ((%root :initarg :root :reader root)))
12
-
13
-(defclass git-object ()
14
-  ())
15
-
16
-(defclass commit (git-object)
17
-  ())
18
-
19
-(defun repository (root)
20
-  (fw.lu:new 'repository root))
21
-
22
-(defun get-local-branches (root)
23
-  (mapcar (data-lens:juxt #'pathname-name
24
-                          (alexandria:compose #'serapeum:trim-whitespace
25
-                                              #'alexandria:read-file-into-string))
26
-          (uiop:directory*
27
-           (merge-pathnames ".git/refs/heads/*"
28
-                            root))))
29
-
30
-(defun loose-object-path (sha)
31
-  (let ((obj-path (fwoar.string-utils:insert-at 2 #\/ sha)))
32
-    (merge-pathnames obj-path ".git/objects/")))
33
-
34
-(defun pack (index pack)
35
-  (fw.lu:new 'pack index pack))
36
-
37
-(defun pack-files (repo)
38
-  (mapcar 'pack
39
-          (uiop:directory*
40
-           (merge-pathnames ".git/objects/pack/*.idx"
41
-                            repo))
42
-          (uiop:directory*
43
-           (merge-pathnames ".git/objects/pack/*.pack"
44
-                            repo))))
45
-
46 3
 (defun find-object-in-pack-files (repo id)
47 4
   (dolist (pack-file (pack-files repo))
48 5
     (multiple-value-bind (pack mid) (find-pack-containing pack-file id)
... ...
@@ -216,12 +173,6 @@
216 173
                         idx-sha)
217 174
             object-count)))
218 175
 
219
-(defun read-bytes (count format stream)
220
-  (let ((seq (make-array count)))
221
-    (read-sequence seq stream)
222
-    (funcall format
223
-             seq)))
224
-
225 176
 (defun collect-data (idx-toc s num)
226 177
   (let ((sha-idx (getf idx-toc :shas))
227 178
         (crc-idx (getf idx-toc :packed-crcs))
... ...
@@ -239,15 +190,6 @@
239 190
               (file-position s (+ 4-byte-offsets-idx (* num 4)))
240 191
               (read-bytes 4 'fwoar.bin-parser:be->int s)))))
241 192
 
242
-(defun object-type->sym (object-type)
243
-  (ecase object-type
244
-    (1 :commit)
245
-    (2 :tree)
246
-    (3 :blob)
247
-    (4 :tag)
248
-    (6 :ofs-delta)
249
-    (7 :ref-delta)))
250
-
251 193
 (defun read-object-metadata-from-pack (s)
252 194
   (let* ((metadata (fwoar.bin-parser:extract-high s))
253 195
          (type (get-object-type metadata))
... ...
@@ -276,28 +218,5 @@
276 218
                 ,@(multiple-value-list
277 219
                    (read-object-metadata-from-pack pack))
278 220
                 (:offset . ,offset))
279
-              result))
280
-      )))
281
-
282
-(defun sp-ob (ob-string)
283
-  (partition #\null
284
-             ob-string))
285
-
286
-(defun split-object (object-data)
287
-  (destructuring-bind (head tail)
288
-      (partition 0
289
-                 object-data)
290
-    (destructuring-bind (type length)
291
-        (partition #\space
292
-                   (babel:octets-to-string head :encoding :latin1))
293
-      (values tail
294
-              (list type
295
-                    (parse-integer length))))))
296
-
221
+              result)))))
297 222
 
298
-(defun parse-commit (commit)
299
-  (destructuring-bind (metadata message)
300
-      (partition-subseq #(#\newline #\newline)
301
-                        commit #+(or)(babel:octets-to-string commit :encoding :latin1))
302
-    (values message
303
-            (fwoar.string-utils:split #\newline metadata))))
... ...
@@ -6,3 +6,7 @@
6 6
 
7 7
 (defpackage :cl-git-user
8 8
   (:use :cl :fwoar.cl-git))
9
+
10
+(defpackage :git
11
+  (:use)
12
+  (:export #:show #:branch))
9 13
\ No newline at end of file
... ...
@@ -47,3 +47,31 @@
47 47
 (serapeum:defalias ->sha-string
48 48
   (data-lens:<>1 (data-lens:over 'fwoar.bin-parser:byte-array-to-hex-string)
49 49
                  'batch-20))
50
+
51
+(defun read-bytes (count format stream)
52
+  (let ((seq (make-array count)))
53
+    (read-sequence seq stream)
54
+    (funcall format
55
+             seq)))
56
+
57
+(defun sp-ob (ob-string)
58
+  (partition #\null
59
+             ob-string))
60
+
61
+(defun split-object (object-data)
62
+  (destructuring-bind (head tail)
63
+      (partition 0
64
+                 object-data)
65
+    (destructuring-bind (type length)
66
+        (partition #\space
67
+                   (babel:octets-to-string head :encoding :latin1))
68
+      (values tail
69
+              (list type
70
+                    (parse-integer length))))))
71
+
72
+(defun parse-commit (commit)
73
+  (destructuring-bind (metadata message)
74
+      (partition-subseq #(#\newline #\newline)
75
+                        commit #+(or)(babel:octets-to-string commit :encoding :latin1))
76
+    (values message
77
+            (fwoar.string-utils:split #\newline metadata))))