Fossil Wrapper

Check-in [b04bf5a394]
Login

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

Overview
Comment: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.
Timelines: family | ancestors | descendants | both | grep
Files: files | file ages | folders
SHA1: b04bf5a394e86f6fa2786a00823e4ccaeac8acba
User & Date: j 2019-07-11 15:29:55
Context
2019-07-11
17:13
beautify the output somewhat. use alternating colors to separate between adjacent hashes/checkins in the output. check-in: 4e76e7d42b user: j tags: grep
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

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
641
642
643
644
645
646
647
648
649
         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
      regsub -all "(.*?)($greppat)(.*)" $line \\1[coloured redbold \\2]\\3 line
      lappend out [coloured magenta $revnum]:$line
   }
   return $out
}

proc adjustWidth params {
   set widopt {}
   regexp -- {(timeline|finfo|search|descendants).*(-W)} $params widopt







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







>
>
|












>
>
>
>
>
|
>
>

>
>
|
>
>
>
|
|
<
|







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
         dict set revnums $rev [expr {$numrev - $revcnt}]
      }
   }
   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\]
   }
   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 {
      # need to separate file hash and line number to match `greppat'
      # against the real line content (so that anchoring of the
      # pattern works and spurious coloring of hash or line number
      # is prevented).
      set field  [split $line :]
      set fhash  [string trimright [first $field]]
      set lino   [lindex $field 1]
      set line   [join [lrange $field 2 end]]
      set cihash [dict get $cihashes $fhash]
      set revnum {}
      foreach hash $cihash {
         append revnum [dict get $revnums $hash] " "
      }
      set revnum [join $revnum ,]
      regsub -all "($greppat)" $line [coloured redbold \\1] line
      # for now, we just preprend the chronological revision numbers
      # and add a bit of colour

      lappend out [coloured magenta $revnum]:$fhash:$lino:$line
   }
   return $out
}

proc adjustWidth params {
   set widopt {}
   regexp -- {(timeline|finfo|search|descendants).*(-W)} $params widopt