git.fiddlerwoaroof.com
Browse code

feat: resolve strings as refs in first argument to GIT:GIT

Ed L authored on 15/11/2020 09:07:28
Showing 2 changed files
... ...
@@ -47,7 +47,7 @@
47 47
     #+END_SRC
48 48
 
49 49
     #+RESULTS:
50
-    : Merge commit 'e24e23183435b58a7d6176d848ee0f6c6b3e815a'
50
+    : feat: resolve strings as refs in first argument to GIT:GIT
51 51
 
52 52
 *** Show the messages of the commit's parent
53 53
 
... ...
@@ -58,8 +58,7 @@
58 58
     #+END_SRC
59 59
 
60 60
     #+RESULTS:
61
-    : (#<LOOSE-REF f4040ce of ~/git_repos/cl-git/>
62
-    :  #<LOOSE-REF e24e231 of ~/git_repos/cl-git/>)
61
+    : (#<LOOSE-REF 216c17e of ~/git_repos/cl-git/>)
63 62
 
64 63
 *** Show the files in a commit
65 64
 
... ...
@@ -78,7 +77,7 @@
78 77
     | .gitignore      | 100644 | 8a9fe9f77149f74fed5c05388be8e5ffd4a31678 |
79 78
     | .projectile     | 100644 | e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 |
80 79
     | LICENSE         | 100644 | 0306819e780fa57dc3bf6b99a0a059670b605ae0 |
81
-    | README.org      | 100644 | 2703b3dae5a5f8bee662bcc88820b348b41a9ca5 |
80
+    | README.org      | 100644 | c133adfd06f1bff1140d163147465fd3b996f4e5 |
82 81
     | branch.lisp     | 100644 | e06b66967fa4fa005ccf00dcbc7d839b22259593 |
83 82
     | cl-git.asd      | 100644 | 265a98fb79595e0067e53d8cf222dec4283f8525 |
84 83
     | commit.lisp     | 100644 | 197e10755343900cfbcb7fc6d863d4b3231e74d4 |
... ...
@@ -86,12 +85,12 @@
86 85
     | extract.lisp    | 100644 | 4707eca4ee0c70520ccdc57c0e831187b21271e7 |
87 86
     | git.lisp        | 100644 | c516dfc248544509c3ae58e3a8c2ab81c225aa9c |
88 87
     | graph.lisp      | 100644 | 31576396aff0fff28f69e0ef84571c0dc8cc43ec |
89
-    | model.lisp      | 100644 | 508861152a0ad7ebfafedd12cee7f4c0a170785c |
90
-    | package.lisp    | 100644 | a9d12e807ab4cdf923de2b0479507910054da0d4 |
91
-    | porcelain.lisp  | 100644 | d2bf143d76f597409fa729ea6095e89fe2fb9d79 |
88
+    | model.lisp      | 100644 | aa372879f4feeb170bc6d06047bf50f55a23042e |
89
+    | package.lisp    | 100644 | 65b2d0c35ea59f3d3cb88161402fd7e3de9798e4 |
90
+    | porcelain.lisp  | 100644 | 8906d2e411f63ea2558d5d4721495801506b0cb1 |
92 91
     | protocol.lisp   | 100644 | 7e24a6a7a4349497fce06830fa132e9a8ef6fd06 |
93
-    | repository.lisp | 100644 | d9fd84a83d400f416097571ae378302e4cce289b |
94
-    | tree.lisp       | 100644 | b757bb704b4c7a54622b7bd197ad5c1ea51ef2cc |
92
+    | repository.lisp | 100644 | 3eded300aa984e9ad2eb066e5ca4f78fe83e4137 |
93
+    | tree.lisp       | 100644 | 06bceb0a932817adedc9192edd6f9d4077277624 |
95 94
     | undelta.lisp    | 100644 | ae0a070133d1a14d6e940a0f790f40b37e885b22 |
96 95
     | util.lisp       | 100644 | 66279b2fa08c9d0872e888b85fe14d9950e27326 |
97 96
 
... ...
@@ -31,22 +31,42 @@
31 31
     (t (cons (in-git-package (car _1))
32 32
              (cdr _1)))))
33 33
 
34
+(defun git::resolve-refish (it)
35
+  (flet ((hash-p (it)
36
+           (and (> (length it) 32)
37
+                (every (serapeum:op
38
+                         (digit-char-p _1 16))
39
+                       it))))
40
+    (cond
41
+      ((let ((it "master"))
42
+         (block is-branch
43
+           (mapc (fw.lu:destructuring-lambda ((name hash))
44
+                   (when (equal it name)
45
+                     (return-from is-branch
46
+                       (ensure-ref hash))))
47
+                 (branches *git-repository*))
48
+           nil)))
49
+      ((hash-p it) (ensure-ref it)))))
50
+
34 51
 (defmacro git:git (&rest commands)
35 52
   `(uiop:nest ,@(reverse
36
-                 (mapcar (serapeum:op
37
-                           (typecase _1
38
-                             (string `(identity ,_1))
39
-                             (list (handle-list _1))))
40
-                         commands))))
41
-
42
-(defun ensure-ref (thing &optional (repo (repository *git-repository*)))
43
-  (typecase thing
44
-    (git-ref thing)
45
-    (t (ref repo thing))))
53
+                 (funcall (data-lens:<>1
54
+                           (data-lens:over (serapeum:op
55
+                                             (typecase _1
56
+                                               (string `(identity ,_1))
57
+                                               (list (handle-list _1)))))
58
+                           (data-lens:transform-head (serapeum:op
59
+                                                       (etypecase _1
60
+                                                         (string `(resolve-refish ,_1))
61
+                                                         (t _1)))))
62
+                          commands))))
46 63
 
47 64
 (defun git::ensure-ref (it)
48 65
   (ensure-ref it))
49 66
 
67
+(defun git::decode (it)
68
+  (babel:octets-to-string it :encoding *git-encoding*))
69
+
50 70
 (defun git::<<= (fun &rest args)
51 71
   (apply #'mapcan fun args))
52 72
 
... ...
@@ -86,8 +106,7 @@
86 106
   (extract-object thing))
87 107
 
88 108
 (defun git:show (object)
89
-  (extract-object
90
-   object))
109
+  (extract-object object))
91 110
 
92 111
 (defun git:contents (object)
93 112
   (git:show object))