예제 #1
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['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
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
파일: 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
예제 #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
def subjects_for_branch(branch, new_revno, old_revno, is_push, message):
    """
    Generates the event's subject for commit, push and pull events
    
    branch - the bzrlib.branch.Branch instance
    new_revno - the new revision number generated after a commit, 
        after a push or a pull
    old_revno - the old revno which is was present before the commit,
        push or pull event
    is_push - True then push, is False then pull, is None then commit
    message - the Commit message
    """

    from zeitgeist.datamodel import Subject, Interpretation, Manifestation
    location = urlutils.unescape_for_display(branch.base, "utf-8").decode("utf-8")
    
    if is_push is None:
        # Commit
        text = u"Revision: %s, Message: %s" %(new_revno, message)
    elif is_push is True:
        # Push
        text = "Pushed branch from %s to %s" %(old_revno, new_revno)
    elif is_push is False:
        # Pull
        text = "Updated branch from %s to %s" %(old_revno, new_revno)
    
    folder_subj =  Subject.new_for_values(
        uri=unicode(branch.base),
        interpretation=unicode(Interpretation.FOLDER),
        manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
        text=text,
        origin=unicode(branch.base),
        mimetype="application/x-bzr",
    )
    
    all_subjs = [folder_subj, ]
    
    # List down the files only in case of Commit as in case of 
    # push or pull, remote URI is used using which constructing
    # file URI is not possible
    if is_push is None:
        prev_tree = branch.repository.revision_tree(branch.get_rev_id(old_revno))
        next_tree = branch.repository.revision_tree(branch.get_rev_id(new_revno))
    
        for (file_id, path, content_change, versioned, parent_id, name, kind,
             executable) in next_tree.iter_changes(prev_tree):
             
            name = path[0] if path[0] is not None else path[1]
            uri = os.path.join(unicode(branch.base), name)
             
            # fi.get_content_type returns the file mimetype 
            f=Gio.File.new_for_uri(uri)
            fi=f.query_info("*", Gio.FileQueryInfoFlags.NONE, None)
             
            subj = Subject.new_for_values(
                uri=uri,
                manifestation=unicode(Manifestation.FILE_DATA_OBJECT),
                text=text,
                origin=unicode(branch.base),
                mimetype=fi.get_content_type(),
            )
            all_subjs.append(subj)
    
    return all_subjs