Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | another `fixGrep' which is possibly superior since overall easier and faster. |
---|---|
Timelines: | family | ancestors | descendants | both | grep |
Files: | files | file ages | folders |
SHA1: |
ee7ec69ea7c487b87af0fde9b05dcbdb |
User & Date: | j 2019-07-08 16:05:26 |
Context
2019-07-11
| ||
15:29 | removed old `fixGrep' (the newer one is superior) and account for possibility that a single file artifact belongs to multiple checkins when reporting the incremental checkin numbers. check-in: b04bf5a394 user: j tags: grep | |
2019-07-08
| ||
16:05 | another `fixGrep' which is possibly superior since overall easier and faster. check-in: ee7ec69ea7 user: j tags: grep | |
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 | |
Changes
Changes to fsl.
︙ | ︙ | |||
560 561 562 563 564 565 566 | regexp $rgxrev $line rev dict set revnums $rev [expr {$numrev - $revcnt}] } } return $revnums } | > | | | | | | | | | | | | | | | | | | | > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | 560 561 562 563 564 565 566 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 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | regexp $rgxrev $line rev dict set revnums $rev [expr {$numrev - $revcnt}] } } return $revnums } proc fixGrep {lines params grepflags} { 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 {^[^[]+(\[[a-f\d]{10}\])} regexp $rgxpat [lindex $report 4] _ cihash dict set cihashes $fhash $cihash } } return $cihashes } set f1 [last $grepflags] set f2 [first $grepflags] if {$f1 + $f2 > 0} { set buf $lines set lines {} if {$f1} { lappend lines [first $buf] } if {$f2} { lappend lines [last $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 fixGrep {lines params grepflags} { # alternative implementation avoiding `whatis' and using `finfo' # output instead to map file hash to checkin hash. this is faster # when having lots of matching revisions but slower when `-F -L' # are used since we always have to process the complete `finfo' # output. 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 dict set cihashes $fhash \[$cihash\] } set revnums [computeRevnums {}] set f1 [last $grepflags] set f2 [first $grepflags] if {$f1 + $f2 > 0} { set buf $lines set lines {} if {$f1} { lappend lines [first $buf] } if {$f2} { lappend lines [last $buf] } } 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 |
︙ | ︙ | |||
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 | # ------------------------------------------------------------------------ # 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] | > > > > > | 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 | # ------------------------------------------------------------------------ # 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. # ------------------------------------------------------------------------ # THINK: one might consider to convert this to a complete # interceptor, moving all processing from the expect/filter block # here. The benefit would be the added capability to make 'grep' # work on multiple input files (or the whole '[fsl] ls' output). # 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] |
︙ | ︙ | |||
1435 1436 1437 1438 1439 1440 1441 | # Prepare filters: set chain [chain_for $candidate] set chain [expr {[empty? $chain] ? [chain_for $command] : $chain}] set chain [string trimright $chain] # Expect settings: set prior_log [log_user]; # to be reverted before returning | > > > > > > > > > > > > > > | | > < < < < < < < < < < < | 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | # Prepare filters: set chain [chain_for $candidate] set chain [expr {[empty? $chain] ? [chain_for $command] : $chain}] set chain [string trimright $chain] # Expect settings: set prior_log [log_user]; # to be reverted before returning # FIXME: reconcider the overall logic of how to handle log_user # on/off. it is slowly becoming a mess. previously 'log_user 0' # had to be called only if filter chain is non-empty (indicating # that the usual fossil output is going to be processed prior to # display). redefining this filter chain further down to # `passthrough' then is not a problem (as is done for 'timeline' # etc. where the output modifcation is not done by any filter but # in a proc prior to final filtering) but it _is_ a problem for # commands that lead to an empty filter chain (which usually # indicates that one wants just to see the raw fossil output) # while something is still done to their output as is the case for # `grep' now. maybe we can put everything in a grep filter # instead so that this explicit test for 'grep' becomes obsolete: if {![empty? $chain] || $command == "grep"} { log_user 0; # disable logging to stdout } if {![interactive? $params]} { set stty_init -onlcr; # do not map LF to CRLF on output } #ensure that `lines' always exists: set lines {} # Call to `fossil' binary: spawn -noecho fossil {*}$params while 1 { if {[interactive? $params]} { interact; break |
︙ | ︙ |