<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 2015-11-29 09:56, Matthew D. Fuller
      wrote:<br>
    </div>
    <blockquote cite="mid:20151129085602.GY30248@over-yonder.net"
      type="cite">
      <pre wrap="">On Sun, Nov 29, 2015 at 09:53:33AM +0100 I heard the voice of
Sebastien Alaiwan, and lo! it spake thus:
</pre>
      <blockquote type="cite">
        <pre wrap="">
Is this the expected behaviour? Not updating the "revno" file on
"bzr update -r XXX" commands seems error-prone, as you might want to
build older revisions of your project.

I was about to suggest to directly use, from your build system, the
".bzr/branch/last-revision" file.  However, this will couple your
build system to bazaar ; which you probably want to avoid.
</pre>
      </blockquote>
      <pre wrap="">
Technically, you'd want to be directly using .bzr/checkout/dirstate,
since you care about the WT rev, not the branch rev.

</pre>
    </blockquote>
    Thanks for your suggestion. Then, I'd better go for the plugin
    approach than trying to parse 'dirstate' with a one-liner in a build
    system.<br>
    Here's a modified version of Chris' plugin.<br>
    I managed to catch the event "bzr update -r some_old_revision",
    however, it seems I catch it too early: at this point, the revno is
    still the "old" revision number of the tree.<br>
    I mean, the revno which gets printed is the one before the
    application of the "bzr update" command.<br>
    <br>
    I searched through the documentation, but I can't find an event
    related to the MutableTree occuring "at the end" of a "bzr update"
    command.<br>
    <br>
    Any ideas?<br>
    (Disclaimer: I need to achieve the same behaviour for fixing
    bzr-externals.)<br>
    <br>
    <tt>"""Update the "revno" file when the branch changes.</tt><tt><br>
    </tt><tt><br>
    </tt><tt>This post_change_branch_tip hook puts the current revno in
      a file called</tt><tt><br>
    </tt><tt>"revno" in the base directory of the current branch, if it
      exists. If "revno"</tt><tt><br>
    </tt><tt>doesn't exist, then it is not created."""</tt><tt><br>
    </tt><tt><br>
    </tt><tt>from bzrlib import branch, mutabletree</tt><tt><br>
    </tt><tt>version_info = (1, 0, 0, 'final', 0)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>def write_revno_file(branch, revno, revid):</tt><tt><br>
    </tt><tt>    import os.path</tt><tt><br>
    </tt><tt>    from bzrlib import errors</tt><tt><br>
    </tt><b><tt>    print "write_revno_file: ", revno</tt></b><tt><br>
    </tt><tt>    try:</tt><tt><br>
    </tt><tt>        trans = branch.bzrdir.root_transport</tt><tt><br>
    </tt><tt>        path = trans.local_abspath('revno')</tt><tt><br>
    </tt><tt>    except errors.NotLocalUrl:</tt><tt><br>
    </tt><tt>        return # Nothing to do for a remote URL</tt><tt><br>
    </tt><tt>    if os.path.isfile(path):</tt><tt><br>
    </tt><tt>        f = open(path,'w')</tt><tt><br>
    </tt><tt>        f.write('%s\n%s' % (revno, revid))</tt><tt><br>
    </tt><tt>        f.close()</tt><tt><br>
    </tt><tt><br>
    </tt><tt>def update_revno_file_on_bzrcommit(params):</tt><tt><br>
    </tt><b><tt>    print "update_revno_file_on_bzrcommit"</tt></b><tt><br>
    </tt><tt>    write_revno_file(params.branch, params.new_revno,
      params.new_revid)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>branch.Branch.hooks.install_named_hook('post_change_branch_tip',</tt><tt><br>
    </tt><tt>        update_revno_file_on_bzrcommit,</tt><tt><br>
    </tt><tt>        'N/A')</tt><tt><br>
    </tt><br>
    <tt>def update_revno_file_on_bzrupdate(tree, transform):</tt><b><tt><br>
      </tt></b><b><tt>    print "update_revno_file_on_bzrupdate"</tt></b><tt><br>
    </tt><tt>    revid = tree.last_revision()</tt><tt><br>
    </tt><tt>    revno_t =
      tree.branch.revision_id_to_dotted_revno(revid)</tt><tt><br>
    </tt><tt>    revno = ".".join(str(n) for n in revno_t)</tt><tt><br>
    </tt><tt>    write_revno_file(tree.branch, revno, revid)</tt><tt><br>
    </tt><tt><br>
    </tt><tt>mutabletree.MutableTree.hooks.install_named_hook('post_transform',</tt><tt><br>
    </tt><tt>        update_revno_file_on_bzrupdate,</tt><tt><br>
    </tt><tt>        'N/A')</tt><tt><br>
    </tt><tt><br>
    </tt><br>
  </body>
</html>