Fossil Wrapper

Check-in [c0a6e8052f]
Login

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

Overview
Comment:added some comments as a personal memo.
Timelines: family | ancestors | descendants | both | dresden
Files: files | file ages | folders
SHA1: c0a6e8052fd23f716588c3899f2c320d85df2ea5
User & Date: j 2013-07-27 19:56:54
Context
2013-07-27
22:06
postpone revision number computation until it is really needed. check-in: 614b48ebe9 user: j tags: dresden
19:56
added some comments as a personal memo. check-in: c0a6e8052f user: j tags: dresden
16:46
minor. check-in: abdb439351 user: j tags: dresden
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to fsl.

209
210
211
212
213
214
215
216









217







218

219





220
221
222
223
224
225
226



227
228
229
230
231
232
233
#   interceptors' below for usage.)
#
# - If an interceptor returns an empty list, the wrapper is expected
#   to exit without calling Fossil, thereby fully intercepting the
#   query. Otherwise, it acts as a pre-processor: the returned list is
#   treated as a revised parameter list and will be supplied to
#   `fossil'.










proc interceptor {command_spec body} {







    set fn [list {params} $body [uplevel 1 {namespace current}]]

    foreach command [triggers_for $command_spec] {





        dict set config::commands $command $fn
    }
}

proc intercept {params} {
    set command [first $params]
    if {[interceptor? $command]} {



        set params [apply [dict get $config::commands $command] $params]
    }
    return $params
}

# --( Command triggers )------------------------------------------------








|
>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>

>

>
>
>
>
>
|






>
>
>







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#   interceptors' below for usage.)
#
# - If an interceptor returns an empty list, the wrapper is expected
#   to exit without calling Fossil, thereby fully intercepting the
#   query. Otherwise, it acts as a pre-processor: the returned list is
#   treated as a revised parameter list and will be supplied to
#   `fossil'.
#
#   rephrased: 
#      interceptor modifies `params' (the current command line arguments
#      of the `fsl' call) and returns the modified list which is then
#      used in further processing and the final call to `fossil'. if
#      the interceptor returns nothing, `fsl' exits immediately.
#      in this case the only performed actions are those executed
#      by the interceptor itself.
#

proc interceptor {command_spec body} {
    # cf. `apply' documentation: the anonymous function for `apply'
    # has to be specified in the form {args body namespace} where
    # `args' spefifies the formal arguments of the function. in the
    # present case `args' is identical to `params'. in the current setup
    # the `namespace' argument is apparently redundant and could be
    # ommitted:

    set fn [list {params} $body [uplevel 1 {namespace current}]]
    
    foreach command [triggers_for $command_spec] {
       # this loop sets up the dictionary `config::commands' whose
       # keys are the known interceptor commands and whose values are
       # the corresponding anonymous function definitions. note that each
       # alternate name in `commands_spec (e.g., a, ali, alias etc.)
       # generates a further entry (with identical value).
       dict set config::commands $command $fn
    }
}

proc intercept {params} {
    set command [first $params]
    if {[interceptor? $command]} {
        # here, the interceptor definition is retrieved from the
        # `commands' dictionary and used as the anonymous function
        # argument for `apply' (and `params' as its concrete argument). 
        set params [apply [dict get $config::commands $command] $params]
    }
    return $params
}

# --( Command triggers )------------------------------------------------

385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401

   # map this interceptor command to `fossil (g)diff'. actually, we use `di'
   # instead of `diff' since only the former will trigger the `diff' filter:
   regsub {^(g?d)f} $params {\1i} params

   # extract the revison number information from `params'. contrary to
   # `fossil' it is acceptable to omit blanks between `-r' and `n:m':
   set rgxrevnum {[[:digit:]]+(:[[:digit:]]+)?}
   set rgx { -r} 
   set rgx { \-r[[:blank:]]*}

   set rgx $rgx$rgxrevnum

   # without `-r' argument we can return already:
   if {![regexp $rgx $params revarg]} {return $params}

   # translate rev. numbers to sha1 hashes and construct the 
   # required `diff' arguments:







<
<

>







410
411
412
413
414
415
416


417
418
419
420
421
422
423
424
425

   # map this interceptor command to `fossil (g)diff'. actually, we use `di'
   # instead of `diff' since only the former will trigger the `diff' filter:
   regsub {^(g?d)f} $params {\1i} params

   # extract the revison number information from `params'. contrary to
   # `fossil' it is acceptable to omit blanks between `-r' and `n:m':


   set rgx { \-r[[:blank:]]*}
   set rgxrevnum {[[:digit:]]+(:[[:digit:]]+)?}
   set rgx $rgx$rgxrevnum

   # without `-r' argument we can return already:
   if {![regexp $rgx $params revarg]} {return $params}

   # translate rev. numbers to sha1 hashes and construct the 
   # required `diff' arguments:
412
413
414
415
416
417
418


419
420
421
422
423
424
425
      incr cnt
   } 

   #replace `-r n:m' by the constructed `diff' arguments: 
   regsub $revarg $params $from$to 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.
# (maybe the \n should go away?). continuation lines belonging
# to the checkin message (including the trailing user/tags info)







>
>







436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
      incr cnt
   } 

   #replace `-r n:m' by the constructed `diff' arguments: 
   regsub $revarg $params $from$to params
   return $params
}

# --( further procs )---------------------------------------------------

proc unwrapTimeline records {
#-----------------------------------------------------------------------
# unwrap `fossil timeline' output, putting each checkin on a single
# line. expected input: currently, a list of \n terminated lines.
# (maybe the \n should go away?). continuation lines belonging
# to the checkin message (including the trailing user/tags info)