Fossil Wrapper

Check-in [1f0b2f3546]
Login

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

Overview
Comment:improved `df' interceptor.
Timelines: family | ancestors | descendants | both | dresden
Files: files | file ages | folders
SHA1: 1f0b2f35460cc7b141145f50b2c34c22d3d58b05
User & Date: j 2013-07-27 12:04:27
Context
2013-07-27
12:20
adjusted `fancy_timeline' which now highlights the relative revision numbers in magenta. check-in: 1d05884eb1 user: j tags: dresden
12:04
improved `df' interceptor. check-in: 1f0b2f3546 user: j tags: dresden
09:59
new interceptor `df' allowing relative svn/hg-style revison numbers during diffs. alpha state. check-in: 132ed5e030 user: j tags: dresden
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

353
354
355
356
357
358
359

360
361
362
363
364
365
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
393
394

395
396


397
398
399
400

401
402

403
404
405
406



407


408
409
410
411
412
413
414
415
    puts "Currently defined expansions:"
    dict for {alias expansion} $config::aliases {
        puts [format "%10s -> %s" $alias $expansion]
    }
}

interceptor df {

   # a first stab at getting relative revision numbers working with `diff'.
   # should be called as `fsl df -r n' or `fsl df -r n:m' where `n, m' are
   # counting from 0 (initial checkin). This call which is 
   # be mapped to 
   #
   # `fsl di -r sha1_n --to sha1_m'
   #
   # where `sha1_n, sha1_m' are the sha1 hashes of the respective checkins.
   #


   set hash2num [computeRevnums {}]
   set dim [dict size $hash2num]

   #revert the above dictonary in order to get the mapping from numbers to sha1.
   #at the same time, strip the square brackets around the hash value.
   dict for {key val} $hash2num {
      regexp {[[:alnum:]]+} $key sha1
      dict set num2hash [expr {$dim - $val}] $sha1
   }

   set parstring [concat $params]




   # first introduce a blank between `-r' and revnum in case it was forgotten...



   set rgxrevnum {[[:digit:]]+(:[[:digit:]]+)?}
   regsub "\\-r($rgxrevnum)" $parstring {-r \1} parstring










   #extract the full match of the `df' command as well as the revnums
   set rgx {df[ ]+\-r[ ]+([[:digit:]]+(:[[:digit:]]+)?)}
   regexp $rgx $parstring fullmatch numbers











   set revs [split $numbers :]
   set fromto [list from to]



   set to {}
   set cnt 0
   
   #translate to sha1 hashes and prepend with correct `diff' options

   foreach rev $revs {
      set which [lindex $fromto $cnt] 


      set $which " --$which [dict get $num2hash $rev]"
      incr cnt
   } 
   #we use `di' instead of `diff' since only the former triggers the `diff' filter

   set replace "di $from$to"
   regsub $fullmatch $parstring $replace parstring


   #create the modified `params' list
   regsub -all {[[:blank:]]+} $parstring " " parstring
   set params [split $parstring]






   puts "executing 'fossil $params'"
   return $params
}

proc unwrapTimeline records {
#-----------------------------------------------------------------------
# unwrap `fossil timeline' output, putting each checkin on a single
# line. expected input: currently, a list of \n terminated lines.







>





|


|
<
>



|
|





|
>
>
>

<
>
>
>

<
>
>
>
>
>
>
>
>
>
|
<
<
<
>
>
>
>
>
>
>
>
>
>
>

<
>
>
>


<
<
>


>
>



<
>
|
|
>

<
|
|
>
>
>
|
>
>
|







353
354
355
356
357
358
359
360
361
362
363
364
365
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
393
394
395
396
397
398
399



400
401
402
403
404
405
406
407
408
409
410
411

412
413
414
415
416


417
418
419
420
421
422
423
424

425
426
427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
    puts "Currently defined expansions:"
    dict for {alias expansion} $config::aliases {
        puts [format "%10s -> %s" $alias $expansion]
    }
}

interceptor df {
   # ----------------------------------------------------------------------
   # a first stab at getting relative revision numbers working with `diff'.
   # should be called as `fsl df -r n' or `fsl df -r n:m' where `n, m' are
   # counting from 0 (initial checkin). This call which is 
   # be mapped to 
   #
   # fsl di -r sha1_n --to sha1_m
   #
   # where `sha1_n, sha1_m' are the sha1 hashes of the respective checkins.
   # further arguments to `diff' are passed through unmodified (hopefully).

   # ----------------------------------------------------------------------
   set hash2num [computeRevnums {}]
   set dim [dict size $hash2num]

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

   # modification of the `params' list is performed in place and step by
   # step. we use `di' instead of `diff' since only the former triggers the
   # `diff' filter:
   set params [lreplace $params  0 0 di]


   # extract the revison number information from `params'. the case where the
   # blank between `-r' and `n:m' is ommitted is handled, too:
   set cnt 0
   set rgxrevnum {[[:digit:]]+(:[[:digit:]]+)?}

   foreach word $params {
      set rgx {^\-r} 
      if {[regexp $rgx $word]} {
         set flagpos $cnt
         set rgx $rgx$rgxrevnum
         if {[regexp $rgx $word]} {
            set noblank 1 
         } else {set noblank 0}
         break
      }



      incr cnt
   }
   if {$noblank} {
      set dum [lindex $params $flagpos]
      set numbers [string trimleft $dum -r]
   } else {
      set idx [expr $flagpos + 1]
      set numbers [lindex $params $idx] 
      # remove the `numbers' field from `params':
      set params [lreplace $params $idx $idx]
   }
   set revs [split $numbers :]


   # translate rev. numbers to sha1 hashes and construct the 
   # required `diff' arguments:
   set to {}
   set cnt 0


   set fromto [list from to]
   foreach rev $revs {
      set which [lindex $fromto $cnt] 
      # this evals in turn to define variables `from' and `to', respectively,
      # which contain the respective `diff' arguments.
      set $which " --$which [dict get $num2hash $rev]"
      incr cnt
   } 


   # insert the canonical `diff' arguments/options into the `params' list
   # after `-r' (whose position is given by `flagpos') and finally remove the
   # `-r'.


   set cnt 1
   foreach word $from$to {
      set idx [expr $flagpos + $cnt]
      set params [linsert $params $idx $word]
      incr cnt
   }
   set params [lreplace $params $flagpos $flagpos]

   puts "executing `fossil $params'"
   return $params
}

proc unwrapTimeline records {
#-----------------------------------------------------------------------
# unwrap `fossil timeline' output, putting each checkin on a single
# line. expected input: currently, a list of \n terminated lines.