summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorArun Isaac2022-06-25 14:48:47 +0530
committerArun Isaac2022-06-25 15:10:05 +0530
commit223df46be51d641279f98ff5f9cb6a9b477e09c6 (patch)
treeb8f53203c6e488c3568baaa6dd6bd20df8e25d14 /bin
parent4698be366ee6079ba4198f42b2b8306d9eda2136 (diff)
downloadtissue-223df46be51d641279f98ff5f9cb6a9b477e09c6.tar.gz
tissue-223df46be51d641279f98ff5f9cb6a9b477e09c6.tar.lz
tissue-223df46be51d641279f98ff5f9cb6a9b477e09c6.zip
bin: Index issues using xapian.
* bin/tissue: Import (ice-9 ftw), (git), (xapian wrap) and (xapian xapian). (delete-xapian-index): New function. (%state-directory, %xapian-index): New variables. (main): Build index if it does not exist. * tissue/issue.scm: Import (xapian xapian). (index-person): New function. (index-issue): New public function.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue42
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/tissue b/bin/tissue
index 2deb23d..85f18b9 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -28,10 +28,14 @@ exec guile --no-auto-compile -s "$0" "$@"
(srfi srfi-37)
(srfi srfi-171)
(srfi srfi-171 gnu)
+ (ice-9 ftw)
(ice-9 match)
(ice-9 popen)
(ice-9 regex)
(term ansi-color)
+ (git)
+ (xapian wrap)
+ (xapian xapian)
(tissue conditions)
(tissue git)
(tissue issue)
@@ -39,6 +43,12 @@ exec guile --no-auto-compile -s "$0" "$@"
(tissue utils)
(tissue web))
+(define %state-directory
+ ".tissue")
+
+(define %xapian-index
+ (string-append %state-directory "/xapian"))
+
(define (invoke program . args)
(unless (zero? (apply system* program args))
(error "Invocation of program failed" (cons program args))))
@@ -328,6 +338,16 @@ To get usage information for one of these sub-commands, run
(command-line-program)
(command-line-program)))
+(define (delete-xapian-index)
+ "Delete xapian index if it exists. Current directory must be at the
+top-level of the git repository."
+ (when (file-exists? %xapian-index)
+ (for-each (lambda (file)
+ (delete-file (string-append %xapian-index "/" file)))
+ (scandir %xapian-index
+ (negate (cut member <> (list "." "..")))))
+ (rmdir %xapian-index)))
+
(define main
(match-lambda*
((_ (or "-h" "--help"))
@@ -343,6 +363,28 @@ To get usage information for one of these sub-commands, run
(lambda ()
(parameterize ((%issue-files (tissue-configuration-issue-files (load-config)))
(%aliases (tissue-configuration-aliases (load-config))))
+ ;; Create hidden tissue directory unless it exists.
+ (unless (file-exists? %state-directory)
+ (mkdir %state-directory))
+ ;; Ensure index exists rebuilding it if it is stale.
+ (let ((current-head
+ (oid->string (reference-name->oid
+ (current-git-repository) "HEAD"))))
+ (unless (and (file-exists? %xapian-index)
+ (string=? (call-with-database %xapian-index
+ (cut Database-get-metadata <> "commit"))
+ current-head))
+ (guard (c (else (delete-xapian-index)
+ (display "Building xapian index failed."
+ (current-error-port))
+ (raise c)))
+ (delete-xapian-index)
+ (call-with-writable-database %xapian-index
+ (lambda (db)
+ (for-each (cut index-issue db <>)
+ (issues))
+ (WritableDatabase-set-metadata db "commit" current-head))))))
+ ;; Handle sub-command.
(apply (match command
("list" tissue-list)
("show" tissue-show)