git.fiddlerwoaroof.com
Browse code

Continue refining porcelain

Ed Langley authored on 08/05/2019 08:26:41
Showing 2 changed files
... ...
@@ -10,4 +10,4 @@
10 10
 (defpackage :git
11 11
   (:use)
12 12
   (:export #:show #:branch #:branches #:commit-parents #:in-repository
13
-           #:current-repository #:show-repository #:git))
13
+           #:current-repository #:show-repository #:git #:tree #:contents))
... ...
@@ -21,10 +21,7 @@
21 21
                                                                     :git))
22 22
                                                       (cddr _1)))
23 23
                                         ((map) (list* 'mapcar
24
-                                                      (list 'quote
25
-                                                            (intern (symbol-name (cadadr _1))
26
-                                                                    :git))
27
-                                                      (cddr _1)))
24
+                                                      (cdr _1)))
28 25
                                         (t (cons (intern (symbol-name (car _1))
29 26
                                                          :git)
30 27
                                                  (cdr _1)))))
... ...
@@ -37,6 +34,31 @@
37 34
            '(vector serapeum:octet))
38 35
    :encoding *git-encoding*))
39 36
 
37
+(defun git:contents (object)
38
+  (git:show object))
39
+
40
+(defstruct (tree-entry (:type vector))
41
+  te-name te-mode te-id)
42
+
43
+(defun git:tree (commit)
44
+  (cadr (fw.lu:v-assoc "tree"
45
+                       (nth-value 1 (parse-commit commit))
46
+                       :test 'equal)))
47
+
48
+(defun git::filter-tree (name-pattern tree)
49
+  #+lispworks
50
+  (declare (notinline serapeum:string-prefix-p))
51
+  (let* ((lines (fwoar.string-utils:split #\newline tree))
52
+         (columns (map 'list
53
+                       (serapeum:op
54
+                         (coerce (fwoar.string-utils:split #\tab _)
55
+                                 'simple-vector))
56
+                       lines)))
57
+    (remove-if-not (serapeum:op
58
+                     (serapeum:string-prefix-p name-pattern _))
59
+                   columns
60
+                   :key #'tree-entry-te-name)))
61
+
40 62
 (defun git:branch (&optional (branch "master"))
41 63
   #+lispworks
42 64
   (declare (notinline serapeum:assocadr))