コード例 #1
0
ファイル: bzr_buildbot.py プロジェクト: AndreaCrotti/buildbot
def generate_change(branch,
                    old_revno=None, old_revid=None,
                    new_revno=None, new_revid=None,
                    blame_merge_author=False):
    """Return a dict of information about a change to the branch.

    Dict has keys of "files", "who", "comments", and "revision", as used by
    the buildbot Change (and the PBChangeSource).

    If only the branch is given, the most recent change is returned.

    If only the new_revno is given, the comparison is expected to be between
    it and the previous revno (new_revno -1) in the branch.

    Passing old_revid and new_revid is only an optimization, included because
    bzr hooks usually provide this information.

    blame_merge_author means that the author of the merged branch is
    identified as the "who", not the person who committed the branch itself.
    This is typically used for PQM.
    """
    change = {} # files, who, comments, revision; NOT branch (= branch.nick)
    if new_revno is None:
        new_revno = branch.revno()
    if new_revid is None:
        new_revid = branch.get_rev_id(new_revno)
    # TODO: This falls over if this is the very first revision
    if old_revno is None:
        old_revno = new_revno -1
    if old_revid is None:
        old_revid = branch.get_rev_id(old_revno)
    repository = branch.repository
    new_rev = repository.get_revision(new_revid)
    if blame_merge_author:
        # this is a pqm commit or something like it
        change['who'] = repository.get_revision(
            new_rev.parent_ids[-1]).get_apparent_authors()[0]
    else:
        change['who'] = new_rev.get_apparent_authors()[0]
    # maybe useful to know:
    # name, email = bzrtools.config.parse_username(change['who'])
    change['comments'] = new_rev.message
    change['revision'] = new_revno
    files = change['files'] = []
    changes = repository.revision_tree(new_revid).changes_from(
        repository.revision_tree(old_revid))
    for (collection, name) in ((changes.added, 'ADDED'),
                               (changes.removed, 'REMOVED'),
                               (changes.modified, 'MODIFIED')):
        for info in collection:
            path = info[0]
            kind = info[2]
            files.append(' '.join([path, kind, name]))
    for info in changes.renamed:
        oldpath, newpath, id, kind, text_modified, meta_modified = info
        elements = [oldpath, kind,'RENAMED', newpath]
        if text_modified or meta_modified:
            elements.append('MODIFIED')
        files.append(' '.join(elements))
    return change
コード例 #2
0
def generate_change(branch,
                    old_revno=None, old_revid=None,
                    new_revno=None, new_revid=None,
                    blame_merge_author=False):
    """Return a dict of information about a change to the branch.

    Dict has keys of "files", "who", "comments", and "revision", as used by
    the buildbot Change (and the PBChangeSource).

    If only the branch is given, the most recent change is returned.

    If only the new_revno is given, the comparison is expected to be between
    it and the previous revno (new_revno -1) in the branch.

    Passing old_revid and new_revid is only an optimization, included because
    bzr hooks usually provide this information.

    blame_merge_author means that the author of the merged branch is
    identified as the "who", not the person who committed the branch itself.
    This is typically used for PQM.
    """
    change = {} # files, who, comments, revision; NOT branch (= branch.nick)
    if new_revno is None:
        new_revno = branch.revno()
    if new_revid is None:
        new_revid = branch.get_rev_id(new_revno)
    # TODO: This falls over if this is the very first revision
    if old_revno is None:
        old_revno = new_revno -1
    if old_revid is None:
        old_revid = branch.get_rev_id(old_revno)
    repository = branch.repository
    new_rev = repository.get_revision(new_revid)
    if blame_merge_author:
        # this is a pqm commit or something like it
        change['author'] = repository.get_revision(
            new_rev.parent_ids[-1]).get_apparent_authors()[0]
    else:
        change['author'] = new_rev.get_apparent_authors()[0]
    # maybe useful to know:
    # name, email = bzrtools.config.parse_username(change['who'])
    change['comments'] = new_rev.message
    change['revision'] = new_revno
    files = change['files'] = []
    changes = repository.revision_tree(new_revid).changes_from(
        repository.revision_tree(old_revid))
    for (collection, name) in ((changes.added, 'ADDED'),
                               (changes.removed, 'REMOVED'),
                               (changes.modified, 'MODIFIED')):
        for info in collection:
            path = info[0]
            kind = info[2]
            files.append(' '.join([path, kind, name]))
    for info in changes.renamed:
        oldpath, newpath, id, kind, text_modified, meta_modified = info
        elements = [oldpath, kind,'RENAMED', newpath]
        if text_modified or meta_modified:
            elements.append('MODIFIED')
        files.append(' '.join(elements))
    return change
コード例 #3
0
ファイル: wutils.py プロジェクト: I201821180/NextgenWifi
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
コード例 #4
0
ファイル: bot.py プロジェクト: TijmenW/openteacher
    def _checkBranch(self, branchName, branchUrl):
        branch = bzrlib.branch.Branch.open(branchUrl)

        old_revno = self._branchRevnos.get(branchUrl, branch.revno())
        new_revno = branch.revno()

        revnos = range(old_revno + 1, new_revno + 1)
        revids = [branch.get_rev_id(revno) for revno in revnos]
        revs = branch.repository.get_revisions(revids)

        #[-4:] to prevent a flood. More than 4 revisions pushed in one
        #time is probably not worth printing anyway.
        for revno, rev in zip(revnos, revs)[-4:]:
            authors = rev.get_apparent_authors()
            authors = (a.rsplit(" ", 1)[0] for a in authors)
            resp = u"Revision {revno} pushed to {branchName} by {authors}: {summary}".format(
                authors=", ".join(authors),
                branchName=branchName,
                revno=revno,
                summary=rev.get_summary()).encode("UTF-8")
            self.msg(self.factory.branchChannel, resp)
        self._branchRevnos[branchUrl] = new_revno
コード例 #5
0
ファイル: bot.py プロジェクト: TijmenW/openteacher
	def _checkBranch(self, branchName, branchUrl):
		branch = bzrlib.branch.Branch.open(branchUrl)

		old_revno = self._branchRevnos.get(branchUrl, branch.revno())
		new_revno = branch.revno()

		revnos = range(old_revno + 1, new_revno + 1)
		revids = [branch.get_rev_id(revno) for revno in revnos]
		revs = branch.repository.get_revisions(revids)

		#[-4:] to prevent a flood. More than 4 revisions pushed in one
		#time is probably not worth printing anyway.
		for revno, rev in zip(revnos, revs)[-4:]:
			authors = rev.get_apparent_authors()
			authors = (a.rsplit(" ", 1)[0] for a in authors)
			resp = u"Revision {revno} pushed to {branchName} by {authors}: {summary}".format(
				authors=", ".join(authors),
				branchName=branchName,
				revno=revno,
				summary=rev.get_summary()
			).encode("UTF-8")
			self.msg(self.factory.branchChannel, resp)
		self._branchRevnos[branchUrl] = new_revno