;;; tissue --- Text based issue tracker ;;; Copyright © 2022, 2023 Arun Isaac ;;; ;;; 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 . (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-hash doc:commit-author doc:commit-author-date commits-in-current-repository)) (define-class () (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 )) "Return the ID term for COMMIT." (string-append "Qcommit." (commit-hash commit))) (define-method (document-boolean-terms (commit )) "Return the boolean terms in COMMIT." (list (string-append "Qcommit." (commit-hash commit)) (string-append "A" (doc:commit-author commit)))) (define-method (document-recency-date (commit )) "Return a date representing the recency of COMMIT." (doc:commit-author-date commit)) (define-method (document-text (commit )) "Return the full text of COMMIT." (commit-message (commit-lookup (current-git-repository) (string->oid (commit-hash commit))))) (define-method (print (commit ) mset port) "Print COMMIT, a 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 (repository-commits repository) "Return a list of objects representing commits in REPOSITORY." (fold-commits (lambda (commit result) (cons (make #: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) ;; The snippet source text excludes the ;; first paragraph (i.e., the summary line) ;; of the commit. Hence, we use commit-body. #:snippet-source-text (commit-body (commit-lookup (current-git-repository) (commit-id commit)))) result)) (list) repository)) (define (commits-in-current-repository) "Return a list of objects representing commits in current repository." (repository-commits (current-git-repository)))