Exemple #1
0
def _get_version_from_bzr_lib(path):
    import bzrlib.tag, bzrlib.branch
    fullpath = os.path.abspath(path)
    if sys.platform == 'win32':
        fullpath = fullpath.replace('\\', '/')
        fullpath = '/' + fullpath
    branch = bzrlib.branch.Branch.open('file://' + fullpath)
    tags = bzrlib.tag.BasicTags(branch)
    #print "Getting version information from bzr branch..."
    branch.lock_read()
    try:
        history = branch.iter_merge_sorted_revisions(direction="reverse")
        version = None
        extra_version = []
        for revid, depth, revno, end_of_merge in history:
            for tag_name, tag_revid in tags.get_tag_dict().iteritems():
                #print tag_revid, "<==>", revid
                if tag_revid == revid:
                    #print "%s matches tag %s" % (revid, tag_name)
                    version = [int(s) for s in tag_name.split('.')]
                    ## if the current revision does not match the last
                    ## tag, we append current revno to the version
                    if tag_revid != branch.last_revision():
                        extra_version = [branch.revno()]
                    break
            if version:
                break
    finally:
        branch.unlock()
    assert version is not None
    _version = version + extra_version
    return _version
Exemple #2
0
def export_branch(repo, name):
    ref = '%s/heads/%s' % (prefix, name)
    tip = marks.get_tip(name)

    branch = get_remote_branch(name)
    repo = branch.repository

    branch.lock_read()
    revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
    try:
        tip_revno = branch.revision_id_to_revno(tip)
        last_revno, _ = branch.last_revision_info()
        total = last_revno - tip_revno
    except bzrlib.errors.NoSuchRevision:
        tip_revno = 0
        total = 0

    for revid, _, seq, _ in revs:

        if marks.is_marked(revid):
            continue

        rev = repo.get_revision(revid)
        revno = seq[0]

        parents = rev.parent_ids
        time = rev.timestamp
        tz = rev.timezone
        committer = rev.committer.encode('utf-8')
        committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
        authors = rev.get_apparent_authors()
        if authors:
            author = authors[0].encode('utf-8')
            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
        else:
            author = committer
        msg = rev.message.encode('utf-8')

        msg += '\n'

        if len(parents) == 0:
            parent = bzrlib.revision.NULL_REVISION
        else:
            parent = parents[0]

        cur_tree = repo.revision_tree(revid)
        prev = repo.revision_tree(parent)
        modified, removed = get_filechanges(cur_tree, prev)

        modified_final = export_files(cur_tree, modified)

        if len(parents) == 0:
            print 'reset %s' % ref

        print "commit %s" % ref
        print "mark :%d" % (marks.get_mark(revid))
        print "author %s" % (author)
        print "committer %s" % (committer)
        print "data %d" % (len(msg))
        print msg

        for i, p in enumerate(parents):
            try:
                m = rev_to_mark(p)
            except KeyError:
                # ghost?
                continue
            if i == 0:
                print "from :%s" % m
            else:
                print "merge :%s" % m

        for f in removed:
            print "D %s" % (f, )
        for f in modified_final:
            print "M %s :%u %s" % f
        print

        if len(seq) > 1:
            # let's skip branch revisions from the progress report
            continue

        progress = (revno - tip_revno)
        if (progress % 100 == 0):
            if total:
                print "progress revision %d '%s' (%d/%d)" % (revno, name,
                                                             progress, total)
            else:
                print "progress revision %d '%s' (%d)" % (revno, name,
                                                          progress)

    branch.unlock()

    revid = branch.last_revision()

    # make sure the ref is updated
    print "reset %s" % ref
    print "from :%u" % rev_to_mark(revid)
    print

    marks.set_tip(name, revid)
Exemple #3
0
def export_branch(repo, name):
    ref = '%s/heads/%s' % (prefix, name)
    tip = marks.get_tip(name)

    branch = get_remote_branch(name)
    repo = branch.repository

    branch.lock_read()
    revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
    try:
        tip_revno = branch.revision_id_to_revno(tip)
        last_revno, _ = branch.last_revision_info()
        total = last_revno - tip_revno
    except bzrlib.errors.NoSuchRevision:
        tip_revno = 0
        total = 0

    for revid, _, seq, _ in revs:

        if marks.is_marked(revid):
            continue

        rev = repo.get_revision(revid)
        revno = seq[0]

        parents = rev.parent_ids
        time = rev.timestamp
        tz = rev.timezone
        committer = rev.committer.encode('utf-8')
        committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
        authors = rev.get_apparent_authors()
        if authors:
            author = authors[0].encode('utf-8')
            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
        else:
            author = committer
        msg = rev.message.encode('utf-8')

        msg += '\n'

        if len(parents) == 0:
            parent = bzrlib.revision.NULL_REVISION
        else:
            parent = parents[0]

        cur_tree = repo.revision_tree(revid)
        prev = repo.revision_tree(parent)
        modified, removed = get_filechanges(cur_tree, prev)

        modified_final = export_files(cur_tree, modified)

        if len(parents) == 0:
            print 'reset %s' % ref

        print "commit %s" % ref
        print "mark :%d" % (marks.get_mark(revid))
        print "author %s" % (author)
        print "committer %s" % (committer)
        print "data %d" % (len(msg))
        print msg

        for i, p in enumerate(parents):
            try:
                m = rev_to_mark(p)
            except KeyError:
                # ghost?
                continue
            if i == 0:
                print "from :%s" % m
            else:
                print "merge :%s" % m

        for f in removed:
            print "D %s" % (f,)
        for f in modified_final:
            print "M %s :%u %s" % f
        print

        if len(seq) > 1:
            # let's skip branch revisions from the progress report
            continue

        progress = (revno - tip_revno)
        if (progress % 100 == 0):
            if total:
                print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
            else:
                print "progress revision %d '%s' (%d)" % (revno, name, progress)

    branch.unlock()

    revid = branch.last_revision()

    # make sure the ref is updated
    print "reset %s" % ref
    print "from :%u" % rev_to_mark(revid)
    print

    marks.set_tip(name, revid)
Exemple #4
0
def export_branch(repo, name):
    ref = '%s/heads/%s' % (prefix, name)
    tip = marks.get_tip(name)

    branch = get_remote_branch(name)
    repo = branch.repository

    branch.lock_read()
    revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
    try:
        tip_revno = branch.revision_id_to_revno(tip)
        last_revno, _ = branch.last_revision_info()
        total = last_revno - tip_revno
    except bzrlib.errors.NoSuchRevision:
        tip_revno = 0
        total = 0

    for revid, _, seq, _ in revs:

        if marks.is_marked(revid):
            continue

        rev = repo.get_revision(revid)
        revno = seq[0]

        parents = rev.parent_ids
        time = rev.timestamp
        tz = rev.timezone
        committer = rev.committer.encode('utf-8')
        committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
        authors = rev.get_apparent_authors()
        if authors:
            author = authors[0].encode('utf-8')
            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
        else:
            author = committer
        msg = rev.message.encode('utf-8')

        msg += '\n'

        if rev.properties.has_key('file-info'):
            from bzrlib import bencode
            try:
                files = bencode.bdecode(
                    rev.properties['file-info'].encode('utf-8'))
            except Exception, e:
                # protect against repository corruption
                # (happens in the wild, see MySQL tree)
                files = ()

            rmsg = msg.rstrip('\r\n ')
            file_comments = []
            for file in files:
                fmsg = file['message'].rstrip('\r\n ')
                # Skip empty file comments and file comments identical to the
                # commit comment (they originate from tools and policies that
                # require writing per-file comments and users simply copy-paste
                # revision comment over, these comments add no value as a part of
                # the commit comment).
                if fmsg == '' or fmsg == rmsg:
                    continue

                file_comments.append(file['path'] + ':')
                for l in fmsg.split('\n'):
                    file_comments.append('  ' + l)

            msg += '\n' + '\n'.join(file_comments) + '\n'

        if len(parents) == 0:
            parent = bzrlib.revision.NULL_REVISION
        else:
            parent = parents[0]

        cur_tree = repo.revision_tree(revid)
        prev = repo.revision_tree(parent)
        modified, removed = get_filechanges(cur_tree, prev)

        modified_final = export_files(cur_tree, modified)

        if len(parents) == 0:
            print 'reset %s' % ref

        print "commit %s" % ref
        print "mark :%d" % (marks.get_mark(revid))
        print "author %s" % (author)
        print "committer %s" % (committer)
        print "data %d" % (len(msg))
        print msg

        for i, p in enumerate(parents):
            try:
                m = rev_to_mark(p)
            except KeyError:
                # ghost?
                continue
            if i == 0:
                print "from :%s" % m
            else:
                print "merge :%s" % m

        for f in removed:
            print "D %s" % (f, )
        for f in modified_final:
            print "M %s :%u %s" % f
        print

        if len(seq) > 1:
            # let's skip branch revisions from the progress report
            continue

        progress = (revno - tip_revno)
        if (progress % 100 == 0):
            if total:
                print "progress revision %d '%s' (%d/%d)" % (revno, name,
                                                             progress, total)
            else:
                print "progress revision %d '%s' (%d)" % (revno, name,
                                                          progress)
Exemple #5
0
def export_branch(repo, name):
    ref = '%s/heads/%s' % (prefix, name)
    tip = marks.get_tip(name)

    branch = get_remote_branch(name)
    repo = branch.repository

    branch.lock_read()
    revs = branch.iter_merge_sorted_revisions(None, tip, 'exclude', 'forward')
    try:
        tip_revno = branch.revision_id_to_revno(tip)
        last_revno, _ = branch.last_revision_info()
        total = last_revno - tip_revno
    except bzrlib.errors.NoSuchRevision:
        tip_revno = 0
        total = 0

    for revid, _, seq, _ in revs:

        if marks.is_marked(revid):
            continue

        rev = repo.get_revision(revid)
        revno = seq[0]

        parents = rev.parent_ids
        time = rev.timestamp
        tz = rev.timezone
        committer = rev.committer.encode('utf-8')
        committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz))
        authors = rev.get_apparent_authors()
        if authors:
            author = authors[0].encode('utf-8')
            author = "%s %u %s" % (fixup_user(author), time, gittz(tz))
        else:
            author = committer
        msg = rev.message.encode('utf-8')

        msg += '\n'

        if rev.properties.has_key('file-info'):
            from bzrlib import bencode
            try:
                files = bencode.bdecode(rev.properties['file-info'].encode('utf-8'))
            except Exception, e:
                # protect against repository corruption
                # (happens in the wild, see MySQL tree)
                files = ()

            rmsg = msg.rstrip('\r\n ')
            file_comments = []
            for file in files:
              fmsg = file['message'].rstrip('\r\n ')
              # Skip empty file comments and file comments identical to the
              # commit comment (they originate from tools and policies that
              # require writing per-file comments and users simply copy-paste
              # revision comment over, these comments add no value as a part of
              # the commit comment).
              if fmsg == '' or fmsg == rmsg:
                  continue

              file_comments.append(file['path'] + ':')
              for l in fmsg.split('\n'):
                  file_comments.append('  ' + l)

            msg += '\n' + '\n'.join(file_comments) + '\n'

        if len(parents) == 0:
            parent = bzrlib.revision.NULL_REVISION
        else:
            parent = parents[0]

        cur_tree = repo.revision_tree(revid)
        prev = repo.revision_tree(parent)
        modified, removed = get_filechanges(cur_tree, prev)

        modified_final = export_files(cur_tree, modified)

        if len(parents) == 0:
            print 'reset %s' % ref

        print "commit %s" % ref
        print "mark :%d" % (marks.get_mark(revid))
        print "author %s" % (author)
        print "committer %s" % (committer)
        print "data %d" % (len(msg))
        print msg

        for i, p in enumerate(parents):
            try:
                m = rev_to_mark(p)
            except KeyError:
                # ghost?
                continue
            if i == 0:
                print "from :%s" % m
            else:
                print "merge :%s" % m

        for f in removed:
            print "D %s" % (f,)
        for f in modified_final:
            print "M %s :%u %s" % f
        print

        if len(seq) > 1:
            # let's skip branch revisions from the progress report
            continue

        progress = (revno - tip_revno)
        if (progress % 100 == 0):
            if total:
                print "progress revision %d '%s' (%d/%d)" % (revno, name, progress, total)
            else:
                print "progress revision %d '%s' (%d)" % (revno, name, progress)