From ec434ea0710e9ece9f5239c7fe2b1f965a53bea1 Mon Sep 17 00:00:00 2001
From: Arun Isaac
Date: Mon, 4 Jul 2022 23:59:29 +0530
Subject: bin: Move stale index checks to main function.

We want `tissue pull' to unconditionally rebuild the index. Hence, we
move stale index checks out of the index function.

* bin/tissue (index): Do not check if index is stale. Always rebuild
index.
(main): Call the index function only when index is stale.
---
 bin/tissue | 55 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

(limited to 'bin')

diff --git a/bin/tissue b/bin/tissue
index 6d5625a..9f26992 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -298,32 +298,27 @@ To get usage information for one of these sub-commands, run
           (command-line-program)))
 
 (define (index db-path)
-  "Index current repository into xapian database at DB-PATH. If DB-PATH
-already exists and is up to date, do nothing."
-  (let ((current-head
-         (oid->string (reference-name->oid (current-git-repository) "HEAD"))))
-    (unless (and (file-exists? db-path)
-                 (string=? (call-with-database db-path
-                             (cut Database-get-metadata <> "commit"))
-                           current-head))
-      (guard (c (else (delete-file-recursively db-path)
-                      (format (current-error-port)
-                              "Building xapian index failed.~%")
-                      (raise c)))
-        (delete-file-recursively db-path)
-        (call-with-writable-database db-path
-          (lambda (db)
-            (for-each (lambda (indexed-document)
-                        (let* ((document (slot-set ((indexed-document-reader indexed-document))
-                                                   'web-uri
-                                                   (indexed-document-web-uri indexed-document)))
-                               (term-generator (document-term-generator document)))
-                          (index-text! term-generator (document-type document) #:prefix "XT")
-                          (replace-document! db
-                                             (document-id-term document)
-                                             (TermGenerator-get-document term-generator))))
-                      (tissue-configuration-indexed-documents (load-config)))
-            (WritableDatabase-set-metadata db "commit" current-head)))))))
+  "Index current repository into xapian database at DB-PATH."
+  (guard (c (else (delete-file-recursively db-path)
+                  (format (current-error-port)
+                          "Building xapian index failed.~%")
+                  (raise c)))
+    (delete-file-recursively db-path)
+    (call-with-writable-database db-path
+      (lambda (db)
+        (for-each (lambda (indexed-document)
+                    (let* ((document (slot-set ((indexed-document-reader indexed-document))
+                                               'web-uri
+                                               (indexed-document-web-uri indexed-document)))
+                           (term-generator (document-term-generator document)))
+                      (index-text! term-generator (document-type document) #:prefix "XT")
+                      (replace-document! db
+                                         (document-id-term document)
+                                         (TermGenerator-get-document term-generator))))
+                  (tissue-configuration-indexed-documents (load-config)))
+        (WritableDatabase-set-metadata
+         db "commit" (oid->string (reference-name->oid
+                                   (current-git-repository) "HEAD")))))))
 
 (define (pull state-directory hostname upstream-repository)
   "Pull latest from UPSTREAM-REPOSITORY into STATE-DIRECTORY for
@@ -466,7 +461,13 @@ Pull latest from upstream repositories.
              (unless (file-exists? %state-directory)
                (mkdir %state-directory))
              ;; Ensure index exists, rebuilding it if it is stale.
-             (index %xapian-index)
+             (let ((current-head
+                    (oid->string (reference-name->oid (current-git-repository) "HEAD"))))
+               (unless (and (file-exists? db-path)
+                            (string=? (call-with-database db-path
+                                        (cut Database-get-metadata <> "commit"))
+                                      current-head))
+                 (index %xapian-index)))
              ;; Handle sub-command.
              (apply (match command
                       ("search" tissue-search)
-- 
cgit v1.2.3