Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | added a `grep' interceptor to allow for further options. other small edits. |
---|---|
Timelines: | family | ancestors | descendants | both | grep |
Files: | files | file ages | folders |
SHA1: |
1043c975888bdbb9f6130601dcee2ad1 |
User & Date: | j 2019-07-06 16:18:55 |
Context
2019-07-06
| ||
16:24 | reverse order of first/last report to make it consistent with the newest to oldest sorting of `grep' reporting. check-in: ea60fe5655 user: j tags: grep | |
16:18 | added a `grep' interceptor to allow for further options. other small edits. check-in: 1043c97588 user: j tags: grep | |
2019-07-05
| ||
16:52 | a first try at improving/augmenting `fossil grep'. check-in: bd064e74b7 user: j tags: grep | |
Changes
Changes to fsl.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/env expect # -*-tcl-*- # # Copyright (c) 2012, Marc Simpson <marc@0branch.com> (ISC, see LICENSE) # --( Aliases and Filters )--------------------------------------------- namespace eval config { variable dbglvl 0; # debug level variable reset 0; # 1/0: do/don't recreate config file set aliases {} set filters {}; # registered filters set commands {}; # registered interceptors proc manpage {} { set mantext { | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #!/usr/bin/env expect # -*-tcl-*- # # Copyright (c) 2012, Marc Simpson <marc@0branch.com> (ISC, see LICENSE) # --( Aliases and Filters )--------------------------------------------- namespace eval config { variable dbglvl 0; # debug level variable reset 0; # 1/0: do/don't recreate config file variable grepflags ;# needed to pass around info needed by `fixGrep' set aliases {} set filters {}; # registered filters set commands {}; # registered interceptors proc manpage {} { set mantext { |
︙ | ︙ | |||
102 103 104 105 106 107 108 | alias . changes alias .. {changes --differ} alias , ui alias ahelp {test-all-help} alias alog {timeline -t ci -n 0} alias b branch alias d diff | | | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | alias . changes alias .. {changes --differ} alias , ui alias ahelp {test-all-help} alias alog {timeline -t ci -n 0} alias b branch alias d diff alias dd {df -tk} alias de descendants alias desc descendants alias di diff alias elog {timeline -t ci -n 0 -v} alias f {finfo} alias fb {finfo -b} alias fi {finfo} |
︙ | ︙ | |||
174 175 176 177 178 179 180 | changes: { if {[regexp {^changes:[ ]+None. Already up-to-date} $line]} then { regsub {(^changes:[ ]+)(.*)} $line [coloured green &] } else { regsub {(^changes:[ ]+)(.*)} $line [coloured red &] } } | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | changes: { if {[regexp {^changes:[ ]+None. Already up-to-date} $line]} then { regsub {(^changes:[ ]+)(.*)} $line [coloured green &] } else { regsub {(^changes:[ ]+)(.*)} $line [coloured red &] } } default { set line } } } 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... |
︙ | ︙ | |||
365 366 367 368 369 370 371 | underscored 4 reversed 7 } ansi $mode $modes $text } proc coloured {colour text} { set colours { | | | > > > > > > > > > > | | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | underscored 4 reversed 7 } ansi $mode $modes $text } proc coloured {colour text} { set colours { black 0;30 blue 0;34 bluebold 1;34 cyan 0;36 green 0;32 grey 0;37 magenta 0;35 magentabold 1;35 purple 0;35 red 0;31 redbold 1;31 yellow 0;33 } ansi $colour $colours $text } proc alias? {name} { dict exists $config::aliases $name } proc filter? {name} { dict exists $config::filters $name } |
︙ | ︙ | |||
556 557 558 559 560 561 562 | proc cihashLookup {lines} { set cihashes {} foreach line $lines { # FIXME: there must be a nicer way to handle `grep -l' as well, # no? set fhash [string trimright [first [split $line :]]] | | | > > > | > > > > > > > > | > | | 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | proc cihashLookup {lines} { set cihashes {} foreach line $lines { # FIXME: there must be a nicer way to handle `grep -l' as well, # no? set fhash [string trimright [first [split $line :]]] if { [catch {dict get $cihashes $fhash}] } { # no entry, yet, for this file artifact, so we do the lookup. # this is the rate limiting step by a large maring here. # hopefully `fossil grep' will report the checkin hash itself # at some time in the future. set report [split [exec fossil whatis $fhash] \n] set rgxpat {^[^[]+(\[[0-9a-f]+\])} regexp $rgxpat [lindex $report 4] _ cihash dict set cihashes $fhash $cihash } } return $cihashes } proc fixGrep {lines params grepflags} { set f1 [first $grepflags] set f2 [last $grepflags] if {$f1 + $f2 > 0} { set buf $lines set lines {} if {$f1} { lappend lines [last $buf] } if {$f2} { lappend lines [first $buf] } } set cihashes [cihashLookup $lines] set revnums [computeRevnums {}] set greppat [lindex $params end-1] foreach line $lines { set fhash [string trimright [first [split $line :]]] set cihash [dict get $cihashes $fhash] set revnum [dict get $revnums $cihash] # for now, we just preprend the chronological revision numbers and # add a bit of colour regsub -all "(.*?)($greppat)(.*)" $line \\1[coloured redbold \\2]\\3 line lappend out [coloured magenta $revnum]:$line } return $out } proc adjustWidth params { set widopt {} |
︙ | ︙ | |||
1254 1255 1256 1257 1258 1259 1260 | # non-unique (hit > 1) matches (e.g. `fossil a') should not # trigger this block at all. # NO LONGER QUITE RIGHT (st:stat ...), NEEDS RECONSIDERATION. # if {$command != $thematch} { set insert "an abbreviation of `$thematch' and " } else { set insert "" } | | | 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 | # non-unique (hit > 1) matches (e.g. `fossil a') should not # trigger this block at all. # NO LONGER QUITE RIGHT (st:stat ...), NEEDS RECONSIDERATION. # if {$command != $thematch} { set insert "an abbreviation of `$thematch' and " } else { set insert "" } puts "Fossil's `$command' command is ${insert}intercepted by `fsl'." puts "The interceptor does the following:" # extract leading comment block from the interceptor source set src [lindex [dict get $config::commands $command] 1] set lines [split $src \n] foreach line $lines { if {![regexp {^#} $line]} { continue } ;#skip the first line... if {[regexp {^#[ ]?(.*)} $line {} line]} { |
︙ | ︙ | |||
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 | lappend report [format "%10s -> %s" $alias [dict get $config::aliases $alias ]] } puts "Alias definitions:" puts "------------------" puts [join $report \n] } interceptor df|gd:gdf { # ------------------------------------------------------------------------ # drop-in replacement for `fsl (g)di' using hg/svn-style chronological # revision numbers. call as # # fsl (g)df ... -r n(:m) ... | > > > > > > > > > > > > > > > > > > > > > > > > | 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 | lappend report [format "%10s -> %s" $alias [dict get $config::aliases $alias ]] } puts "Alias definitions:" puts "------------------" puts [join $report \n] } interceptor gr:grep { # ------------------------------------------------------------------------ # Extend `grep' by options # -F # -L # to report only _f_irst (oldest) and _l_ast (newest) checkin matching # the pattern. This is frequently what one is interested in. # ------------------------------------------------------------------------ # we set up a 2-element list `grepflags' with 0/1 entries # indicating whether F and L are set. this list is put into the # `config' namespace to make it accessible elsewhere. set grepopts [lrange $params 1 end-2] set grepflags [regexp -- -F $grepopts] lappend grepflags [regexp -- -L $grepopts] set config::grepflags $grepflags # strip the non-standard options since `fossil grep' does not # understand them regsub -all { -(F|L)} $params {} params return $params } interceptor df|gd:gdf { # ------------------------------------------------------------------------ # drop-in replacement for `fsl (g)di' using hg/svn-style chronological # revision numbers. call as # # fsl (g)df ... -r n(:m) ... |
︙ | ︙ | |||
1474 1475 1476 1477 1478 1479 1480 | set revnums [computeRevnums $params] set lines [reformFinfo-b $lines $revnums] } else { set revnums [computeRevnums $params] set lines [reformTimeline $lines $revnums $command] } } elseif {$command == "grep" && [llength $lines] > 1} { | | | 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 | set revnums [computeRevnums $params] set lines [reformFinfo-b $lines $revnums] } else { set revnums [computeRevnums $params] set lines [reformTimeline $lines $revnums $command] } } elseif {$command == "grep" && [llength $lines] > 1} { set lines [fixGrep $lines $params $config::grepflags] set chain ::config::fslrc::passthrough } if {$::config::dbglvl > 1} {puts "*** filter chain: [join $chain ", "]"} foreach line $lines { if {$::config::dbglvl > 98} { |
︙ | ︙ |