Fossil Wrapper

Check-in [dee40a390a]
Login

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

Overview
Comment:more flexible pattern for localizing the sha1/3 hashes (allowing for adjusting the no. of displayed hash digits via `fossil set hash-digits'). empirically, `fossil' displays at least 6 digits irrespective of a possibly smaller hash-digits setting. hence the {6,} or {2,} repetitions in the assorted patterns.
Timelines: family | ancestors | descendants | both | dresden
Files: files | file ages | folders
SHA1: dee40a390af3ff9bf7a041397525c2a11191c334
User & Date: j 2019-11-13 13:17:18
Context
2019-11-14
22:28
a hack to make grep work for non-standard hash-digits setting. Leaf check-in: 23d147961a user: j tags: dresden
2019-11-13
13:17
more flexible pattern for localizing the sha1/3 hashes (allowing for adjusting the no. of displayed hash digits via `fossil set hash-digits'). empirically, `fossil' displays at least 6 digits irrespective of a possibly smaller hash-digits setting. hence the {6,} or {2,} repetitions in the assorted patterns. check-in: dee40a390a user: j tags: dresden
2019-10-16
13:26
give up on hard-coding a list of valid commands (to decrease latency minimally) and use a dynamic list instead. check-in: a721f86fe9 user: j tags: dresden
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
...
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
....
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
....
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
....
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
....
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
....
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
....
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
    alias  f      {finfo}
    alias  fb     {finfo -b}
    alias  fi     {finfo}
    alias  flog   {finfo}
    alias  heads  leaves;       # for hg refugees
    alias  log    {timeline -t ci}
    alias  not    {extras --dotfiles --ignore {}}
    alias  s      {changes --differ}     ;# instead of redundandt `show' interceptor...
    alias  t      {timeline -t ci}
    alias  ticks  {ticket show 1}
    alias  time   {timeline}

    # -- Filters:

    filter status {
................................................................................
    filter colorizeOutput {finfo leaves status} {
        # this used to be `fancy_timeline'. but is now used much less
        # since most of the work is relocated to `reformTimeline'
        # the regex/regsubs below could be tidied up, accordingly...
        #
        # Expressions to match:
        set revnum_rx   {(\]:)(\d+)}
        set artifact_rx {\[([a-f\d]{4})([a-f\d]{6}\]*)\]}
        set date_rx     {(^|\n|([ ]*\(\d+\) ))((=== )?\d{4}-\d\d-\d\d( ===)?)}
        set time_rx     {\d\d:\d\d:\d\d (UTC)?}
        set current_rx  {\*CURRENT\*}
        set frkmrg_rx   {\*(FORK|MERGE|BRANCH)\*}
        # Colour the output (repeated substitutions on $line):
        set line [regsub $date_rx    $line \\2[coloured blue \\3\\6]]
        set line [regsub $time_rx    $line [coloured yellow &]]
................................................................................
   if {$::config::dbglvl > 98} then {set origlines $lines}

   # join all lines to enable matching patterns across line boundaries:
   set timeline [join $lines ""]

   set rgxdate {(\d{4}-\d\d-\d\d)}
   set rgxtime {(\d\d:\d\d:\d\d)}
   set rgxsha1 {(\[[a-f\d]{10}\])}

   set rgxtimd {}
   set rgxdatehead {}
   set rgxrev {}
   append rgxtimd {(^|\n)} "\($rgxtime|$rgxdate\)"
   append rgxdatehead {(^|\n)(=== )} $rgxdate {( ===)(\n)}
   set rgxarti {(\[)([a-f\d]{4})([a-f\d]{6}\])(:)([0-9-]+)}
   append rgxrev $rgxtimd { } $rgxsha1
   set rgxuser {( \()(user:( |(\n\s+)))([^\s]+)}
   set rgxtags {( (tags|branch):)([^)]+)(\))}
   set rgxcurr {\*CURRENT\*}
   set rgxfmbr {\*(FORK|MERGE|BRANCH)\*}

   set p1      {(--- (line|entry) limit \([0-9]+\) reached ---)}
................................................................................

proc reformFinfo-b {lines revnums} {
#--------------------------------------------------
# `finfo -b' needs some special treatment prior to
# further filtering/colorizing
#--------------------------------------------------
   set out {}
   set rgxrev {^([a-f\d]{10})}
   set cinum  [dict size $revnums]
   set ciwid  [string length $cinum]

   foreach line $lines {
      set words [split $line]

      set rev [lindex $words 0]
................................................................................
proc computeRevnums {params} {
#-----------------------------------------------------------------------
# generate a dictionary of SHA1 keys vs. revision numbers
#-----------------------------------------------------------------------
   set revcnt  0
   set numrev  0
   set rgxtime {^\d\d:\d\d:\d\d}
   set rgxrev  {\[([a-f\d]{10})([^\]]*)\]}
   set rgxrepo {\-R\s+.+}
   set repo    {}

   regexp $rgxrepo $params repo
   if { [catch {exec fossil timeline -t ci -n 0 -W 0 {*}$repo} timeline] } {
      puts $timeline
      exit 1
................................................................................
   return $revnums
}

proc fixGrep {lines params grepflags} {
   set fname [last $params]
   set finfo [lrange [split [exec fossil finfo -W 0 $fname] \n] 1 end]
   set rgxdate {^\d{4}-\d\d-\d\d}
   set rgxhash {\[([a-f\d]{10})\]}
   foreach line $finfo {
      regexp "$rgxdate $rgxhash" $line _ cihash
      regexp ", artifact: $rgxhash, branch: .*\\)" $line _ fhash
      # an artifact 'fhash' can be part of multiple checkins. so we
      # have to collect all of them via `dict lappend'
      dict lappend cihashes $fhash \[$cihash\]
   }
................................................................................
   }
   regsub $args $args0 {} opts

   set version [lindex $args 0]
   if { $version != "" } then {
      set hash2num [computeRevnums {}]
      dict for {key val} $hash2num {
         regexp {[a-f\d]{10}} $key sha1
         dict set num2hash $val $sha1
      }
      if {[dict exists $num2hash $version]} {
         set version [dict get $num2hash $version]
         set args [lreplace $args 0 0 $version]
      }
   }
................................................................................
# Note: tentative interpretation of UUID as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{10}} $key sha1
      dict set num2hash $val $sha1
   }
   # we assume canonical use of `amend' as described in its manpage:
   # uuid can be expected to be the first argument.
   set uuid [lindex $params 1]
   if {[dict exists $num2hash $uuid]} {
      set version [dict get $num2hash $uuid]
................................................................................
# Note: tentative interpretation of VERSION as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{10}} $key sha1
      dict set num2hash $val $sha1
   }

   set rflagpos  [lsearch $params {-r}]
   set revnumpos [expr $rflagpos + 1]
   set version   [lindex $params $revnumpos]

................................................................................
# Note: tentative interpretation of VERSION as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{10}} $key sha1
      dict set num2hash $val $sha1
   }

   set version [last $params]
   if {[dict exists $num2hash $version]} {
      set version [dict get $num2hash $version]
      set params [lreplace $params end end $version]
................................................................................
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]

   # exchange keys and values in the above dictonary. at the same time,
   # strip the square brackets around the hash value:
   dict for {key val} $hash2num {
      regexp {[a-f\d]{10}} $key sha1
      dict set num2hash $val $sha1
   }

   set tversion {}
   set fversion {}
   set fidx 0
   set tidx 0
................................................................................
   if {![regexp $rgxopt $params revarg]} {return $params}

   set hash2num [computeRevnums {}]

   # exchange keys and values in the above dictonary. at the same time,
   # strip the square brackets around the hash value:
   dict for {key val} $hash2num {
      regexp {[a-f\d]{10}} $key sha1
      dict set num2hash $val $sha1
   }

   # translate rev. numbers to sha1 hashes and construct the
   # required `diff' arguments:
   regexp $rgxrevnum $revarg numbers
   set revs   [split $numbers :]







|







 







|







 







|






|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
...
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
...
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
....
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
....
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
....
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
....
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
....
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
....
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
    alias  f      {finfo}
    alias  fb     {finfo -b}
    alias  fi     {finfo}
    alias  flog   {finfo}
    alias  heads  leaves;       # for hg refugees
    alias  log    {timeline -t ci}
    alias  not    {extras --dotfiles --ignore {}}
    alias  s      {changes --differ}     ;# instead of redundant `show' interceptor...
    alias  t      {timeline -t ci}
    alias  ticks  {ticket show 1}
    alias  time   {timeline}

    # -- Filters:

    filter status {
................................................................................
    filter colorizeOutput {finfo leaves status} {
        # this used to be `fancy_timeline'. but is now used much less
        # since most of the work is relocated to `reformTimeline'
        # the regex/regsubs below could be tidied up, accordingly...
        #
        # Expressions to match:
        set revnum_rx   {(\]:)(\d+)}
        set artifact_rx {\[([a-f\d]{4})([a-f\d]{2,}\]*)\]}
        set date_rx     {(^|\n|([ ]*\(\d+\) ))((=== )?\d{4}-\d\d-\d\d( ===)?)}
        set time_rx     {\d\d:\d\d:\d\d (UTC)?}
        set current_rx  {\*CURRENT\*}
        set frkmrg_rx   {\*(FORK|MERGE|BRANCH)\*}
        # Colour the output (repeated substitutions on $line):
        set line [regsub $date_rx    $line \\2[coloured blue \\3\\6]]
        set line [regsub $time_rx    $line [coloured yellow &]]
................................................................................
   if {$::config::dbglvl > 98} then {set origlines $lines}

   # join all lines to enable matching patterns across line boundaries:
   set timeline [join $lines ""]

   set rgxdate {(\d{4}-\d\d-\d\d)}
   set rgxtime {(\d\d:\d\d:\d\d)}
   set rgxsha1 {(\[[a-f\d]{6,}\])}

   set rgxtimd {}
   set rgxdatehead {}
   set rgxrev {}
   append rgxtimd {(^|\n)} "\($rgxtime|$rgxdate\)"
   append rgxdatehead {(^|\n)(=== )} $rgxdate {( ===)(\n)}
   set rgxarti {(\[)([a-f\d]{4})([a-f\d]{2,}\])(:)([0-9-]+)}
   append rgxrev $rgxtimd { } $rgxsha1
   set rgxuser {( \()(user:( |(\n\s+)))([^\s]+)}
   set rgxtags {( (tags|branch):)([^)]+)(\))}
   set rgxcurr {\*CURRENT\*}
   set rgxfmbr {\*(FORK|MERGE|BRANCH)\*}

   set p1      {(--- (line|entry) limit \([0-9]+\) reached ---)}
................................................................................

proc reformFinfo-b {lines revnums} {
#--------------------------------------------------
# `finfo -b' needs some special treatment prior to
# further filtering/colorizing
#--------------------------------------------------
   set out {}
   set rgxrev {^([a-f\d]{6,})}
   set cinum  [dict size $revnums]
   set ciwid  [string length $cinum]

   foreach line $lines {
      set words [split $line]

      set rev [lindex $words 0]
................................................................................
proc computeRevnums {params} {
#-----------------------------------------------------------------------
# generate a dictionary of SHA1 keys vs. revision numbers
#-----------------------------------------------------------------------
   set revcnt  0
   set numrev  0
   set rgxtime {^\d\d:\d\d:\d\d}
   set rgxrev  {\[([a-f\d]{6,})([^\]]*)\]}
   set rgxrepo {\-R\s+.+}
   set repo    {}

   regexp $rgxrepo $params repo
   if { [catch {exec fossil timeline -t ci -n 0 -W 0 {*}$repo} timeline] } {
      puts $timeline
      exit 1
................................................................................
   return $revnums
}

proc fixGrep {lines params grepflags} {
   set fname [last $params]
   set finfo [lrange [split [exec fossil finfo -W 0 $fname] \n] 1 end]
   set rgxdate {^\d{4}-\d\d-\d\d}
   set rgxhash {\[([a-f\d]{6,})\]}
   foreach line $finfo {
      regexp "$rgxdate $rgxhash" $line _ cihash
      regexp ", artifact: $rgxhash, branch: .*\\)" $line _ fhash
      # an artifact 'fhash' can be part of multiple checkins. so we
      # have to collect all of them via `dict lappend'
      dict lappend cihashes $fhash \[$cihash\]
   }
................................................................................
   }
   regsub $args $args0 {} opts

   set version [lindex $args 0]
   if { $version != "" } then {
      set hash2num [computeRevnums {}]
      dict for {key val} $hash2num {
         regexp {[a-f\d]{6,}} $key sha1
         dict set num2hash $val $sha1
      }
      if {[dict exists $num2hash $version]} {
         set version [dict get $num2hash $version]
         set args [lreplace $args 0 0 $version]
      }
   }
................................................................................
# Note: tentative interpretation of UUID as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{6,}} $key sha1
      dict set num2hash $val $sha1
   }
   # we assume canonical use of `amend' as described in its manpage:
   # uuid can be expected to be the first argument.
   set uuid [lindex $params 1]
   if {[dict exists $num2hash $uuid]} {
      set version [dict get $num2hash $uuid]
................................................................................
# Note: tentative interpretation of VERSION as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{6,}} $key sha1
      dict set num2hash $val $sha1
   }

   set rflagpos  [lsearch $params {-r}]
   set revnumpos [expr $rflagpos + 1]
   set version   [lindex $params $revnumpos]

................................................................................
# Note: tentative interpretation of VERSION as chronological revison number
# takes precedence. If you actually mean the SHA1 hash you might need to
# provide a longer initial segment to disambiguate it (e.g. 1234 might not
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   dict for {key val} $hash2num {
      regexp {[a-f\d]{6,}} $key sha1
      dict set num2hash $val $sha1
   }

   set version [last $params]
   if {[dict exists $num2hash $version]} {
      set version [dict get $num2hash $version]
      set params [lreplace $params end end $version]
................................................................................
# suffice if there are already so many checkins).
# ----------------------------------------------------------------------------
   set hash2num [computeRevnums {}]

   # exchange keys and values in the above dictonary. at the same time,
   # strip the square brackets around the hash value:
   dict for {key val} $hash2num {
      regexp {[a-f\d]{6,}} $key sha1
      dict set num2hash $val $sha1
   }

   set tversion {}
   set fversion {}
   set fidx 0
   set tidx 0
................................................................................
   if {![regexp $rgxopt $params revarg]} {return $params}

   set hash2num [computeRevnums {}]

   # exchange keys and values in the above dictonary. at the same time,
   # strip the square brackets around the hash value:
   dict for {key val} $hash2num {
      regexp {[a-f\d]{6,}} $key sha1
      dict set num2hash $val $sha1
   }

   # translate rev. numbers to sha1 hashes and construct the
   # required `diff' arguments:
   regexp $rgxrevnum $revarg numbers
   set revs   [split $numbers :]