diff options
author | Arun Isaac | 2022-07-09 16:38:46 +0530 |
---|---|---|
committer | Arun Isaac | 2022-07-09 16:45:20 +0530 |
commit | fc8cf0ed8a5bd1507865df888a37ac5e90a46416 (patch) | |
tree | a3ca3075819531898d5d0d10afa5c408315fc4e1 | |
parent | 693d4c492c760794df7186058f95e12f91cfc2be (diff) | |
download | tissue-fc8cf0ed8a5bd1507865df888a37ac5e90a46416.tar.gz tissue-fc8cf0ed8a5bd1507865df888a37ac5e90a46416.tar.lz tissue-fc8cf0ed8a5bd1507865df888a37ac5e90a46416.zip |
commit: Index commit messages too.
* tissue/commit.scm: New file.
* tissue/web/server.scm (%css)[.search-result-commit]: Add COMMIT
marker.
* bin/tissue: Import (tissue commit).
* tissue.scm (#:indexed-documents): Add commits.
* issues/index-commit-messages.gmi: Close issue.
-rwxr-xr-x | bin/tissue | 1 | ||||
-rw-r--r-- | issues/index-commit-messages.gmi | 6 | ||||
-rw-r--r-- | tissue.scm | 16 | ||||
-rw-r--r-- | tissue/commit.scm | 125 | ||||
-rw-r--r-- | tissue/web/server.scm | 5 |
5 files changed, 147 insertions, 6 deletions
@@ -38,6 +38,7 @@ exec guile --no-auto-compile -s "$0" "$@" (git) (xapian wrap) (xapian xapian) + (tissue commit) (tissue document) (tissue git) (tissue issue) diff --git a/issues/index-commit-messages.gmi b/issues/index-commit-messages.gmi index 54ab253..5c5ad12 100644 --- a/issues/index-commit-messages.gmi +++ b/issues/index-commit-messages.gmi @@ -5,3 +5,9 @@ Currently, we only index issues and other documents. We could also index commit messages. If a project is in the habit of writing long detailed story-like commit messages, this feature could be very useful. I have always been frustrated by the lack of stemming when searching commit messages with git log --grep. If we can index commit messages, could we even index commit diffs and source files as well? Perhaps there is something about source code that makes it harder to index? + +## Resolution + +Commit messages are now indexed. We can revisit indexing commit diffs and source code later, if need be. + +* closed @@ -1,10 +1,16 @@ (tissue-configuration #:project "tissue" - #:indexed-documents (map (lambda (filename) - (slot-set (read-gemtext-issue filename) - 'web-uri - (string-append "/" (string-remove-suffix ".gmi" filename)))) - (gemtext-files-in-directory "issues")) + #:indexed-documents (append (map (lambda (filename) + (slot-set (read-gemtext-issue filename) + 'web-uri + (string-append "/" (string-remove-suffix ".gmi" filename)))) + (gemtext-files-in-directory "issues")) + (map (lambda (commit) + (slot-set commit + 'web-uri + (string-append "https://git.systemreboot.net/tissue/commit/?id=" + (commit-hash commit)))) + (commits-in-current-repository))) #:web-files (cons (file "index.html" (skribe-exporter "website/index.skb")) (filter-map (lambda (filename) diff --git a/tissue/commit.scm b/tissue/commit.scm new file mode 100644 index 0000000..2ff6553 --- /dev/null +++ b/tissue/commit.scm @@ -0,0 +1,125 @@ +;;; tissue --- Text based issue tracker +;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of tissue. +;;; +;;; tissue is free software: you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; tissue is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with tissue. If not, see <https://www.gnu.org/licenses/>. + +(define-module (tissue commit) + #:use-module (oop goops) + #:use-module (term ansi-color) + #:use-module (git) + #:use-module (tissue document) + #:use-module (tissue git) + #:use-module (tissue person) + #:use-module (tissue utils) + #:export (<commit> + commit-hash + doc:commit-author + doc:commit-author-date + commits-in-current-repository)) + +(define-class <commit> (<document>) + (hash #:getter commit-hash #:init-keyword #:hash) + ;; We prefix commit-author and commit-author-date with doc: in order + ;; to not conflict with similarly named functions from (git) and + ;; (tissue git). + (author #:getter doc:commit-author #:init-keyword #:author) + (author-date #:getter doc:commit-author-date #:init-keyword #:author-date)) + +(define-method (document-id-term (commit <commit>)) + "Return the ID term for DOCUMENT." + (string-append "Qcommit." (commit-hash commit))) + +(define-method (document-term-generator (commit <commit>)) + "Return a term generator indexing COMMIT." + (let ((term-generator (next-method))) + (index-person! term-generator (doc:commit-author commit) "A") + term-generator)) + +(define-method (document-snippet-source-text (commit <commit>)) + "Return the source text for COMMIT from which to extract a search +result snippet." + (commit-body + (commit-lookup (current-git-repository) + (string->oid (commit-hash commit))))) + +(define-method (document-text (commit <commit>)) + "Return the full text of COMMIT." + (commit-message + (commit-lookup (current-git-repository) + (string->oid (commit-hash commit))))) + +(define-method (print (commit <commit>) mset port) + "Print COMMIT, a <commit> object, to PORT as part of command-line +search results. MSET is the xapian MSet object representing a list of +search results." + (display (colorize-string (document-title commit) 'MAGENTA 'UNDERLINE) + port) + (newline port) + (display (colorize-string "COMMIT" 'BOLD 'YELLOW) + port) + (display " " port) + (display (colorize-string (commit-hash commit) 'YELLOW) + port) + (newline port) + (display (string-append + "authored " + (colorize-string (human-date-string (doc:commit-author-date commit)) 'CYAN) + " by " + (colorize-string (doc:commit-author commit) 'CYAN)) + port) + (newline port) + (let ((snippet (document-snippet commit mset))) + (unless (string-null? snippet) + (display snippet port) + (newline port) + (newline port)))) + +(define-method (document->sxml (commit <commit>) mset) + "Render COMMIT, a <commit> object, to SXML. MSET is the xapian MSet +object representing a list of search results." + `(li (@ (class ,(string-append "search-result search-result-commit"))) + (a (@ (href ,(document-web-uri commit)) + (class "search-result-title")) + ,(document-title commit)) + (div (@ (class "search-result-metadata")) + ,(string-append + (format #f "authored ~a by ~a" + (human-date-string (doc:commit-author-date commit)) + (doc:commit-author commit)))) + ,@(let ((snippet (document-sxml-snippet commit mset))) + (if snippet + (list `(div (@ (class "search-result-snippet")) + ,@snippet)) + (list))))) + +(define (repository-commits repository) + "Return a list of <commit> objects representing commits in +REPOSITORY." + (fold-commits (lambda (commit result) + (cons (make <commit> + #:title (commit-summary commit) + #:hash (oid->string (commit-id commit)) + #:author (resolve-alias (signature-name (commit-author commit)) + (%aliases)) + #:author-date (commit-author-date commit)) + result)) + (list) + repository)) + +(define (commits-in-current-repository) + "Return a list of <commit> objects representing commits in current +repository." + (repository-commits (current-git-repository))) diff --git a/tissue/web/server.scm b/tissue/web/server.scm index 6b6f088..39d63e2 100644 --- a/tissue/web/server.scm +++ b/tissue/web/server.scm @@ -70,7 +70,9 @@ form { text-align: center; } font-size: larger; } .search-result-title, .search-result-title:before { vertical-align: middle; } -.search-result-document .search-result-title:before, .search-result-issue .search-result-metadata:before { +.search-result-commit .search-result-metadata:before, +.search-result-document .search-result-title:before, +.search-result-issue .search-result-metadata:before { font-size: xx-small; font-weight: bold; margin: 0 0.2em; @@ -78,6 +80,7 @@ form { text-align: center; } background-color: darkmagenta; color: white; } +.search-result-commit .search-result-metadata:before { content: \"COMMIT\"; } .search-result-document .search-result-title:before { content: \"DOC\"; } .search-result-open-issue .search-result-metadata:before { content: \"ISSUE\"; |