Edit detail for BzrIn revision 4 of 4

1 2 3 4
Editor: terry_n_brown
Time: 2010/08/04 13:28:19 GMT-7

-  is very simplistic, but it should usually work.**
  is very simplistic, but it should usually work.


This is a new (2008-9-8) version of the script which looks at all revisions in both branches, not just the last. It's not thoroughly tested and its parsing of the log file is very simplistic, but it should usually work.

So I have 10 leo branches in my leo branch directory, and I want to know which ones I can delete. I.e. which of my development branches are already included in the trunk. Below is a throwaway script that can be invoked like this:

python bzrin.py menuat-test trunk

and it will grab the revision ID (not the revision number) of the latest commit in menuat-test and check that that revision ID exists in trunk:

"""Check that the latest commit in bzr branch A exists in bzr branch B

# bzrin2
# Author: Terry Brown
# Created: Mon Sep  8 12:18:21 CDT 2008

import subprocess, sys, os
import tempfile  # ? because subprocess.PIPE hangs in .wait() ?

def emit(s):

def main():
    branch = tuple(sys.argv[1:3])
    emit("Checking for commits of revs in '%s' in '%s'\n" % branch)

    # show status
    for i in branch:
        emit("Status of '%s':\n" % i)
        cmd = subprocess.Popen(('bzr status '+i).split())

    revs = []

    for i in branch:
        emit("Counting revs in %s\n" % i)
        tmpFile, tmpName = tempfile.mkstemp()
        cmd = subprocess.Popen(('bzr log --show-ids '+i).split(),
            stdout = tmpFile)
        source = file(tmpName)
        for line in source:
            content = line.strip()
            if content.startswith('revision-id:'):
                id_ = content.split(None,1)[1]
                while not line.strip() == 'message:':
                    line = source.next()
                line = source.next()
                msg = []
                while not line.strip().startswith('-'*10):
                        line = source.next()
                    except StopIteration:  # end of file
                revs[-1].add((id_, tuple(msg)))
        emit("%d revs in %s\n" % (len(revs[-1]), i))

    diff = revs[0].difference(revs[1])

    if not diff:
        emit ("All revs in %s exist in %s : OK\n" % branch)
        emit ("WARNING: %s contains revs NOT in %s\n" % branch)
        for i in diff:
            emit("%s\n%s\n" % (i[0], ''.join(['  '+m for m in i[1]])))
        emit ("WARNING: %s contains revs NOT in %s\n" % branch)

if __name__ == '__main__':