Fossil Wrapper

Artifact [278e103a57]
Login

Artifact 278e103a57a3be1b434e2997e6d61e5c4c9be384:

Wiki page [Cookbook] by marc 2019-12-12 19:06:05.
D 2019-12-12T19:06:05.570
L Cookbook
P 9b3887ad65842bd467dbdc58121367446cf8e61d
U marc
W 8112
<h1><code>fsl</code> Cookbook</h1>

This is a gathering point for <code>.fslrc</code> snippets that do potentially useful things.  It can be surfed for snippets to take out and use directly or just as inspiration for other functionality.

<h2>Initial workflow fix</h2>

One of the annoyances of Fossil is that the usual workflow can be a bit tedious and repetitive.  The following interceptor adds a "cr:eate" command that solves this.  Its command line is as follows:

  <code>fsl cr(eate) <nowiki>[password]</nowiki></code>

The interceptor does the following:

  #  Creates a new fossil repository in <code>~/Repositories</code> named by the
     current working directory (assumed to be where the project will live).  It
     gets its default settings from <code>~/Repositories/skeleton.fossil</code>.
  #  Opens the newly-created repository.
  #  If the optional password is given, sets the password on the Fossil user
     matching the logged-in user.
  #  Opens a new branch named "development".
  #  Switches to that new branch.

<code><verbatim>interceptor cr:create {
    global tcl_platform

    set repodir [file join [file normalize ~] Repositories]
    set reponame [file join $repodir [file tail [pwd].fossil]]
    set skeleton [file join $repodir skeleton.fossil]

    set user $tcl_platform(user)
    set password [lindex $params 1]

    fossil new $reponame --template $skeleton
    fossil open $reponame

    if {$password != ""} {
        fossil user password $user $password
    }

    fossil branch new development trunk
    fossil update development

    return {}
}</verbatim></code>

<hr><div id="a39e5758b078906a"><i>On 2012-12-29 13:53:21 UTC michael added:</i><br />
<h2>Making things garish</h2>

You can do a lot of stuff with filters.  Say, for example, that you want a busier <code>timeline</code> or <code>leaves</code> display.  The following filter will give it to you:

<code><verbatim>filter fancy_timeline {leaves timeline} {
    if {[regexp "^=== .* ===" $line]} {
        return [coloured green $line]
    }
    # Expressions to match:
    set artifact_rx  {\[([a-f\d]{4})([^\]]*)\]}
    set date_rx      {^\d\d:\d\d:\d\d}
    set current_rx   {\*CURRENT\*}
    set branch_rx    {\*(MERGE|BRANCH)\*}
    # Colour the output (repeated substitutions on $line):
    set line [regsub -all $artifact_rx $line\
        [format {[%s%s]}\
            [coloured yellow [display bright {\1}]]\
            [coloured yellow {\2}]]]
    set line [regsub $date_rx    $line [coloured blue &]]
    set line [regsub $current_rx $line [display reversed &]]
    set line [regsub $branch_rx  $line [display bright &]]
    # Values for user and tags may wrap, so left uncoloured:
    regsub -all {(user:|tags:)\s+} $line [coloured yellow &]
}</verbatim></code>

Be sure to also disable <code>log_entry</code> otherwise both filters
will be triggered. To do so either comment out <code>log_entry</code> or
clear its command list,

<verbatim>
filter log_entry {} {
    ...
}
</verbatim>

This is what it looks like:

<a href="http://imgur.com/2WgOO"><img src="http://i.imgur.com/2WgOO.png?1" alt="" title="Hosted by imgur.com" /></a>
</div id="a39e5758b078906a">

<hr><div id="160de22eaba8727e"><i>On 2012-12-30 14:16:50 UTC michael added:</i><br />
<h2>Cloning workflow fix</h2>

This interceptor is the other half of the pair begun with the "Initial workflow fix" interceptor.  Its command line is:

  <code>fsl dup(licate) url <nowiki>[password]</nowiki></code>

The interceptor works as follows:

  #  Clones the repository at the provided URL into <code>~/Repositories</code>
     named by the current working directory.
  #  Opens the newly-cloned repository into the current working directory.
  #  Adds the current logged-in user to the user list.
  #  If the optional password is given, the user's password is changed to that.

<code><verbatim>interceptor dup:duplicate {
    global tcl_platform

    set repodir  [file join [file normalize ~] Repositories]
    set reponame [file join $repodir [file tail [pwd].fossil]]

    set user     $tcl_platform(user)
    set url      [lindex $params 1]
    set password [lindex $params 2]

    fossil clone $url $reponame
    fossil open $reponame

    if {$password != ""} {
        fossil user password $user $password
    }

    return {}
}</verbatim></code></div id="160de22eaba8727e">

<hr><div id="85088e0d75e458b8"><i>On 2013-01-17 09:29:19 UTC michael added:</i><br />
<h2>Purging <tt>MISSING</tt> files</h2>

This combination of an alias, a filter and an interceptor will purge all <tt>MISSING</tt> files from your repository.  Useful for those cases where you forget to <kbd>fossil rm</kbd> before using the real <kbd>rm</kbd>.

<code><verbatim># fsl purge
# Purge all files flagged as "MISSING".
alias capture_changes changes

filter captured_changes {capture_changes} {
    variable captured
    lappend captured $line
    return {}
}

interceptor purge {
    variable captured {}
    fossil capture_changes
    foreach line $captured {
        if [string match MISSING* $line] {
            regsub ^MISSING $line {} file
            fossil rm [string trim $file]
        }
    }
    return {}
}</verbatim></code></div id="85088e0d75e458b8">

<hr><div id="3dd418e8d91c8951"><i>On 2013-07-03 21:33:51 UTC marc added:</i><br />
<h2>Colouring the current branch</h2>

A simple filter for colouring the current branch:

<code><verbatim>
filter branch {br:branch} {
    switch -regexp $line {
        {^\*}   { coloured yellow $line }
        default {             set  line }
    }
}
</verbatim></code>

Output,

<a href="http://imgur.com/QKuRtqy"><img src="http://i.imgur.com/QKuRtqy.png?1" title="Hosted by imgur.com" /></a></div id="3dd418e8d91c8951">

<hr><div id="17598ce12c6e10e5"><i>On 2014-05-07 10:35:18 UTC fifr added:</i><br />
<h2>Interactive commit: record</h2>
During development it is sometimes convenient to be able to commit only some of the changes in the current working directory. Fossil allows to select some files to be included in the next commit, but it is not possible to select only few changes in one file. Note that it is arguable whether such partial commits are a good thing or not because they encourage the creation of checkins with untested code.

This modification adds a <code>record</code> command, which mimics Mercurial's [http://mercurial.selenic.com/wiki/RecordExtension|record extension]. It allows to interactively select hunks to be included in the next commit.

  <code>fsl record some/files/*</code>

The latest version of a fslrc file with this code is in the [/timeline?r=record|record branch] and can be found [/doc/record/fslrc|here] (just drop the code into your .fslrc file).

<a href="http://imgur.com/mjpXDCQ"><img src="http://i.imgur.com/mjpXDCQ.png?1" title="Hosted by imgur.com" /></a>
</div id="17598ce12c6e10e5">

<hr><div id="80a99c86c25c7500"><i>On 2016-04-24 16:18:19 UTC marc added:</i><br />
<h2>Controlling autosync</h2>
Useful aliases for controlling <code>autosync</code> behaviour:

<code><verbatim>
alias live  {set autosync on}
alias local {set autosync off}
</verbatim></code>

then,

<code><verbatim>
$ fsl local
# ...work offline for a while...
$ fsl live
</verbatim></code>
</div id="80a99c86c25c7500">

<hr /><div id="7ad517bc28152cf6"><i>On 2019-12-12 19:06:05 UTC marc added:</i><br />
<h2>Quick snapshots</h2>

To quickly snapshot the working tree (without reverting anything),

<code><verbatim>
interceptor snap {
  set now [clock format [clock seconds]]
  fossil stash snapshot -m "fsl snap @ $now"
  return {}  
}
</verbatim></code>

then,

<code><verbatim>
$ fsl snap
$ fsl stash ls
    1: [06a31756cc58f2] on 2019-12-12 19:05:22
       fsl snap @ Thu Dec 12 11:05:22 PST 2019
</verbatim></code>

(inspired by Stephan Beal's <tt>fsnap</tt> <a href="https://fossil-scm.org/forum/forumpost/d1a3fc7897">alias</a>).</div id="7ad517bc28152cf6">
Z 2f7103ba546f1f780218438dd6eb858f