From: Chris Hanson Date: Mon, 20 Mar 2000 22:52:51 +0000 (+0000) Subject: Changes to generate ChangeLog-style output, and to support CVS in X-Git-Tag: 20090517-FFI~4192 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=42538299d5253674cc45e5a4ffa49924a9d1f3a9;p=mit-scheme.git Changes to generate ChangeLog-style output, and to support CVS in addition to RCS. --- diff --git a/v7/src/rcs/logmer.scm b/v7/src/rcs/logmer.scm index f794c0ec1..658254ddf 100644 --- a/v7/src/rcs/logmer.scm +++ b/v7/src/rcs/logmer.scm @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: logmer.scm,v 1.19 2000/02/01 01:59:51 cph Exp $ +$Id: logmer.scm,v 1.20 2000/03/20 22:52:26 cph Exp $ Copyright (c) 1988-2000 Massachusetts Institute of Technology @@ -23,92 +23,220 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (declare (usual-integrations)) -(define (rcs-directory-log directory #!optional output-file) - (let ((output-file - (merge-pathnames (if (or (default-object? output-file) - (not output-file)) - "RCS.log" - output-file) - (pathname-as-directory directory))) +(define (rcs-directory-log directory #!optional output-file + changelog? changelog-map) + (let ((changelog? (if (default-object? changelog?) #f changelog?)) + (changelog-map + (if (default-object? changelog-map) + (list (os/hostname)) + changelog-map)) (port (notification-output-port))) - (write-string "regenerating log for directory: " port) - (write (->namestring directory)) - (write-string "..." port) - (let ((pathnames (rcs-directory-read directory))) - (if (let ((time (file-modification-time-indirect output-file))) - (or (not time) - (there-exists? pathnames - (lambda (w.r) - (> (file-modification-time-indirect (cdr w.r)) time))))) - (begin - (newline port) - (write-string "total files: " port) - (write (length pathnames) port) - (newline port) - (let ((entries (read-entries pathnames port))) - (write-string "total entries: " port) - (write (length entries) port) - (newline port) - (let ((entries (sort-entries entries))) - (write-string "sorting finished" port) + (let ((output-file + (merge-pathnames (if (or (default-object? output-file) + (not output-file)) + (if changelog? "ChangeLog" "RCS.log") + output-file) + (pathname-as-directory directory)))) + (fluid-let ((*date-rounds-to-day?* changelog?)) + (write-string "regenerating log for directory: " port) + (write (->namestring directory)) + (write-string "..." port) + (let ((pathnames (rcs-directory-read directory))) + (if (let ((time (file-modification-time-indirect output-file))) + (or (not time) + (there-exists? pathnames + (lambda (w.r) + (> (file-modification-time-indirect (cdr w.r)) + time))))) + (begin (newline port) - (call-with-output-file output-file - (lambda (port) - (format/entries entries port)))))) - (begin - (write-string " log is up to date" port) - (newline port)))))) - -(define (format/entries entries port) - (let ((groups (compress-entries entries))) - (if (not (null? groups)) + (write-string "total files: " port) + (write (length pathnames) port) + (newline port) + (let ((entries (read-entries pathnames port))) + (write-string "total entries: " port) + (write (length entries) port) + (newline port) + (let ((entries + (if changelog? + (sort-entries-for-changelog entries) + (sort-entries-for-rcs.log entries)))) + (write-string "sorting finished" port) + (newline port) + (call-with-output-file output-file + (lambda (port) + (if changelog? + (format-changelog entries changelog-map port) + (format-rcs.log entries port))))))) + (begin + (write-string " log is up to date" port) + (newline port)))))))) + +;;;; RCS.log format + +(define (format-rcs.log entries port) + (let ((groups (group-entries-by-log entries)) + (format-group + (lambda (group) + (for-each (lambda (entry) + (let ((delta (car entry)) + (filename (cdr entry))) + (write-string "file: " port) + (write-string filename port) + (write-string "; revision: " port) + (write-string (delta/number delta) port) + (write-string "\ndate: " port) + (write-string (date->string (delta/date delta)) port) + (write-string "; author: " port) + (write-string (delta/author delta) port) + (newline port))) + group) + (newline port) + (write-string (delta/log (car (car group))) port) + (newline port)))) + (if (pair? groups) (begin - (format/group (car groups) port) + (format-group (car groups)) (for-each (lambda (group) (write-string "----------------------------" port) (newline port) - (format/group group port)) + (format-group group)) + (cdr groups)))))) + +(define (sort-entries-for-rcs.log entries) + (sort entries + (lambda (x y) + (date" port))) + (newline port) + (for-each (lambda (entries) + (newline port) + (write-char #\tab port) + (write-string "* " port) + (write-string (cdar entries) port) + (let loop + ((entries (cdr entries)) + (column (fix:+ 11 (string-length (cdar entries))))) + (if (pair? entries) + (let ((filename (cdar entries))) + (let ((column* + (+ column 2 (string-length filename)))) + (if (fix:>= column* 80) + (begin + (write-string "," port) + (newline port) + (write-char #\tab port) + (write-string " " port) + (write-string filename port) + (loop (cdr entries) + (fix:+ 11 + (string-length filename)))) + (begin + (write-string ", " port) + (write-string filename port) + (loop (cdr entries) column*))))))) + (write-string ":" port) + (newline port) + (format-log-for-changelog (delta/log (caar entries)) + port)) + (group-entries-by-log entries))))) + (if (pair? groups) + (begin + (format-group (car groups)) + (for-each (lambda (group) + (newline port) + (format-group group)) (cdr groups)))))) + +(define (sort-entries-for-changelog entries) + (sort entries + (lambda (x y) + (or (> (date/universal (delta/date (car x))) + (date/universal (delta/date (car y)))) + (and (= (date/universal (delta/date (car x))) + (date/universal (delta/date (car y)))) + (or (stringstring (decoded-time/year dt)) + "-" + (string-pad-left (number->string (decoded-time/month dt)) 2 #\0) + + "-" + (string-pad-left (number->string (decoded-time/day dt)) 2 #\0)))) -(define (format/group group port) - (for-each (lambda (entry) - (format/entry (cdr entry) (car entry) port)) - group) - (newline port) - (write-string (delta/log (car (car group))) port) - (newline port)) - -(define (format/entry filename delta port) - (write-string "file: " port) - (write-string filename port) - (write-string "; revision: " port) - (write-string (delta/number delta) port) - (write-string "\ndate: " port) - (write-string (date->string (delta/date delta)) port) - (write-string "; author: " port) - (write-string (delta/author delta) port) - (write-string "; state: " port) - (write-string (delta/state delta) port) - (newline port)) +(define (format-log-for-changelog log port) + (write-char #\tab port) + (let ((end (string-length log))) + (let loop ((start 0)) + (let ((index (substring-find-next-char log start end #\newline))) + (if index + (let ((index (fix:+ index 1))) + (write-substring log start index port) + (if (fix:< index end) + (begin + (write-char #\tab port) + (loop index)))) + (begin + (write-substring log start end port) + (newline port))))))) -(define (compress-entries entries) - (if (null? entries) - '() - (let ((entry (car entries))) - (let loop - ((entries (cdr entries)) - (receiver - (lambda (similar entries) - (cons (cons entry similar) - (compress-entries entries))))) - (if (or (null? entries) - (not (string=? (delta/log (car entry)) - (delta/log (car (car entries)))))) - (receiver '() entries) - (loop (cdr entries) - (lambda (similar entries*) - (receiver (cons (car entries) similar) - entries*)))))))) +(define (group-entries-by-author&date entries) + (group-entries entries + (lambda (x y) + (and (string=? (delta/author (car x)) + (delta/author (car y))) + (= (date/universal (delta/date (car x))) + (date/universal (delta/date (car y)))))))) + +(define (group-entries-by-log entries) + (group-entries entries + (lambda (x y) + (string=? (delta/log (car x)) + (delta/log (car y)))))) + +(define (group-entries entries predicate) + (let outer ((entries entries) (groups '())) + (if (pair? entries) + (let ((entry (car entries))) + (let inner ((entries (cdr entries)) (group (list entry))) + (if (and (pair? entries) + (predicate entry (car entries))) + (inner (cdr entries) (cons (car entries) group)) + (outer entries (cons (reverse! group) groups))))) + (reverse! groups)))) (define (read-entries pairs notification-port) (let ((prefix (greatest-common-prefix (map car pairs)))) @@ -120,11 +248,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (read-file (cdr w.r) notification-port))) pairs))) -(define (sort-entries entries) - (sort entries - (lambda (x y) - (dateuniversal-time + (if *date-rounds-to-day?* + (make-decoded-time 0 0 0 day month year 0) + dt)))))) -(define (date->string date) - (string-append (date-component->string (date/year date)) - "/" - (date-component->string (date/month date)) - "/" - (date-component->string (date/day date)) - " " - (date-component->string (date/hour date)) - ":" - (date-component->string (date/minute date)) - ":" - (date-component->string (date/second date)) - " GMT")) +(define-integrable (date/decoded date) (car date)) +(define-integrable (date/universal date) (cdr date)) -(define (date-component->string number) - (cond ((zero? number) "00") - ((< number 10) (string-append "0" (write-to-string number))) - (else (write-to-string number)))) +(define-integrable (date->string date) + (decoded-time->string (date/decoded date))) (define-integrable (date