Fossil Wrapper

Check-in [c9f625fef0]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:modified `timeline' processing in order to sanitize output in case `-showfiles' is specified. otherwise some tidy up.
Timelines: family | ancestors | descendants | both | dresden
Files: files | file ages | folders
SHA1: c9f625fef0025962a2a116c3ea3bb47045f90614
User & Date: j 2013-01-15 13:05:07
Context
2013-01-16
14:04
tentative filtering of `finfo' output through `fancy_timeline'. check-in: ae9928cc77 user: j tags: dresden
2013-01-15
13:05
modified `timeline' processing in order to sanitize output in case `-showfiles' is specified. otherwise some tidy up. check-in: c9f625fef0 user: j tags: dresden
2013-01-11
20:53
small fixes. check-in: 37ea358f3a user: j tags: dresden
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

53
54
55
56
57
58
59

60
61
62

63


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
326
327
328
329
330
331
332
333
334
335




336
337
338
339



340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445




446

447
448
449
450
451
452
453
...
509
510
511
512
513
514
515
516

517

518
519
520
521
522
523
524

set config::defaults {
    # -*-tcl-*-

    # -- Aliases:

    alias  .      changes

    alias  d      diff
    alias  di     diff
    alias  not    {extras --dotfiles --ignore ""}

    alias  heads  leaves;       # for hg refugees


    alias  st     status
    alias  stat   status
    alias  time   timeline
    alias  log    {timeline -t ci}
    alias  t      {timeline -t ci}
    alias  ,      ui

    # -- Filters:

    filter status {changes status timeline add rm addremove} {
        lassign [split [string trim $line]] status
        switch $status {
            MERGED_WITH { coloured purple $line }
            ADDED       { coloured  green $line }
            EDITED      { coloured   cyan $line }
            DELETED     { coloured    red $line }
            MISSING     { coloured  blue $line }
................................................................................
            coloured blue $line
        } else {
            regsub -all {\[[A-Fa-f0-9]+\]} $line [coloured yellow &]
        }
    }

   filter fancy_timeline {leaves timeline} {
       if {[regexp "^=== .* ===" $line]} {
           return [coloured yellow $line]
       }
       # Expressions to match:
       set artifact_rx {\[([a-f\d]{4})([^\]]*)\]}
       set date_rx     {^\d\d:\d\d:\d\d}
       set current_rx  {\*CURRENT\*}
       set frkmrg_rx   {\*(FORK|MERGE|BRANCH)\*}
       # Colour the output (repeated substitutions on $line):
       set line [regsub -all $artifact_rx $line\
                     [format {[%s%s]} [coloured red {\1}] {\2}]]
       set line [regsub $date_rx    $line [coloured blue &]]
       set line [regsub $current_rx $line [display reversed &]]
................................................................................
    dict for {alias expansion} $config::aliases {
        puts [format "%10s -> %s" $alias $expansion]
    }
}

proc unwrapTimeline records {
#-----------------------------------------------------------------------
# unwrap `fossil timeline' output, putting each comment on a single
# line. expected input: currently, a list of \n terminated lines.
# (maybe the \n should go away?)




#
# result: a new (probably shorter) list with the unwrapped lines
# (multiple spaces squeezed) 
#-----------------------------------------------------------------------



   set len [llength $records]
   set i 0
   set out {}
   while {$i < $len} {
      set record [lindex $records $i]
      incr i
      if {[regexp {^[0-9]} $record]} {
         set line [lindex $records $i] 
         set line [string trimright "$line"]
         while {[regexp {^ } $line]} {
            set sub { }
            regsub -all {[[:blank:]]+} $line $sub line
            set record "[string trimright ${record}]${line}"

            incr i
            set line [lindex $records $i]
            set line [string trimright $line]
................................................................................
   set rgxtime {^\d\d:\d\d:\d\d}
   set rgxrev {\[([a-f\d]{10})([^\]]*)\]}
   set rgxuser {\(user: .*\)}

   set maxrev [dict size $revnums]

   foreach record $records {
      # temporarily get rid of the record terminating newline:
      set record "[string trimright $record]"

      if {[regexp $rgxdate $record]} {
         # a "date" line is passed through as is (plus linefeeds)
         lappend out $record\n
         continue
      } 


      regexp $rgxtime $record time
      regexp $rgxrev $record rev
      regexp $rgxuser $record usertag
      set numrev [expr { $maxrev - [dict get $revnums $rev] }]
      lappend out "$time $numrev:$rev $usertag\n"
      #lappend out "$time $rev:$numrev\n$usertag\n"

      regsub $rgxuser $record "" record
      regsub $time    $record "" record
      regsub $rgxrev  $record "" record

      set message [string trim $record]
      set words [split $message]
      set line $indent[lindex $words 0]
      set len [string length $line]

      set words [lreplace $words 0 0]
      set wrdnum [llength $words]
      set wrdcnt 0
      foreach word $words {
         incr wrdcnt
         set wrdlen [string length $word]
         set len [expr {$len + 1 + $wrdlen}]
         if {$len <= $maxlen} {
            set line "$line $word"
            set isAppended 0
         } else {
            lappend out $line\n
            set line $indent$word
            set len [string length $line]
            if {$wrdcnt < $wrdnum} {
               set isAppended 1
            } else {set isAppended 0} ;#since the loop stops _now_...
         }
      }
      if {$isAppended == 0} {lappend out $line\n}




      lappend out \n

   }
   return $out
}

proc computeRevnums {} {
#-----------------------------------------------------------------------
# generate a dictionary of SHA1 keys vs. "reverse" revision numbers 
................................................................................
            interact; break
        }
        expect {
            eof { break }
            \n {
            #collect everything and postpone filtering
            lappend lines $expect_out(buffer)
        }   ;# Transfer control to user following prompt:

            -re {[\?:] $} {

                if {![log_user]} {
                    send_user $expect_out(buffer)
                }
                interact -o \n { send_user \r\n }
                break
            }
        }







>


<
>

>
>


<
<

|



|







 







|




|







 







|

|
>
>
>
>




>
>
>









|







 







|



|
|
|
<
<
>
|
|
|
|
|
<

|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
>







 







<
>

>







53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68


69
70
71
72
73
74
75
76
77
78
79
80
81
..
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
...
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
...
402
403
404
405
406
407
408
409
410
411
412
413
414
415


416
417
418
419
420
421

422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
...
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536

set config::defaults {
    # -*-tcl-*-

    # -- Aliases:

    alias  .      changes
    alias  ,      ui
    alias  d      diff
    alias  di     diff

    alias  elog   {timeline -t ci -showfiles}
    alias  heads  leaves;       # for hg refugees
    alias  log    {timeline -t ci}
    alias  not    {extras --dotfiles --ignore ""}
    alias  st     status
    alias  stat   status


    alias  t      {timeline -t ci}
    alias  time   timeline

    # -- Filters:

    filter status {changes status info timeline add rm addremove} {
        lassign [split [string trim $line]] status
        switch $status {
            MERGED_WITH { coloured purple $line }
            ADDED       { coloured  green $line }
            EDITED      { coloured   cyan $line }
            DELETED     { coloured    red $line }
            MISSING     { coloured  blue $line }
................................................................................
            coloured blue $line
        } else {
            regsub -all {\[[A-Fa-f0-9]+\]} $line [coloured yellow &]
        }
    }

   filter fancy_timeline {leaves timeline} {
       if {[regexp "\n=== .* ===" $line]} {
           return [coloured yellow $line]
       }
       # Expressions to match:
       set artifact_rx {\[([a-f\d]{4})([^\]]*)\]}
       set date_rx     {\n\d\d:\d\d:\d\d}
       set current_rx  {\*CURRENT\*}
       set frkmrg_rx   {\*(FORK|MERGE|BRANCH)\*}
       # Colour the output (repeated substitutions on $line):
       set line [regsub -all $artifact_rx $line\
                     [format {[%s%s]} [coloured red {\1}] {\2}]]
       set line [regsub $date_rx    $line [coloured blue &]]
       set line [regsub $current_rx $line [display reversed &]]
................................................................................
    dict for {alias expansion} $config::aliases {
        puts [format "%10s -> %s" $alias $expansion]
    }
}

proc unwrapTimeline records {
#-----------------------------------------------------------------------
# unwrap `fossil timeline' output, putting each checkin on a single
# line. expected input: currently, a list of \n terminated lines.
# (maybe the \n should go away?). continuation lines belonging
# to the checkin message (including the trailing user/tags info)
# are identified by a leading indent of 10 blanks. all other
# lines (notably file status lines as delivered by 
# `timeline -showfiles') are passed through as is.
#
# result: a new (probably shorter) list with the unwrapped lines
# (multiple spaces squeezed) 
#-----------------------------------------------------------------------
   # this pattern is taken to identify checkin message continuation lines:
   set indent {^[ ]{9}}   

   set len [llength $records]
   set i 0
   set out {}
   while {$i < $len} {
      set record [lindex $records $i]
      incr i
      if {[regexp {^[0-9]} $record]} {
         set line [lindex $records $i] 
         set line [string trimright "$line"]
         while {[regexp $indent $line]} {
            set sub { }
            regsub -all {[[:blank:]]+} $line $sub line
            set record "[string trimright ${record}]${line}"

            incr i
            set line [lindex $records $i]
            set line [string trimright $line]
................................................................................
   set rgxtime {^\d\d:\d\d:\d\d}
   set rgxrev {\[([a-f\d]{10})([^\]]*)\]}
   set rgxuser {\(user: .*\)}

   set maxrev [dict size $revnums]

   foreach record $records {
      # temporarily get rid of the record/line terminating newline:
      set record "[string trimright $record]"

      if {[regexp $rgxdate $record]} {
         # a "date" line is passed through (plus additional linefeed):
         lappend out \n$record\n
      } elseif {[regexp $rgxrev $record]} {


         # this line contains the checkin message:
         regexp $rgxtime $record time
         regexp $rgxrev $record rev
         regexp $rgxuser $record usertag
         set numrev [expr { $maxrev - [dict get $revnums $rev] }]
         lappend out "\n$time $numrev:$rev $usertag\n"


         regsub $rgxuser $record "" record
         regsub $time    $record "" record
         regsub $rgxrev  $record "" record

         set message [string trim $record]
         set words [split $message]
         set line $indent[lindex $words 0]
         set len [string length $line]

         set words [lreplace $words 0 0]
         set wrdnum [llength $words]
         set wrdcnt 0
         foreach word $words {
            incr wrdcnt
            set wrdlen [string length $word]
            set len [expr {$len + 1 + $wrdlen}]
            if {$len <= $maxlen} {
               set line "$line $word"
               set isAppended 0
            } else {
               lappend out $line\n
               set line $indent$word
               set len [string length $line]
               if {$wrdcnt < $wrdnum} {
                  set isAppended 1
               } else {set isAppended 0} ;#since the loop stops _now_...
            }
         }
         if {$isAppended == 0} {lappend out $line\n}
      } else {
         # should be a file status line as delivered by `-showfiles' (since
         # it is neither matching `rgxdate' nor `rgxrev') and is passed 
         # through as is.
         lappend out $record\n
      }
   }
   return $out
}

proc computeRevnums {} {
#-----------------------------------------------------------------------
# generate a dictionary of SHA1 keys vs. "reverse" revision numbers 
................................................................................
            interact; break
        }
        expect {
            eof { break }
            \n {
            #collect everything and postpone filtering
            lappend lines $expect_out(buffer)

        }
            -re {[\?:] $} {
                # Transfer control to user following prompt:
                if {![log_user]} {
                    send_user $expect_out(buffer)
                }
                interact -o \n { send_user \r\n }
                break
            }
        }