Skip to content

Commit

Permalink
refactor: ref to its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
fiddlerwoaroof committed Nov 8, 2023
1 parent 0b2176e commit d9c448c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
3 changes: 2 additions & 1 deletion co.fwoar.cl-git.asd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
:components ((:file "package")
(:file "types" :depends-on ("package"))
(:file "util" :depends-on ("types" "package"))
(:file "pack" :depends-on ("types" "package" "util" "delta"))
(:file "ref" :depends-on ("types" "package" "util"))
(:file "pack" :depends-on ("types" "package" "util" "ref" "delta"))

;; data model
(:file "model" :depends-on ("package"))
Expand Down
6 changes: 3 additions & 3 deletions delta.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
(defun resolve-delta (ref maybe-delta)
(typecase maybe-delta
(delta (multiple-value-bind (raw-data type) (trace-bases
(fwoar.cl-git.pack::packed-ref-pack ref)
(fwoar.cl-git.pack:packed-ref-pack ref)
maybe-delta)
(-extract-object-of-type type
raw-data
(fwoar.cl-git::ref-repo ref)
:hash (fwoar.cl-git::ref-hash ref))))
(fwoar.cl-git.ref:ref-repo ref)
:hash (fwoar.cl-git.ref:ref-hash ref))))
(t maybe-delta)))

(defun get-bases (pack delta)
Expand Down
18 changes: 0 additions & 18 deletions model.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,8 @@
"Is ID an ID of a loose object?"
(loose-object repository id))

(defclass git-ref ()
((%repo :initarg :repo :reader ref-repo)
(%hash :initarg :hash :reader ref-hash)))
(defclass loose-ref (git-ref)
((%file :initarg :file :reader loose-ref-file)))

(defmethod print-object ((obj git-ref) s)
(print-unreadable-object (obj s :type t :identity t)
(format s "~a of ~a"
(subseq (ref-hash obj) 0 6)
(ref-repo obj)
#+(or)
(serapeum:string-replace (namestring (user-homedir-pathname))
(root-of (ref-repo obj))
"~/"))))

(defmethod component ((component (eql :hash)) (object git-object))
(hash object))
(defmethod component ((component (eql :hash)) (object git-ref))
(ref-hash object))

(fw.lu:defclass+ blob (fwoar.cl-git::git-object)
((%data :reader data :initarg :data)))
Expand Down
11 changes: 9 additions & 2 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
#:loose-ref
#:extract-object-at-pos))

(defpackage :fwoar.cl-git.ref
(:use :cl :fwoar.cl-git.protocol)
(:export #:git-ref #:loose-ref
#:ref-repo
#:ref-hash
#:loose-ref-file))

(defpackage :fwoar.cl-git
(:use :cl :fwoar.cl-git.protocol)
(:import-from :fwoar.cl-git.commit #:git-commit)
(:import-from :fwoar.cl-git.pack #:packed-ref)
(:import-from :fwoar.cl-git.ref #:git-ref #:loose-ref #:ref-hash #:ref-repo)
(:export #:ensure-ref #:repository #:*want-delta* #:git-object
#:hash #:*git-encoding* #:git-commit #:ref #:component
#:*git-repository* #:git-ref #:extract-object
#:git-tree
#:*git-repository* #:git-ref #:extract-object #:git-tree
#:blob))

(defpackage :fwoar.cl-git.types
Expand Down
20 changes: 20 additions & 0 deletions ref.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(in-package :fwoar.cl-git.ref)

(defclass git-ref ()
((%repo :initarg :repo :reader ref-repo)
(%hash :initarg :hash :reader ref-hash)))
(defclass loose-ref (git-ref)
((%file :initarg :file :reader loose-ref-file)))

(defmethod print-object ((obj git-ref) s)
(print-unreadable-object (obj s :type t :identity t)
(format s "~a of ~a"
(subseq (ref-hash obj) 0 6)
(ref-repo obj)
#+(or)
(serapeum:string-replace (namestring (user-homedir-pathname))
(root-of (ref-repo obj))
"~/"))))

(defmethod fwoar.cl-git:component ((component (eql :hash)) (object git-ref))
(ref-hash object))
22 changes: 11 additions & 11 deletions tests/git-objects.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
(5am:is (equal ()
(component :parents object)))
(5am:is (equal "1da546ab4697b719efb62f11fd785d6ad3b226d2"
(fwoar.cl-git::ref-hash (component :tree object))))
(fwoar.cl-git.ref:ref-hash (component :tree object))))
(5am:is (equal *fake-repo*
(fwoar.cl-git::ref-repo (component :tree object))))
(fwoar.cl-git.ref:ref-repo (component :tree object))))
(5am:is (equal '(("author" "L Edgley <[email protected]> 1605513585 -0800")
("committer" "Ed L <[email protected]> 1605513585 -0800")
("tree" "1da546ab4697b719efb62f11fd785d6ad3b226d2"))
Expand Down Expand Up @@ -87,8 +87,8 @@
:fwoar.cl-git.git-objects.pack
hash))
(object (progn (fiveam:is (not (null ref)))
(fiveam:is (equal hash (fwoar.cl-git::ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref)))
(fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref)))
(fwoar.cl-git:extract-object ref))))

(5am:is (typep object 'fwoar.cl-git:git-commit))
Expand All @@ -105,9 +105,9 @@
(component :parents object)))
(let ((fwoar.cl-git:*git-repository* *fake-repo*))
(5am:is (equal "1da546ab4697b719efb62f11fd785d6ad3b226d2"
(fwoar.cl-git::ref-hash (component :tree object))))
(fwoar.cl-git.ref:ref-hash (component :tree object))))
(5am:is (equal *fake-repo*
(fwoar.cl-git::ref-repo (component :tree object)))))
(fwoar.cl-git.ref:ref-repo (component :tree object)))))
(5am:is (equal '(("author" "L Edgley <[email protected]> 1605513585 -0800")
("committer" "Ed L <[email protected]> 1605513585 -0800")
("tree" "1da546ab4697b719efb62f11fd785d6ad3b226d2"))
Expand All @@ -122,8 +122,8 @@
:fwoar.cl-git.git-objects.pack
hash))
(object (progn (fiveam:is (not (null ref)))
(fiveam:is (equal hash (fwoar.cl-git::ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref)))
(fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref)))
(fwoar.cl-git:extract-object ref))))
(5am:is (typep object 'fwoar.cl-git::git-tree))
(let* ((entries (fwoar.cl-git::entries object))
Expand All @@ -142,8 +142,8 @@
:fwoar.cl-git.git-objects.pack
hash))
(object (progn (fiveam:is (not (null ref)))
(fiveam:is (equal hash (fwoar.cl-git::ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git::ref-repo ref)))
(fiveam:is (equal hash (fwoar.cl-git.ref:ref-hash ref)))
(fiveam:is (equal *fake-repo* (fwoar.cl-git.ref:ref-repo ref)))
(fwoar.cl-git:extract-object ref))))
(5am:is (typep object 'fwoar.cl-git::blob))
(5am:is (equal "hello, world
Expand Down Expand Up @@ -175,7 +175,7 @@
:pack pack-file)))
(defmethod fwoar.cl-git.pack:packed-ref-offset ((ref fake-ref-2))
(nth-value 1 (fwoar.cl-git.pack::find-sha-in-pack (fwoar.cl-git.pack:packed-ref-pack ref)
(fwoar.cl-git::ref-hash ref))))
(fwoar.cl-git.ref:ref-hash ref))))
(defmethod fwoar.cl-git:ref ((repo (eql *fake-repo-2*)) hash)
(fake-ref-2 repo hash))
(defmethod fwoar.cl-git::pack-files ((repo (eql *fake-repo-2*)))
Expand Down

0 comments on commit d9c448c

Please sign in to comment.