1

There have been similar questions to this that I've been involved with before. One example: How can I get the svn revision number in PHP?

But today I'm tackling a project that is managed with BZR. I need to get the bazaar version for a particular file and publish that figure on our website in a way that it automatically updates when the file is update.

The website is all in Python so I'm open to reading files behind the scenes but I would prefer a more passive method if available.

Community
  • 1
  • 1
Oli
  • 235,628
  • 64
  • 220
  • 299

3 Answers3

3

If you need to get the latest revision in which a file was modified, you can doit using the following command:

bzr log -l1 --line <file> | cut -f1 -d:
jcollado
  • 39,419
  • 8
  • 102
  • 133
2

In Python:

from bzrlib.branch import Branch
b = Branch.open(location_of_your_branch)
b.lock_read()
try:
    # Retrieve the contents of the last revision
    t = b.basis_tree()
    revid = t.get_file_revision(t.path2id(your_filename))
    print ".".join([str(x) for x in b.revision_id_to_dotted_revno(revid)])
finally:
    b.unlock()
jelmer
  • 2,405
  • 14
  • 27
0

One way is to have a script that pushes to your website, this script case update version.py or something like that:

# update version
echo "VERSION = \"$(bzr revno)\"" > version.py
# push to website
rsync ...
# tag
bzr tag --force deployed-version
Miki Tebeka
  • 13,428
  • 4
  • 37
  • 49
  • The problem I'm finding with all the bzr commands is they only show the latest rev numbers. For example if there's a file I haven't touched since adding it at init, 100 revs later if I run `bzr revno file` it returns `101`. I want the last rev that file was altered, in this example: `1`. – Oli Nov 27 '11 at 05:20
  • bzr revno shows the last revision number of the entire tree, not of the individual file. – jelmer Nov 27 '11 at 14:44