plugin not working on lightweight checkouts

Sebastien Alaiwan sebastien.alaiwan at
Sun Nov 29 10:06:55 UTC 2015

On 2015-11-29 09:56, Matthew D. Fuller wrote:
> On Sun, Nov 29, 2015 at 09:53:33AM +0100 I heard the voice of
> Sebastien Alaiwan, and lo! it spake thus:
>> 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.
> Technically, you'd want to be directly using .bzr/checkout/dirstate,
> since you care about the WT rev, not the branch rev.
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.
Here's a modified version of Chris' plugin.
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.
I mean, the revno which gets printed is the one before the application of the "bzr update" command.

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.

Any ideas?
(Disclaimer: I need to achieve the same behaviour for fixing bzr-externals.)

"""Update the "revno" file when the branch changes.

This post_change_branch_tip hook puts the current revno in a file called
"revno" in the base directory of the current branch, if it exists. If "revno"
doesn't exist, then it is not created."""

from bzrlib import branch, mutabletree
version_info = (1, 0, 0, 'final', 0)

def write_revno_file(branch, revno, revid):
    import os.path
    from bzrlib import errors
*    print "write_revno_file: ", revno*
        trans = branch.bzrdir.root_transport
        path = trans.local_abspath('revno')
    except errors.NotLocalUrl:
        return # Nothing to do for a remote URL
    if os.path.isfile(path):
        f = open(path,'w')
        f.write('%s\n%s' % (revno, revid))

def update_revno_file_on_bzrcommit(params):
*    print "update_revno_file_on_bzrcommit"*
    write_revno_file(params.branch, params.new_revno, params.new_revid)


def update_revno_file_on_bzrupdate(tree, transform):*
**    print "update_revno_file_on_bzrupdate"*
    revid = tree.last_revision()
    revno_t = tree.branch.revision_id_to_dotted_revno(revid)
    revno = ".".join(str(n) for n in revno_t)
    write_revno_file(tree.branch, revno, revid)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the bazaar mailing list