From fa7cc3f26757d41ef83892a5128ed2dd225f3ede Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 12 Feb 2008 23:28:44 +0100 Subject: [PATCH] hold metadata in memory instead of in git --- tekuti/categories.scm | 18 +----------------- tekuti/comment.scm | 4 ++-- tekuti/git.scm | 4 ++-- tekuti/mod-lisp.scm | 1 + tekuti/post.scm | 26 +++++--------------------- 5 files changed, 11 insertions(+), 42 deletions(-) diff --git a/tekuti/categories.scm b/tekuti/categories.scm index fd97d76..d2bea29 100644 --- a/tekuti/categories.scm +++ b/tekuti/categories.scm @@ -41,21 +41,5 @@ posts) hash)) -(define (build-categories-tree master posts) - (if (null? posts) - #f - (let* ((hash (compute-categories posts)) - (tree (make-tree (hash-map->list - (lambda (k v) (cons k (make-tree v))) - hash))) - (ts (commit-utc-timestamp master)) - (env (list "GIT_COMMMITTER=tekuti" - ;; this quoting is a hack - (format #f "'GIT_COMMITTER_DATE=~a +0000'" ts) - (format #f "'GIT_AUTHOR_DATE=~a +0000'" ts)))) - (string-trim-both - (git/input+env "categories\n" env "commit-tree" tree - "-p" master))))) ;; FIXME: keep history? - (define (reindex-categories master) - (build-categories-tree master (all-published-posts master))) + (compute-categories (all-published-posts master))) diff --git a/tekuti/comment.scm b/tekuti/comment.scm index 91f7ffe..0aa04f8 100644 --- a/tekuti/comment.scm +++ b/tekuti/comment.scm @@ -43,13 +43,13 @@ (debug-enable 'backtrace) (define *comment-spec* - `((timestamp ,string->number))) + `((timestamp . ,string->number))) (define (comment-from-tree encoded-name sha1) (acons 'encoded-name encoded-name (parse-metadata (string-append sha1 ":" "metadata") *comment-spec*))) (define (comment-timestamp comment-alist) - (or (assq-ref x 'timestamp) #f)) + (or (assq-ref comment-alist 'timestamp) #f)) (define (build-comment-skeleton comments) (fold (lambda (sha1 parent) diff --git a/tekuti/git.scm b/tekuti/git.scm index 162ba8a..7c6b07e 100644 --- a/tekuti/git.scm +++ b/tekuti/git.scm @@ -99,13 +99,13 @@ "^(.+) tree (.+)\t(.+)$" (_ mode object name) (cons name object))) -(define (parse-metadata treeish . specs) +(define (parse-metadata treeish specs) (filter identity (match-lines (git "cat-file" "blob" treeish) "^([^: ]+): +(.*)$" (_ k v) (let* ((k (string->symbol k)) - (parse (assq-ref k specs))) + (parse (assq-ref specs k))) (if parse (catch 'parse-error (lambda () diff --git a/tekuti/mod-lisp.scm b/tekuti/mod-lisp.scm index 585c393..9e37acd 100644 --- a/tekuti/mod-lisp.scm +++ b/tekuti/mod-lisp.scm @@ -97,5 +97,6 @@ (sockaddr (cdr pair))) (receive (cookie index) (maybe-reindex old-cookie old-index) + (pk cookie index) (connection-received (car pair) (cdr pair) index handle-request) (lp cookie index))))))) diff --git a/tekuti/post.scm b/tekuti/post.scm index 77dcf11..9330611 100644 --- a/tekuti/post.scm +++ b/tekuti/post.scm @@ -40,14 +40,14 @@ (equal? (assq-ref post-alist 'status) "published")) (define (post-timestamp post-alist) - (or (assq-ref x 'timestamp) #f)) + (or (assq-ref post-alist 'timestamp) #f)) (define (post-categories post-alist) - (or (assq-ref x 'categories) '())) + (or (assq-ref post-alist 'categories) '())) (define *post-spec* - `((timestamp ,string->number) - (categories ,(lambda (v) (map string-trim-both (string-split v #\,)))))) + `((timestamp . ,string->number) + (categories . ,(lambda (v) (map string-trim-both (string-split v #\,)))))) (define (post-from-tree encoded-name sha1) (acons 'url encoded-name @@ -72,21 +72,5 @@ comment-timestamp <)) -(define (build-post-skeleton master posts) - (fold (lambda (sha1 parent) - (let* ((ts (post-timestamp sha1)) - (comments (build-comment-skeleton (post-comments sha1))) - (env (list "GIT_COMMMITTER=tekuti" - ;; this quoting is a hack - (format #f "'GIT_COMMITTER_DATE=~a +0100'" ts) - (format #f "'GIT_AUTHOR_DATE=~a +0100'" ts)))) - (string-trim-both - (git* `("commit-tree" ,sha1 - ,@(if parent (list "-p" parent) '()) - ,@(if comments (list "-p" comments) '())) - #:input "post\n" #:env env)))) - #f - (map cdr posts))) - (define (reindex-posts master) - (build-post-skeleton master (all-published-posts master))) + (all-published-posts master))