Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# annotate.py - File annotation widget## Copyright 2010 Steve Borho <steve@borho.org>## This software may be used and distributed according to the terms of the# GNU General Public License version 2, incorporated herein by reference.importosimportrefrommercurialimportui,hg,error,commands,cmdutil,utilfromtortoisehg.hgqtimportvisdiff,qtlib,wctxactionsfromtortoisehg.utilimportpaths,hglib,colormapfromtortoisehg.hgqt.i18nimport_fromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*# Technical Debt# Syntax Highlighting?
# Pass search parameters to grep
# forward/backward history buttons
+# menu options for viewing appropriate changesetsclass AnnotateView(QFrame):
loadBegin = pyqtSignal()
loadComplete=pyqtSignal()revisionHint=pyqtSignal(QString)classRevArea(QWidget):'Display user@rev in front of each line'def__init__(self,edit,parent=None):QWidget.__init__(self,parent)self.edit=editself.width=0defsizeHint(self):returnQSize(self.width,0)defupdateContents(self,rect,scroll):ifscroll:self.scroll(0,scroll)else:self.update(0,rect.y(),self.width,rect.height())defpaintEvent(self,event):self.edit.paintRevArea(self,event)QWidget.paintEvent(self,event)classTextArea(QPlainTextEdit):'Display lines of annotation text'revisionHint=pyqtSignal(QString)def__init__(self,parent=None):QPlainTextEdit.__init__(self,parent)self.document().setDefaultStyleSheet(qtlib.thgstylesheet)self.setReadOnly(True)self.setContextMenuPolicy(Qt.CustomContextMenu)self.connect(self,SIGNAL('customContextMenuRequested(const QPoint &)'),self.customContextMenuRequested)self.setTextInteractionFlags(Qt.TextSelectableByMouse|Qt.TextSelectableByKeyboard)tm=QFontMetrics(self.font())self.charwidth=tm.width('9')self.charheight=tm.height()self.revs=[]self.summaries=[]self.setMouseTracking(True)self.lastrev=NonedefpaintRevArea(self,revarea,event):painter=QPainter(revarea)painter.fillRect(event.rect(),Qt.lightGray)block=self.firstVisibleBlock()line=block.blockNumber()offs=self.contentOffset()top=self.blockBoundingGeometry(block).translated(offs).top()whileblock.isValid()andline<len(self.revs):ifnotblock.isVisible()ortop>=event.rect().bottom():breakpainter.setPen(Qt.black)rect=QRect(0,top,revarea.width,self.charheight)painter.drawText(rect,Qt.AlignRight,str(self.revs[line]))block=block.next()top+=self.blockBoundingGeometry(block).height()line+=1defmouseMoveEvent(self,event):cursor=self.cursorForPosition(event.pos())line=cursor.block()ifnotline.isValid()orline.blockNumber()>=len(self.revs):returnrev=self.revs[line.blockNumber()]ifrev!=self.lastrev:self.revisionHint.emit(self.summaries[rev])self.lastrev=revdefcustomContextMenuRequested(self,point):cursor=self.cursorForPosition(point)point=self.mapToGlobal(point)line=cursor.block()ifnotline.isValid()orline.blockNumber()>=len(self.revs):returnfctx,line=self.links[line.blockNumber()]data=[fctx.path(),fctx.linkrev(),line]# check if the user has opened a menu on a text selectionc=self.textCursor()ifcursor.position()>=c.selectionStart()and \
cursor.position()<=c.selectionEnd():selection=c.selection().toPlainText()defsorig():sdata=[selection,fctx.linkrev()]self.emit(SIGNAL('searchAtRev'),sdata)defsctx():self.emit(SIGNAL('searchAtParent'),selection)defsearchall():self.emit(SIGNAL('searchAll'),selection)defsann():self.emit(SIGNAL('searchAnnotation'),selection)menu=QMenu(self)menu=QMenu(self)forname,funcin[(_('Search in original revision'),sorig),(_('Search in working revision'),sctx),(_('Search in current annotation'),sann),(_('Search in history'),searchall)]:action=menu.addAction(name)action.wrapper=lambdaf=func:f()self.connect(action,SIGNAL('triggered()'),action.wrapper)returnmenu.exec_(point)defannorig():self.emit(SIGNAL('revSelected'),data)defeditorig():self.emit(SIGNAL('editSelected'),data)menu=QMenu(self)forname,funcin[(_('Annotate originating revision'),annorig),(_('View originating revision'),editorig)]:action=menu.addAction(name)action.wrapper=lambdaf=func:f()self.connect(action,SIGNAL('triggered()'),action.wrapper)iffctx.linkrev()>0:data2=[fctx.path(),fctx.linkrev()-1,line]defannparent():self.emit(SIGNAL('revSelected'),data2)defeditparent():self.emit(SIGNAL('editSelected'),data2)forname,funcin[(_('Annotate parent revision'),annparent),(_('View parent revision'),editparent)]:action=menu.addAction(name)action.wrapper=lambdaf=func:f()self.connect(action,SIGNAL('triggered()'),action.wrapper)menu.exec_(point)def__init__(self,parent=None):super(AnnotateView,self).__init__(parent)self.setFrameStyle(QFrame.StyledPanel|QFrame.Sunken)self.edit=self.TextArea(self)self.revarea=self.RevArea(self.edit)self.edit.updateRequest.connect(self.revarea.updateContents)self.edit.revisionHint.connect(lambdah:self.revisionHint.emit(h))self.connect(self.edit,SIGNAL('revSelected'),lambdadata:self.emit(SIGNAL('revSelected'),data))self.connect(self.edit,SIGNAL('editSelected'),lambdadata:self.emit(SIGNAL('editSelected'),data))self.connect(self.edit,SIGNAL('searchAtRev'),lambdadata:self.emit(SIGNAL('searchAtRev'),data))self.connect(self.edit,SIGNAL('searchAtParent'),lambdapattern:self.emit(SIGNAL('searchAtParent'),pattern))self.connect(self.edit,SIGNAL('searchAll'),lambdapattern:self.emit(SIGNAL('searchAll'),pattern))self.connect(self.edit,SIGNAL('searchAnnotation'),lambdapattern:self.emit(SIGNAL('searchAnnotation'),pattern))hbox=QHBoxLayout(self)hbox.setSpacing(10)hbox.setMargin(0)hbox.addWidget(self.revarea)hbox.addWidget(self.edit)self.thread=Noneself.matches=[]defannotateFileAtRev(self,repo,ctx,wfile,line=None):ifself.threadisnotNone:returnfctx=ctx[wfile]curdate=fctx.date()[0]basedate=repo.filectx(wfile,fileid=0).date()[0]agedays=(curdate-fctx.date()[0])/(24*60*60)self.cm=colormap.AnnotateColorSaturation(agedays)self.curdate=curdateself.repo=repoself.resumeline=lineself.annfile=wfileself.loadBegin.emit()self.thread=AnnotateThread(fctx)self.thread.done.connect(self.finished)self.thread.start()deffinished(self):self.thread.wait()self.loadComplete.emit()ifhasattr(self.thread,'data'):self.fillModel(self.thread.data)lines=len(self.edit.revs)*1.0ifself.resumelineandlines>self.resumeline:cursor=self.edit.textCursor()cursor.movePosition(QTextCursor.NextBlock,QTextCursor.MoveAnchor,self.resumeline-1)cursor.select(QTextCursor.LineUnderCursor)self.edit.setTextCursor(cursor)sb=self.edit.verticalScrollBar()val=int(sb.maximum()*self.resumeline/lines)sb.setValue(val)self.edit.ensureCursorVisible()else:self.edit.verticalScrollBar().setValue(0)self.thread=NonedefkeyPressEvent(self,event):ifevent.key()==Qt.Key_Escape:ifself.threadandself.thread.isRunning():self.thread.terminate()self.finished()returnreturnsuper(AnnotateView,self).keyPressEvent(event)deffillModel(self,data):revs,lines,lpos,sels,links=[],[],[],[],[]sums={}pos=0forfctx,origline,textindata:rev=fctx.linkrev()lines.append(text)lpos.append(pos)revs.append(rev)links.append([fctx,origline])pos+=len(text)ifrevnotinsums:author=hglib.username(fctx.user())date=hglib.age(fctx.date())l=fctx.description().replace(u'\0','').splitlines()summary=landl[0]or''iffctx.path()==self.annfile:source=''else:source='(%s)'%fctx.path()desc='%s@%s%s:%s "%s"'%(author,rev,source,date,summary)sums[rev]=descself.edit.summaries=sumsself.edit.links=linksself.edit.setPlainText(''.join(lines))self.edit.revs=revswidth=max([len(str(r))forrinrevs])*self.edit.charwidth+3self.revarea.width=widthself.revarea.setFixedWidth(width)fori,revinenumerate(revs):ctx=self.repo[rev]rgb=self.cm.get_color(ctx,self.curdate)sel=QTextEdit.ExtraSelection()sel.bgcolor=QColor(rgb)# save a referencesel.format.setBackground(sel.bgcolor)sel.format.setProperty(QTextFormat.FullWidthSelection,True)sel.cursor=QTextCursor(self.edit.document())sel.cursor.setPosition(lpos[i])sel.cursor.clearSelection()sels.append(sel)self.colorsels=selsself.edit.setExtraSelections(self.colorsels)defnextMatch(self):ifnotself.matches:returnifself.curmatch<len(self.matches)-1:self.curmatch+=1self.edit.setTextCursor(self.matches[self.curmatch].cursor)defprevMatch(self):ifnotself.matches:returnifself.curmatch>0:self.curmatch-=1self.edit.setTextCursor(self.matches[self.curmatch].cursor)defsearchText(self,match,icase):matches=[]color=QColor(Qt.yellow)flags=QTextDocument.FindFlags()ifnoticase:flags|=QTextDocument.FindCaseSensitivelydoc=self.edit.document()cursor=doc.find(match,0,flags)whilenotcursor.isNull():selection=QTextEdit.ExtraSelection()selection.format.setBackground(color)selection.cursor=cursormatches.append(selection)cursor=doc.find(match,cursor)self.matches=matchesself.curmatch=0ifmatches:self.edit.setTextCursor(matches[0].cursor)self.edit.setExtraSelections(self.colorsels+self.matches)classAnnotateThread(QThread):'Background thread for annotating a file at a revision'done=pyqtSignal()def__init__(self,fctx):super(AnnotateThread,self).__init__()self.fctx=fctxdefrun(self):data=[]for(fctx,line),textinself.fctx.annotate(True,True):data.append([fctx,line,text])self.data=dataself.done.emit()classAnnotateDialog(QDialog):def__init__(self,*pats,**opts):super(AnnotateDialog,self).__init__(opts.get('parent'))mainvbox=QVBoxLayout()self.setLayout(mainvbox)hbox=QHBoxLayout()hbox.setMargin(0)lbl=QLabel(_('Regexp:'))le=QLineEdit()le.setText(hglib.tounicode(opts.get('pattern','')))lbl.setBuddy(le)lbl.setToolTip(_('Regular expression search pattern'))bt=QPushButton(_('Search'))bt.setDefault(True)bt.clicked.connect(self.searchText)chk=QCheckBox(_('Ignore case'))hbox.addWidget(lbl)hbox.addWidget(le,1)hbox.addWidget(chk)hbox.addWidget(bt)mainvbox.addLayout(hbox)self.le,self.chk=le,chkav=AnnotateView(self)mainvbox.addWidget(av)self.av=avstatus=QLabel()mainvbox.addWidget(status)av.revisionHint.connect(status.setText)self.connect(av,SIGNAL('revSelected'),self.revSelected)self.connect(av,SIGNAL('editSelected'),self.editSelected)self.connect(av,SIGNAL('searchAtRev'),self.searchAtRev)self.connect(av,SIGNAL('searchAtParent'),self.searchAtParent)self.connect(av,SIGNAL('searchAll'),self.searchAll)self.connect(av,SIGNAL('searchAnnotation'),self.searchAnnotation)self.status=statusself.opts=optsline=opts.get('line')iflineandisinstance(line,str):line=int(line)try:repo=hg.repository(ui.ui(),path=paths.find_root())ctx=repo[opts.get('rev')or'.']fctx=ctx[pats[0]]# just for validationexceptException,e:self.status.setText(hglib.tounicode(str(e)))av.annotateFileAtRev(repo,ctx,pats[0],line)self.setWindowTitle(_('Annotate %s@%d')%(pats[0],ctx.rev()))self.repo=repos=QSettings()self.restoreGeometry(s.value('annotate/geom').toByteArray())defrevSelected(self,args):repo=self.repowfile,rev,line=argstry:ctx=repo[rev]fctx=ctx[wfile]exceptException,e:self.status.setText(hglib.tounicode(str(e)))self.av.annotateFileAtRev(repo,ctx,wfile,line)self.setWindowTitle(_('Annotate %s@%d')%(wfile,ctx.rev()))defeditSelected(self,args):pattern=hglib.fromunicode(self.le.text())orNonerepo=self.repowfile,rev,line=argstry:ctx=repo[rev]fctx=ctx[wfile]exceptException,e:self.status.setText(hglib.tounicode(str(e)))base,_=visdiff.snapshot(repo,[wfile],repo[rev])files=[os.path.join(base,wfile)]wctxactions.edit(self,repo.ui,repo,files,line,pattern)defsearchAtRev(self,args):# grep widget needs to support argument passing via **opts# search repo[args[1]]raiseNotImplementedError()defsearchAtParent(self,pattern):# grep widget needs to support argument passing via **opts# search repo['.']raiseNotImplementedError()defsearchAll(self,pattern):# grep widget needs to support argument passing via **opts# search all historyraiseNotImplementedError()defsearchAnnotation(self,pattern):self.le.setText(QRegExp.escape(pattern))self.av.searchText(pattern,False)defsearchText(self):pattern=hglib.fromunicode(self.le.text())ifnotpattern:returntry:regexp=re.compile(pattern)exceptException,inst:msg=_('grep: invalid match pattern: %s\n')%instself.status.setText(hglib.tounicode(msg))ifself.chk.isChecked():regexp=QRegExp(pattern,Qt.CaseInsensitive)icase=Trueelse:icase=Falseregexp=QRegExp(pattern,Qt.CaseSensitive)self.av.searchText(regexp,icase)defwheelEvent(self,event):ifself.childAt(event.pos())!=self.le:event.ignore()returnifevent.delta()>0:self.av.prevMatch()elifevent.delta()<0:self.av.nextMatch()defaccept(self):s=QSettings()s.setValue('annotate/geom',self.saveGeometry())super(AnnotateDialog,self).accept()defreject(self):s=QSettings()s.setValue('annotate/geom',self.saveGeometry())super(AnnotateDialog,self).reject()defrun(ui,*pats,**opts):returnAnnotateDialog(*pats,**opts)
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.