revno and commit_date in app code

John A Meinel john at arbash-meinel.com
Tue Sep 27 20:18:21 BST 2005


george young wrote:
> [bzr-0.0.9, linux]
> I'm starting to use bzr for my main application (in python).
> One thing that I need, somehow, is for an installed instance of
> the app to know it's rev_no, and if possible, also it's commit date and
> committer.  I used to do this in CVS with the imbedded keyword values:
>
> cvs_rev = '$Revision: 1.1.1.1 $'[11:-2]
> cvs_date = '$Date: 2004/03/05 18:19:33 $'[7:-2]
> cvs_author = '$Author: geoyou $'[9:-2]
>
>
> My current bzr hack is this script(kludged from show_info.py), run by make:

In general, I think bzr is following the Arch model, that keywords are
risky, and the better way to do it is at build time. Which is what you
have done.

I would also offer that you can do:
bzr ignore ./rev_info.py

And you can have the rev_info.py file in your source tree, it just isn't
committed along with everything else. Doing the ignore means that it
won't keep reminding you that it doesn't know what to do with the file,
and it won't be accidentally added by a recursive "bzr add".
I believe you need to use the path separator, to prevent bzr from trying
to ignore the same file in other directories (unless that is what you want).

>
>    #!/usr/bin/env python2.4
>    import bzrlib.branch
>
>    branch = bzrlib.branch.Branch.open_containing(None)
>    rev_no = branch.revno()
>    rev = branch.get_revision(branch.revision_history()[-1])
>    rev_timestamp = rev.timestamp
>    print 'import datetime\n' \
>          'rev_no = %s\n' \
>          'rev_date = datetime.datetime.fromtimestamp(%d)' % (rev_no, rev_timestamp)
>
>
> Make install runs "bzr_get_rev_info.py >rev_info.py", and
> the app imports the resultant module.  Of course, rev_info.py can not
> be part of the bzr revision, because it can only be created after the commit.
>
> Is there some cleaner, more stable way to do this?  I could spend some time
> hacking bzr, if someone would suggest a useful path for me that's not too
> laborious.  Is anyone working on or thinking about cvs-like keywords, or
> commit trigger hooks?  Any comments, raves, criticisms are welcome.

Commit trigger hooks are being worked on. The simplest way for what you
want is to write a plugin, which overloads cmd_commit, calls the regular
command, and then does what you want afterwards.

An example would be:

import bzrlib, bzrlib.builtins, bzrlib.commands

class cmd_commit(bzrlib.builtins.cmd_commit):
  def run(self, *args, **kwargs):
    retval = super(cmd_commit, self).run(*args, **kwargs)
    if retval not in (0, None):
      return retval
    # the commit command succeeded, do whatever post processing
    # you want to do. here

John
=:->


>
>
> -- George
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050927/f2102e79/attachment.pgp 


More information about the bazaar mailing list