-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: continue implementing delta expansion
- Loading branch information
1 parent
691d18e
commit 9d5bb29
Showing
8 changed files
with
613 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(in-package :fwoar.cl-git) | ||
|
||
(defclass git-graph () | ||
((%repo :initarg :repo :reader repo) | ||
(%depth :initarg :depth :reader depth) | ||
(%branches :reader branches) | ||
(%node-cache :reader node-cache :initform (make-hash-table :test 'equal)) | ||
(%edge-cache :reader edge-cache :initform (make-hash-table :test 'equal)))) | ||
|
||
(defmethod initialize-instance :after ((object git-graph) &key) | ||
(setf (slot-value object '%branches) | ||
(fw.lu:alist-string-hash-table | ||
(funcall (data-lens:over | ||
(<>1 (data-lens:applying #'cons) | ||
(data-lens:transform-head | ||
(serapeum:op (subseq _1 0 (min (length _1) 7)))) | ||
#'reverse)) | ||
(branches (repo object)))))) | ||
|
||
(defun git-graph (repo) | ||
(fw.lu:new 'git-graph repo)) | ||
|
||
(defun get-commit-parents (repository commit) | ||
#+lispworks | ||
(declare (notinline mismatch serapeum:string-prefix-p)) | ||
(map 'list | ||
(serapeum:op (second (partition #\space _))) | ||
(remove-if-not (lambda (it) | ||
(serapeum:string-prefix-p "parent" it)) | ||
(nth-value 1 (parse-commit | ||
(split-object | ||
(chipz:decompress nil (chipz:make-dstate 'chipz:zlib) | ||
(loose-object repository | ||
commit)))))))) | ||
|
||
(defmethod cl-dot:graph-object-node ((graph git-graph) (commit string)) | ||
(alexandria:ensure-gethash commit | ||
(node-cache graph) | ||
(make-instance 'cl-dot:node | ||
:attributes `(:label ,(gethash #1=(subseq commit 0 7) | ||
(branches graph) | ||
#1#))))) | ||
|
||
(defmethod cl-dot:graph-object-points-to ((graph git-graph) (commit string)) | ||
#+nil | ||
(loop | ||
for cur = (list commit) then parents | ||
for parents = (let ((f (get-commit-parents (repo graph) (car cur)))) | ||
f) | ||
until (or (not parents) | ||
(cdr parents)) | ||
finally (return (or parents | ||
(when (not (equal commit (car cur))) | ||
cur)))) | ||
|
||
(funcall (data-lens:<>1 (data-lens:over (serapeum:op | ||
(setf (gethash (list commit _1) | ||
(edge-cache graph)) | ||
t) | ||
_1)) | ||
(data-lens:exclude (serapeum:op | ||
(gethash (list commit _1) | ||
(edge-cache graph)))) | ||
(data-lens:over (serapeum:op (subseq _ 0 7)))) | ||
(get-commit-parents (repo graph) commit))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
;;; -*- Mode:Lisp; Syntax:ANSI-Common-Lisp; Package: ASDF-USER -*- | ||
(in-package :asdf-user) | ||
|
||
(defsystem :cl-git | ||
:description "A pure-Lisp git implementation" | ||
:author "Ed L <[email protected]>" | ||
:license "MIT" | ||
:pathname #-fw.dev nil #+fw.dev #p"PROJECTS:cl-git;" | ||
:depends-on (:alexandria | ||
:chipz | ||
:cl-dot | ||
:data-lens | ||
:fwoar-lisputils | ||
:fwoar-lisputils/bin-parser | ||
:ironclad | ||
:serapeum | ||
:split-sequence | ||
:uiop) | ||
:components ((:file "package") | ||
(:file "util" :depends-on ("package")) | ||
|
||
;; data model | ||
(:file "model" :depends-on ("package")) | ||
(:file "protocol" :depends-on ("package" "model")) | ||
(:file "repository" :depends-on ("package" "model")) | ||
(:file "tree" :depends-on ("package" "model")) | ||
(:file "commit" :depends-on ("package" "model")) | ||
|
||
(:file "extract" :depends-on ("package" "commit" "tree")) | ||
(:file "branch" :depends-on ("package" "extract")) | ||
(:file "git" :depends-on ("package" "util" "model" "branch")) | ||
|
||
;; stable programmer interface | ||
(:file "porcelain" :depends-on ("package" "git" "commit")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
(in-package :fwoar.cl-git) | ||
|
||
(fw.lu:defun-ct batch-4 (bytes) | ||
(mapcar 'fwoar.bin-parser:be->int | ||
(serapeum:batches bytes 4))) | ||
|
||
(fw.lu:defun-ct batch-20 (bytes) | ||
(serapeum:batches bytes 20)) | ||
|
||
(defmacro sym->plist (&rest syms) | ||
`(list ,@(loop for sym in syms | ||
append (list (alexandria:make-keyword sym) | ||
sym)))) | ||
|
||
(defmacro inspect- (s form) | ||
`(let ((result ,form)) | ||
(format ,s "~&~s (~{~s~^ ~})~%~4t~s~%" | ||
',form | ||
,(typecase form | ||
(list `(list ',(car form) ,@(cdr form))) | ||
(t `(list ,form))) | ||
result) | ||
result)) | ||
|
||
(defun inspect-* (fn) | ||
(lambda (&rest args) | ||
(declare (dynamic-extent args)) | ||
(inspect- *trace-output* | ||
(apply fn args)))) | ||
|
||
(defun partition (char string &key from-end (with-offset nil wo-p)) | ||
(let ((pos (position char string :from-end from-end))) | ||
(if pos | ||
(if wo-p | ||
(list (subseq string 0 (+ pos with-offset 1)) | ||
(subseq string (+ pos 1 with-offset))) | ||
(list (subseq string 0 pos) | ||
(subseq string (1+ pos)))) | ||
(list string | ||
nil)))) | ||
|
||
(defun partition-subseq (subseq string &key from-end) | ||
(let ((pos (search subseq string :from-end from-end))) | ||
(if pos | ||
(list (subseq string 0 pos) | ||
(subseq string (+ (length subseq) pos))) | ||
(list string | ||
nil)))) | ||
|
||
(serapeum:defalias ->sha-string | ||
(data-lens:<>1 (data-lens:over 'fwoar.bin-parser:byte-array-to-hex-string) | ||
'batch-20)) | ||
|
||
(defun read-bytes (count format stream) | ||
(let ((seq (make-array count :element-type 'serapeum:octet))) | ||
(read-sequence seq stream) | ||
(funcall format | ||
seq))) | ||
|
||
(defun sp-ob (ob-string) | ||
(partition #\null | ||
ob-string)) | ||
|
||
(defun split-object (object-data) | ||
(destructuring-bind (head tail) | ||
(partition 0 | ||
object-data) | ||
(destructuring-bind (type length) | ||
(partition #\space | ||
(babel:octets-to-string head :encoding :latin1)) | ||
(values tail | ||
(list type | ||
(parse-integer length)))))) | ||
|
||
(defun parse-commit (commit) | ||
(destructuring-bind (metadata message) | ||
(partition-subseq #(#\newline #\newline) | ||
commit #+(or)(babel:octets-to-string commit :encoding :latin1)) | ||
(values message | ||
(map 'vector (serapeum:op (partition #\space _)) | ||
(fwoar.string-utils:split #\newline metadata))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
(in-package :fwoar.cl-git) | ||
|
||
(fw.lu:defun-ct batch-4 (bytes) | ||
(mapcar 'fwoar.bin-parser:be->int | ||
(serapeum:batches bytes 4))) | ||
|
||
(fw.lu:defun-ct batch-20 (bytes) | ||
(serapeum:batches bytes 20)) | ||
|
||
(defmacro sym->plist (&rest syms) | ||
`(list ,@(loop for sym in syms | ||
append (list (alexandria:make-keyword sym) | ||
sym)))) | ||
|
||
(defmacro inspect- (s form) | ||
`(let ((result ,form)) | ||
(format ,s "~&~s (~{~s~^ ~})~%~4t~s~%" | ||
',form | ||
,(typecase form | ||
(list `(list ',(car form) ,@(cdr form))) | ||
(t `(list ,form))) | ||
result) | ||
result)) | ||
|
||
(defun inspect-* (fn) | ||
(lambda (&rest args) | ||
(declare (dynamic-extent args)) | ||
(inspect- *trace-output* | ||
(apply fn args)))) | ||
|
||
(defun partition (char string &key from-end) | ||
(let ((pos (position char string :from-end from-end))) | ||
(if pos | ||
(list (subseq string 0 pos) | ||
(subseq string (1+ pos))) | ||
(list string | ||
nil)))) | ||
|
||
(defun partition-subseq (subseq string &key from-end) | ||
(let ((pos (search subseq string :from-end from-end))) | ||
(if pos | ||
(list (subseq string 0 pos) | ||
(subseq string (+ (length subseq) pos))) | ||
(list string | ||
nil)))) | ||
|
||
(serapeum:defalias ->sha-string | ||
(data-lens:<>1 (data-lens:over 'fwoar.bin-parser:byte-array-to-hex-string) | ||
'batch-20)) |
Oops, something went wrong.