Skip to content

Commit

Permalink
chore: EXTRACT-OBJECT automatically handles deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
fiddlerwoaroof committed Nov 2, 2023
1 parent 8a984d6 commit 55e7158
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
27 changes: 22 additions & 5 deletions delta.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
:unless (zerop (aref bv ix))
:sum (expt 2 n))))

(defun obj-to-type (obj)
(etypecase obj
(git-commit :commit)
(git-tree :tree)
(blob :blob)))

(defun trace-bases (pack delta)
(assert (typep delta 'delta))
(let* ((offset (second (base delta)))
Expand All @@ -50,14 +56,25 @@
(obj (serapeum:assocdr :object-data o))
(raw (serapeum:assocdr :raw-data o)))
(if (typep obj 'delta)
(let ((next (trace-bases pack obj)))
(length next)
(apply-commands next
(commands delta)))
(multiple-value-bind (next base-type) (trace-bases pack obj)
(values (apply-commands next
(commands delta))
base-type))
(let ((base (apply-commands raw
(commands delta))))
(length base)
base))))
(values base
(obj-to-type obj))))))

(defun resolve-delta (ref maybe-delta)
(typecase maybe-delta
(delta (multiple-value-bind (raw-data type) (trace-bases (packed-ref-pack ref)
maybe-delta)
(-extract-object-of-type type
raw-data
(ref-repo ref)
:hash (ref-hash ref))))
(t maybe-delta)))

(defun get-bases (pack delta)
(if (typep delta 'delta)
Expand Down
9 changes: 5 additions & 4 deletions extract.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
(loose-ref-file object)
object))
(:method ((object packed-ref))
(data-lens.lenses:view *object-data-lens*
(extract-object-from-pack (packed-ref-pack object)
(packed-ref-offset object)
object))))
(resolve-delta object
(data-lens.lenses:view *object-data-lens*
(extract-object-from-pack (packed-ref-pack object)
(packed-ref-offset object)
object)))))

0 comments on commit 55e7158

Please sign in to comment.