Browse code
refactor: ref to its own package
Edward Langley authored on 08/11/2023 12:27:55
Showing 6 changed files
Showing 6 changed files
... | ... |
@@ -24,7 +24,8 @@ |
24 | 24 |
:components ((:file "package") |
25 | 25 |
(:file "types" :depends-on ("package")) |
26 | 26 |
(:file "util" :depends-on ("types" "package")) |
27 |
- (:file "pack" :depends-on ("types" "package" "util" "delta")) |
|
27 |
+ (:file "ref" :depends-on ("types" "package" "util")) |
|
28 |
+ (:file "pack" :depends-on ("types" "package" "util" "ref" "delta")) |
|
28 | 29 |
|
29 | 30 |
;; data model |
30 | 31 |
(:file "model" :depends-on ("package")) |
... | ... |
@@ -70,12 +70,12 @@ |
70 | 70 |
(defun resolve-delta (ref maybe-delta) |
71 | 71 |
(typecase maybe-delta |
72 | 72 |
(delta (multiple-value-bind (raw-data type) (trace-bases |
73 |
- (fwoar.cl-git.pack::packed-ref-pack ref) |
|
73 |
+ (fwoar.cl-git.pack:packed-ref-pack ref) |
|
74 | 74 |
maybe-delta) |
75 | 75 |
(-extract-object-of-type type |
76 | 76 |
raw-data |
77 |
- (fwoar.cl-git::ref-repo ref) |
|
78 |
- :hash (fwoar.cl-git::ref-hash ref)))) |
|
77 |
+ (fwoar.cl-git.ref:ref-repo ref) |
|
78 |
+ :hash (fwoar.cl-git.ref:ref-hash ref)))) |
|
79 | 79 |
(t maybe-delta))) |
80 | 80 |
|
81 | 81 |
(defun get-bases (pack delta) |
... | ... |
@@ -122,26 +122,8 @@ |
122 | 122 |
"Is ID an ID of a loose object?" |
123 | 123 |
(loose-object repository id)) |
124 | 124 |
|
125 |
-(defclass git-ref () |
|
126 |
- ((%repo :initarg :repo :reader ref-repo) |
|
127 |
- (%hash :initarg :hash :reader ref-hash))) |
|
128 |
-(defclass loose-ref (git-ref) |
|
129 |
- ((%file :initarg :file :reader loose-ref-file))) |
|
130 |
- |
|
131 |
-(defmethod print-object ((obj git-ref) s) |
|
132 |
- (print-unreadable-object (obj s :type t :identity t) |
|
133 |
- (format s "~a of ~a" |
|
134 |
- (subseq (ref-hash obj) 0 6) |
|
135 |
- (ref-repo obj) |
|
136 |
- #+(or) |
|
137 |
- (serapeum:string-replace (namestring (user-homedir-pathname)) |
|
138 |
- (root-of (ref-repo obj)) |
|
139 |
- "~/")))) |
|
140 |
- |
|
141 | 125 |
(defmethod component ((component (eql :hash)) (object git-object)) |
142 | 126 |
(hash object)) |
143 |
-(defmethod component ((component (eql :hash)) (object git-ref)) |
|
144 |
- (ref-hash object)) |
|
145 | 127 |
|
146 | 128 |
(fw.lu:defclass+ blob (fwoar.cl-git::git-object) |
147 | 129 |
((%data :reader data :initarg :data))) |
... | ... |
@@ -24,14 +24,21 @@ |
24 | 24 |
#:loose-ref |
25 | 25 |
#:extract-object-at-pos)) |
26 | 26 |
|
27 |
+(defpackage :fwoar.cl-git.ref |
|
28 |
+ (:use :cl :fwoar.cl-git.protocol) |
|
29 |
+ (:export #:git-ref #:loose-ref |
|
30 |
+ #:ref-repo |
|
31 |
+ #:ref-hash |
|
32 |
+ #:loose-ref-file)) |
|
33 |
+ |
|
27 | 34 |
(defpackage :fwoar.cl-git |
28 | 35 |
(:use :cl :fwoar.cl-git.protocol) |
29 | 36 |
(:import-from :fwoar.cl-git.commit #:git-commit) |
30 | 37 |
(:import-from :fwoar.cl-git.pack #:packed-ref) |
38 |
+ (:import-from :fwoar.cl-git.ref #:git-ref #:loose-ref #:ref-hash #:ref-repo) |
|
31 | 39 |
(:export #:ensure-ref #:repository #:*want-delta* #:git-object |
32 | 40 |
#:hash #:*git-encoding* #:git-commit #:ref #:component |
33 |
- #:*git-repository* #:git-ref #:extract-object |
|
34 |
- #:git-tree |
|
41 |
+ #:*git-repository* #:git-ref #:extract-object #:git-tree |
|
35 | 42 |
#:blob)) |
36 | 43 |
|
37 | 44 |
(defpackage :fwoar.cl-git.types |
38 | 45 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,20 @@ |
1 |
+(in-package :fwoar.cl-git.ref) |
|
2 |
+ |
|
3 |
+(defclass git-ref () |
|
4 |
+ ((%repo :initarg :repo :reader ref-repo) |
|
5 |
+ (%hash :initarg :hash :reader ref-hash))) |
|
6 |
+(defclass loose-ref (git-ref) |
|
7 |
+ ((%file :initarg :file :reader loose-ref-file))) |
|
8 |
+ |
|
9 |
+(defmethod print-object ((obj git-ref) s) |
|
10 |
+ (print-unreadable-object (obj s :type t :identity t) |
|
11 |
+ (format s "~a of ~a" |
|
12 |
+ (subseq (ref-hash obj) 0 6) |
|
13 |
+ (ref-repo obj) |
|
14 |
+ #+(or) |
|
15 |
+ (serapeum:string-replace (namestring (user-homedir-pathname)) |
|
16 |
+ (root-of (ref-repo obj)) |
|
17 |
+ "~/")))) |
|
18 |
+ |
|
19 |
+(defmethod fwoar.cl-git:component ((component (eql :hash)) (object git-ref)) |
|
20 |
+ (ref-hash object)) |
... | ... |
@@ -39,9 +39,9 @@ |
39 | 39 |
(5am:is (equal () |
40 | 40 |
(component :parents object))) |
41 | 41 |
(5am:is (equal "1da546ab4697b719efb62f11fd785d6ad3b226d2" |
42 |
- (fwoar.cl-git::ref-hash (component :tree object)))) |
|
42 |
+ (fwoar.cl-git.ref:ref-hash (component :tree object)))) |
|
43 | 43 |
(5am:is (equal *fake-repo* |
44 |
- (fwoar.cl-git::ref-repo (component :tree object)))) |
|
44 |
+ (fwoar.cl-git.ref:ref-repo (component :tree object)))) |
|
45 | 45 |
(5am:is (equal '(("author" "L Edgley <foo@bar.com> 1605513585 -0800") |
46 | 46 |
("committer" "Ed L <el-github@elangley.org> 1605513585 -0800") |
47 | 47 |
("tree" "1da546ab4697b719efb62f11fd785d6ad3b226d2")) |
... | ... |
@@ -87,8 +87,8 @@ |
87 | 87 |
:fwoar.cl-git.git-objects.pack |
88 | 88 |
hash)) |
89 | 89 |
(object (progn (fiveam:is (not (null ref))) |
90 |
- (fiveam:is (equal hash (fwoar.cl-git::ref-hash ref))) |
|
91 |
- (fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref))) |
|
90 |
+ (fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref))) |
|
91 |
+ (fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref))) |
|
92 | 92 |
(fwoar.cl-git:extract-object ref)))) |
93 | 93 |
|
94 | 94 |
(5am:is (typep object 'fwoar.cl-git:git-commit)) |
... | ... |
@@ -105,9 +105,9 @@ |
105 | 105 |
(component :parents object))) |
106 | 106 |
(let ((fwoar.cl-git:*git-repository* *fake-repo*)) |
107 | 107 |
(5am:is (equal "1da546ab4697b719efb62f11fd785d6ad3b226d2" |
108 |
- (fwoar.cl-git::ref-hash (component :tree object)))) |
|
108 |
+ (fwoar.cl-git.ref:ref-hash (component :tree object)))) |
|
109 | 109 |
(5am:is (equal *fake-repo* |
110 |
- (fwoar.cl-git::ref-repo (component :tree object))))) |
|
110 |
+ (fwoar.cl-git.ref:ref-repo (component :tree object))))) |
|
111 | 111 |
(5am:is (equal '(("author" "L Edgley <foo@bar.com> 1605513585 -0800") |
112 | 112 |
("committer" "Ed L <el-github@elangley.org> 1605513585 -0800") |
113 | 113 |
("tree" "1da546ab4697b719efb62f11fd785d6ad3b226d2")) |
... | ... |
@@ -122,8 +122,8 @@ |
122 | 122 |
:fwoar.cl-git.git-objects.pack |
123 | 123 |
hash)) |
124 | 124 |
(object (progn (fiveam:is (not (null ref))) |
125 |
- (fiveam:is (equal hash (fwoar.cl-git::ref-hash ref))) |
|
126 |
- (fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref))) |
|
125 |
+ (fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref))) |
|
126 |
+ (fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref))) |
|
127 | 127 |
(fwoar.cl-git:extract-object ref)))) |
128 | 128 |
(5am:is (typep object 'fwoar.cl-git::git-tree)) |
129 | 129 |
(let* ((entries (fwoar.cl-git::entries object)) |
... | ... |
@@ -142,8 +142,8 @@ |
142 | 142 |
:fwoar.cl-git.git-objects.pack |
143 | 143 |
hash)) |
144 | 144 |
(object (progn (fiveam:is (not (null ref))) |
145 |
- (fiveam:is (equal hash (fwoar.cl-git::ref-hash ref))) |
|
146 |
- (fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref))) |
|
145 |
+ (fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref))) |
|
146 |
+ (fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref))) |
|
147 | 147 |
(fwoar.cl-git:extract-object ref)))) |
148 | 148 |
(5am:is (typep object 'fwoar.cl-git::blob)) |
149 | 149 |
(5am:is (equal "hello, world |
... | ... |
@@ -175,7 +175,7 @@ |
175 | 175 |
:pack pack-file))) |
176 | 176 |
(defmethod fwoar.cl-git.pack:packed-ref-offset ((ref fake-ref-2)) |
177 | 177 |
(nth-value 1 (fwoar.cl-git.pack::find-sha-in-pack (fwoar.cl-git.pack:packed-ref-pack ref) |
178 |
- (fwoar.cl-git::ref-hash ref)))) |
|
178 |
+ (fwoar.cl-git.ref:ref-hash ref)))) |
|
179 | 179 |
(defmethod fwoar.cl-git:ref ((repo (eql *fake-repo-2*)) hash) |
180 | 180 |
(fake-ref-2 repo hash)) |
181 | 181 |
(defmethod fwoar.cl-git::pack-files ((repo (eql *fake-repo-2*))) |