From 7b912bae6f4abcaff41393bc252fab0afd8c1fe2 Mon Sep 17 00:00:00 2001 From: Magali Lemes Date: Sat, 9 Jan 2021 21:18:18 -0300 Subject: scripts: git: log: Manage with different channels. * guix/scripts/git/log.scm (list-channels): New procedure. (get-commits): Retrieve commits from all channels, instead of just one. (%options): By default '--channel-cache-path' lists the paths of all channels. --- guix/scripts/git/log.scm | 50 +++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/guix/scripts/git/log.scm b/guix/scripts/git/log.scm index c5338d43a8..e1fa5a3b3a 100644 --- a/guix/scripts/git/log.scm +++ b/guix/scripts/git/log.scm @@ -19,9 +19,10 @@ (define-module (guix scripts git log) #:use-module (git) #:use-module (guix channels) - #:use-module ((guix git) #:select (url-cache-directory)) + #:use-module (guix git) #:use-module (guix scripts) #:use-module (guix scripts pull) + #:use-module (guix sets) #:use-module (guix ui) #:use-module (ice-9 format) #:use-module (ice-9 match) @@ -43,9 +44,10 @@ (option '("channel-cache-path") #f #t (lambda (opt name arg result) - (alist-cons 'channel-cache-path - (if arg (string->symbol arg) 'guix) - result))) + (if arg + (alist-cons 'channel-cache-path + (string->symbol arg) result) + (list-channels)))) (option '("format") #t #f (lambda (opt name arg result) (unless (member arg %formats) @@ -58,6 +60,14 @@ (define %default-options '()) +(define (list-channels) + (define channels (channel-list '())) + (for-each (lambda (channel) + (format #t "~a~% ~a~%" + (channel-name channel) + (url-cache-directory (channel-url channel)))) + channels)) + (define (show-help) (display (G_ "Usage: guix git log [OPTIONS...] Show Guix commit logs.\n")) @@ -83,6 +93,7 @@ Show Guix commit logs.\n")) (format #t "~a~%" (url-cache-directory (channel-url found-channel))) (leave (G_ "~a: channel not found~%") (symbol->string channel))))) + (define commit-short-id (compose (cut string-take <> 7) oid->string commit-id)) @@ -129,17 +140,18 @@ Show Guix commit logs.\n")) (signature-email committer) (commit-message commit)))))) -;; returns a list of commits from path -(define (get-commits path) - (let* ((repository (repository-open path)) - (latest-commit (commit-lookup repository (reference-target (repository-head repository))))) - (define commits (let loop ((commit latest-commit) - (res (list latest-commit))) - (match (commit-parents commit) - (() (reverse res)) - ((head . tail) - (loop head (cons head res)))))) - commits)) +;; returns a list with commits from all channels +(define (get-commits) + (define channels (channel-list '())) + + (fold (lambda (channel commit-list) + (let* ((channel-path (url-cache-directory (channel-url channel))) + (repository (repository-open channel-path)) + (latest-commit + (commit-lookup repository(reference-target + (repository-head repository))))) + (append (set->list (commit-closure latest-commit)) + commit-list))) '() channels)) (define (guix-git-log . args) (define options @@ -152,13 +164,11 @@ Show Guix commit logs.\n")) (cond (channel-cache (show-channel-cache-path channel-cache)) - (oneline? - (let ((cache (url-cache-directory (channel-url %default-guix-channel)))) + (oneline? (for-each (lambda (commit-list) (show-commit commit-list 'oneline #t)) - (take (get-commits cache) 5)))) + (take (get-commits) 5))) (format-type - (let ((cache (url-cache-directory (channel-url %default-guix-channel)))) (for-each (lambda (commit-list) (show-commit commit-list format-type #f)) - (take (get-commits cache) 5)))))))) + (take (get-commits) 5))))))) -- cgit 1.4.1