Skip to content

Commit

Permalink
add rudimentary packed-refs parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
froydnj committed Mar 29, 2010
1 parent a737dd2 commit 6ee856b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions refs.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(in-package :glitter)

(defclass packed-ref ()
((hash :initarg :hash :reader ref-hash)
(name :initarg :name :reader ref-name)))

(defparameter *print-packed-refs-sha-length* 6)

(defmethod print-object ((object packed-ref) stream)
(print-unreadable-object (object stream)
(format stream "Packed-Ref ~A ~A" (ref-name object)
(binascii:encode (ref-hash object) :hex
:end *print-packed-refs-sha-length*))))

(defun read-packed-refs-file (filename)
(with-open-file (stream filename :direction :input
:element-type 'character)
(do ((line (read-line stream nil stream)
(read-line stream nil stream))
(refs nil))
((eq line stream) (nreverse refs))
(cond
((char= (aref line 0) #\#)
;; FIXME: parse '# pack-refs with:' lines
)
((char= (aref line 0) #\^)
;; FIXME: parse these
)
(t
(let* ((hash-end (position #\Space line))
(hash (binascii:decode line :hex :end hash-end))
(name (subseq line (1+ hash-end))))
(push (make-instance 'packed-ref :hash hash :name name)
refs)))))))

0 comments on commit 6ee856b

Please sign in to comment.