Fossil Wrapper

Check-in [bd064e74b7]
Login

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

Overview
Comment:a first try at improving/augmenting `fossil grep'.
Timelines: family | ancestors | descendants | both | grep
Files: files | file ages | folders
SHA1: bd064e74b76aa24428ea143eb2640290ce8b8ed9
User & Date: j 2019-07-05 16:52:59
Context
2019-07-06
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
16:50
one bug and one regression less. check-in: 6933053d49 user: j tags: dresden
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

548
549
550
551
552
553
554


































555
556
557
558
559
560
561
         incr revcnt
         regexp $rgxrev $line rev
         dict set revnums $rev [expr {$numrev - $revcnt}]
      }
   }
   return $revnums
}



































proc adjustWidth params {
   set widopt {}
   regexp -- {(timeline|finfo|search|descendants).*(-W)} $params widopt
   if {$widopt == ""} then {
      # determine total number of checkins for computation of required
      # additional space. the following works for the current format of







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







548
549
550
551
552
553
554
555
556
557
558
559
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
         incr revcnt
         regexp $rgxrev $line rev
         dict set revnums $rev [expr {$numrev - $revcnt}]
      }
   }
   return $revnums
}

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} dum] }  {
         # no entry, yet, for this file artifact ...
         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} {
   set revnums [computeRevnums $params]
   set cihashes [cihashLookup $lines]
   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 red \\2]\\3 line
      lappend out [coloured magenta $revnum]:$line
   }
   return $out
}

proc adjustWidth params {
   set widopt {}
   regexp -- {(timeline|finfo|search|descendants).*(-W)} $params widopt
   if {$widopt == ""} then {
      # determine total number of checkins for computation of required
      # additional space. the following works for the current format of
1361
1362
1363
1364
1365
1366
1367











1368
1369
1370
1371
1372
1373
1374
    if {![empty? $chain]} {
        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







>
>
>
>
>
>
>
>
>
>
>







1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
    if {![empty? $chain]} {
        log_user 0;             # disable logging to stdout
    }
    if {![interactive? $params]} {
        set stty_init -onlcr;   # do not map LF to CRLF on output
    }

    # FIXME: reconcider the overall logic of how to handle log_user
    # on/off. it is slowly becoming a mess. previously log_user was
    # off if the filter chain is empty. *re*setting the filter chain
    # to `passthrough' then is not a problem (as is done for
    # 'timeline' etc.) but it _is_ a problem for commands that lead to
    # an empty filter chain while something is done to their output
    # elsewhere, 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 {$command == "grep"} { log_user 0 }

    #ensure that `lines' always exists:
    set lines {}
    # Call to `fossil' binary:
    spawn -noecho fossil {*}$params
    while 1 {
        if {[interactive? $params]} {
            interact; break
1428
1429
1430
1431
1432
1433
1434



1435
1436
1437
1438
1439
1440
1441
          } elseif {[regexp {finfo.*-b} $params]} {
             set revnums [computeRevnums $params]
             set lines [reformFinfo-b $lines $revnums]
          } else {
             set revnums [computeRevnums $params]
             set lines [reformTimeline $lines $revnums $command]
          }



       }

       if {$::config::dbglvl > 1} {puts "*** filter chain: [join $chain ", "]"}

       foreach line $lines {
          if {$::config::dbglvl > 98} {
             catch {puts "IN: >$line<"}







>
>
>







1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
          } elseif {[regexp {finfo.*-b} $params]} {
             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]
             set chain ::config::fslrc::passthrough
       }

       if {$::config::dbglvl > 1} {puts "*** filter chain: [join $chain ", "]"}

       foreach line $lines {
          if {$::config::dbglvl > 98} {
             catch {puts "IN: >$line<"}