| 1 | # cvs.tcl -- |
|---|
| 2 | # |
|---|
| 3 | # Handling of various cvs output formats. |
|---|
| 4 | # |
|---|
| 5 | # Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net> |
|---|
| 6 | # |
|---|
| 7 | # See the file "license.terms" for information on usage and redistribution |
|---|
| 8 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
|---|
| 9 | # |
|---|
| 10 | # RCS: @(#) $Id: cvs.tcl,v 1.7 2005/09/28 04:51:19 andreas_kupries Exp $ |
|---|
| 11 | |
|---|
| 12 | package require Tcl 8.2 |
|---|
| 13 | package require textutil |
|---|
| 14 | |
|---|
| 15 | namespace eval ::doctools {} |
|---|
| 16 | namespace eval ::doctools::cvs { |
|---|
| 17 | namespace export scanLog toChangeLog |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | # ::doctools::cvs::scanLog -- |
|---|
| 21 | # |
|---|
| 22 | # Scan a log generated by 'cvs log' and extract the relevant information. |
|---|
| 23 | # |
|---|
| 24 | # Arguments: |
|---|
| 25 | # text The text to scan |
|---|
| 26 | # |
|---|
| 27 | # Results: |
|---|
| 28 | # None. |
|---|
| 29 | # |
|---|
| 30 | # Sideeffects: |
|---|
| 31 | # None. |
|---|
| 32 | # |
|---|
| 33 | # Notes: |
|---|
| 34 | # Original location of code: http://wiki.tcl.tk/3638 |
|---|
| 35 | # aka http://wiki.tcl.tk/log2changelog |
|---|
| 36 | # Original author unknown. |
|---|
| 37 | # Bugfix by TR / Torsten Reincke |
|---|
| 38 | |
|---|
| 39 | proc ::doctools::cvs::scanLog {text evar cvar fvar} { |
|---|
| 40 | |
|---|
| 41 | set text [split $text \n] |
|---|
| 42 | set n [llength $text] |
|---|
| 43 | |
|---|
| 44 | upvar $evar entries ; #set entries [list] |
|---|
| 45 | upvar $cvar comments ; #array set comments {} |
|---|
| 46 | upvar $fvar files ; #array set files {} |
|---|
| 47 | |
|---|
| 48 | for {set i 0} {$i < $n} {incr i} { |
|---|
| 49 | set line [lindex $text $i] |
|---|
| 50 | switch -glob -- $line { |
|---|
| 51 | "*Working file:*" { |
|---|
| 52 | regexp {Working file: (.*)} $line -> filename |
|---|
| 53 | } |
|---|
| 54 | "date:*" { |
|---|
| 55 | scan $line "date: %s %s author: %s" date time author |
|---|
| 56 | set author [string trim $author ";"] |
|---|
| 57 | |
|---|
| 58 | # read the comment lines following date |
|---|
| 59 | set comment "" |
|---|
| 60 | incr i |
|---|
| 61 | set line [lindex $text $i] |
|---|
| 62 | # [TR]: use regexp here to see if log ends: |
|---|
| 63 | while {(![regexp "(-----*)|(=====*)" $line]) && ($i < $n)} { |
|---|
| 64 | append comment $line "\n" |
|---|
| 65 | incr i |
|---|
| 66 | set line [lindex $text $i] |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | # Store this date/author/comment |
|---|
| 70 | lappend entries [list $date $author] |
|---|
| 71 | lappend comments($date,$author) $comment |
|---|
| 72 | lappend files($date,$author,$comment) $filename |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | return |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | # ::doctools::cvs::toChangeLog -- |
|---|
| 82 | |
|---|
| 83 | # Convert a preprocessed cvs log (see scanLog) into a Changelog |
|---|
| 84 | # suitable for emacs. |
|---|
| 85 | # |
|---|
| 86 | # Arguments: |
|---|
| 87 | # evar, cvar, fvar: Name of the variables containing the preprocessed log. |
|---|
| 88 | # |
|---|
| 89 | # Results: |
|---|
| 90 | # A string containing a properly formatted ChangeLog. |
|---|
| 91 | # |
|---|
| 92 | # Sideeffects: |
|---|
| 93 | # None. |
|---|
| 94 | # |
|---|
| 95 | # Notes: |
|---|
| 96 | # Original location of code: http://wiki.tcl.tk/3638 |
|---|
| 97 | # aka http://wiki.tcl.tk/log2changelog |
|---|
| 98 | # Original author unknown. |
|---|
| 99 | |
|---|
| 100 | proc ::doctools::cvs::toChangeLog {evar cvar fvar} { |
|---|
| 101 | upvar $evar entries |
|---|
| 102 | upvar $cvar comments |
|---|
| 103 | upvar $fvar files |
|---|
| 104 | |
|---|
| 105 | set linebuffer [list] |
|---|
| 106 | |
|---|
| 107 | foreach e [lsort -unique -decreasing $entries] { |
|---|
| 108 | |
|---|
| 109 | # print the date/author |
|---|
| 110 | foreach {date author} $e {break} |
|---|
| 111 | lappend linebuffer "$date $author" |
|---|
| 112 | lappend linebuffer "" |
|---|
| 113 | |
|---|
| 114 | # Find all the comments submitted this date/author |
|---|
| 115 | |
|---|
| 116 | set clist [lsort -unique $comments($date,$author)] |
|---|
| 117 | |
|---|
| 118 | foreach c $clist { |
|---|
| 119 | # Print all files for a given comment |
|---|
| 120 | foreach f [lsort -unique $files($date,$author,$c)] { |
|---|
| 121 | lappend linebuffer "\t* $f:" |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | # Format and print the comment |
|---|
| 125 | |
|---|
| 126 | lappend linebuffer [textutil::indent [textutil::undent $c] "\t "] |
|---|
| 127 | lappend linebuffer "" |
|---|
| 128 | continue |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | return [join $linebuffer \n] |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | #------------------------------------ |
|---|
| 136 | # Module initialization |
|---|
| 137 | |
|---|
| 138 | package provide doctools::cvs 0.1.1 |
|---|