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.
# Copyright (c) 2009-2010 LOGILAB S.A. (Paris, FRANCE).# http://www.logilab.fr/ -- mailto:contact@logilab.fr## This program is free software; you can redistribute it and/or modify it under# the terms of the GNU General Public License as published by the Free Software# Foundation; either version 2 of the License, or (at your option) any later# version.## This program is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.## You should have received a copy of the GNU General Public License along with# this program; if not, write to the Free Software Foundation, Inc.,# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."""Qt4 high level widgets for hg repo changelogs and filelogs"""importosimportdifflibimportrefrommercurialimporthg,error,match,patch,utilfrommercurialimportuiasuimod,mdifffromtortoisehg.utilimporthglib,patchctxfromtortoisehg.hgqt.i18nimport_fromtortoisehg.hgqtimportannotate,qscilib,qtlib,blockmatcher,lexersfromtortoisehg.hgqtimportvisdifffromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*fromPyQt4importQsciqsci=Qsci.QsciScintillaDiffMode=1FileMode=2AnnMode=3classHgFileView(QFrame):"""file diff and content viewer"""linkActivated=pyqtSignal(QString)fileDisplayed=pyqtSignal(QString,QString)showMessage=pyqtSignal(QString)revisionSelected=pyqtSignal(int)shelveToolExited=pyqtSignal()searchRequested=pyqtSignal(unicode)"""Emitted (pattern) when user request to search content"""grepRequested=pyqtSignal(unicode,dict)"""Emitted (pattern, opts) when user request to search changelog"""def__init__(self,repo,parent):QFrame.__init__(self,parent)framelayout=QVBoxLayout(self)framelayout.setContentsMargins(0,0,0,0)framelayout.setSpacing(0)l=QHBoxLayout()l.setContentsMargins(0,0,0,0)l.setSpacing(0)self.repo=repoself.topLayout=QVBoxLayout()self.labelhbox=hbox=QHBoxLayout()hbox.setContentsMargins(0,0,0,0)hbox.setSpacing(2)self.topLayout.addLayout(hbox)self.diffToolbar=QToolBar(_('Diff Toolbar'))self.diffToolbar.setIconSize(QSize(16,16))hbox.addWidget(self.diffToolbar)self.filenamelabel=w=QLabel()w.setWordWrap(True)f=w.textInteractionFlags()w.setTextInteractionFlags(f|Qt.TextSelectableByMouse)w.linkActivated.connect(self.linkActivated)hbox.addWidget(w,1)self.extralabel=w=QLabel()w.setWordWrap(True)w.linkActivated.connect(self.linkActivated)self.topLayout.addWidget(w)w.hide()framelayout.addLayout(self.topLayout)framelayout.addLayout(l,1)hbox=QHBoxLayout()hbox.setContentsMargins(0,0,0,0)hbox.setSpacing(0)l.addLayout(hbox)self.blk=blockmatcher.BlockList(self)self.sci=annotate.AnnotateView(repo,self)hbox.addWidget(self.blk)hbox.addWidget(self.sci,1)fornamein('searchRequested','editSelected','grepRequested'):getattr(self.sci,name).connect(getattr(self,name))self.sci.revisionHint.connect(self.showMessage)self.sci.sourceChanged.connect(self.sourceChanged)self.sci.setAnnotationEnabled(False)self.blk.linkScrollBar(self.sci.verticalScrollBar())self.blk.setVisible(False)self.sci.setFrameStyle(0)self.sci.setReadOnly(True)self.sci.setUtf8(True)self.sci.installEventFilter(qscilib.KeyPressInterceptor(self))self.sci.setCaretLineVisible(False)# define markers for colorize zones of diffself.markerplus=self.sci.markerDefine(qsci.Background)self.markerminus=self.sci.markerDefine(qsci.Background)self.markertriangle=self.sci.markerDefine(qsci.Background)self.sci.setMarkerBackgroundColor(QColor('#B0FFA0'),self.markerplus)self.sci.setMarkerBackgroundColor(QColor('#A0A0FF'),self.markerminus)self.sci.setMarkerBackgroundColor(QColor('#FFA0A0'),self.markertriangle)# hide margin 0 (markers)self.sci.setMarginType(0,qsci.SymbolMargin)self.sci.setMarginWidth(0,0)self.searchbar=qscilib.SearchToolBar(hidable=True)self.searchbar.hide()self.searchbar.searchRequested.connect(self.find)self.searchbar.conditionChanged.connect(self.highlightText)self.layout().addWidget(self.searchbar)self._ctx=Noneself._filename=Noneself._status=Noneself._mode=Noneself._lostMode=Noneself._lastSearch=u'',Falseself.actionDiffMode=QAction(qtlib.geticon('view-diff'),_('View change as unified diff output'),self)self.actionDiffMode.setCheckable(True)self.actionDiffMode._mode=DiffModeself.actionFileMode=QAction(qtlib.geticon('view-file'),_('View change in context of file'),self)self.actionFileMode.setCheckable(True)self.actionFileMode._mode=FileModeself.actionAnnMode=QAction(qtlib.geticon('view-annotate'),_('View change in context, annotate with ''revision number'),self)self.actionAnnMode.setCheckable(True)self.actionAnnMode._mode=AnnModeself.modeToggleGroup=QActionGroup(self)self.modeToggleGroup.addAction(self.actionDiffMode)self.modeToggleGroup.addAction(self.actionFileMode)self.modeToggleGroup.addAction(self.actionAnnMode)self.modeToggleGroup.triggered.connect(self.setMode)# Next/Prev diff (in full file mode)self.actionNextDiff=QAction(qtlib.geticon('go-down'),'Next diff (alt+down)',self)self.actionNextDiff.setShortcut('Alt+Down')self.actionNextDiff.triggered.connect(self.nextDiff)self.actionPrevDiff=QAction(qtlib.geticon('go-up'),'Previous diff (alt+up)',self)self.actionPrevDiff.setShortcut('Alt+Up')self.actionPrevDiff.triggered.connect(self.prevDiff)self.setMode(self.actionDiffMode)self.actionFind=self.searchbar.toggleViewAction()self.actionFind.setIcon(qtlib.geticon('edit-find'))self.actionFind.setToolTip(_('Toggle display of text search bar'))self.actionFind.setShortcut(QKeySequence.Find)self.actionShelf=QAction('Shelve',self)self.actionShelf.setIcon(qtlib.geticon('shelve'))self.actionShelf.setToolTip(_('Open shelve tool'))self.actionShelf.triggered.connect(self.launchShelve)tb=self.diffToolbartb.addAction(self.actionDiffMode)tb.addAction(self.actionFileMode)tb.addAction(self.actionAnnMode)tb.addSeparator()tb.addAction(self.actionNextDiff)tb.addAction(self.actionPrevDiff)tb.addSeparator()tb.addAction(self.actionFind)tb.addAction(self.actionShelf)self.timer=QTimer()self.timer.setSingleShot(False)self.timer.timeout.connect(self.timerBuildDiffMarkers)deflaunchShelve(self):fromtortoisehg.hgqtimportshelve# TODO: pass self._filenamedlg=shelve.ShelveDialog(self.repo,self)dlg.finished.connect(dlg.deleteLater)dlg.exec_()self.shelveToolExited.emit()defsetFont(self,font):self.sci.setFont(font)defloadSettings(self,qs,prefix):self.sci.loadSettings(qs,prefix)defsaveSettings(self,qs,prefix):self.sci.saveSettings(qs,prefix)defsetRepo(self,repo):self.repo=repo@pyqtSlot(QAction)defsetMode(self,action):'One of the mode toolbar buttons has been toggled'mode=action._modeifmode!=self._mode:self._mode=modeself.actionNextDiff.setEnabled(False)self.actionPrevDiff.setEnabled(False)self.blk.setVisible(mode==FileMode)self.sci.setAnnotationEnabled(mode==AnnMode)self.displayFile()defrestrictModes(self,candiff,canfile,canann):'Disable modes based on content constraints'self.actionDiffMode.setEnabled(candiff)self.actionFileMode.setEnabled(canfile)self.actionAnnMode.setEnabled(canann)# Switch mode if necessarymode=self._modeifnotcandiffandmode==DiffModeandcanfile:mode=FileModeifnotcanfileandmode!=DiffMode:mode=DiffModeifself._lostModeisNone:self._lostMode=self._modeifself._mode!=mode:self.actionNextDiff.setEnabled(False)self.actionPrevDiff.setEnabled(False)self.blk.setVisible(mode==FileMode)self.sci.setAnnotationEnabled(mode==AnnMode)self._mode=modeifself._mode==DiffMode:self.actionDiffMode.setChecked(True)elifself._mode==FileMode:self.actionFileMode.setChecked(True)else:self.actionAnnMode.setChecked(True)defsetContext(self,ctx):self._ctx=ctxself._p_rev=Noneself.sci.setTabWidth(ctx._repo.tabwidth)self.actionAnnMode.setVisible(ctx.rev()!=None)self.actionShelf.setVisible(ctx.rev()==None)defshowLine(self,line):ifline<self.sci.lines():self.sci.setCursorPosition(line,0)@pyqtSlot()defclearDisplay(self):self._filename=Noneself.restrictModes(False,False,False)self.sci.setMarginWidth(1,0)self.clearMarkup()defclearMarkup(self):self.sci.clear()self.blk.clear()# Setting the label to ' ' rather than clear() keeps the label# from disappearing during refresh, and tool layouts bouncingself.filenamelabel.setText(' ')self.extralabel.hide()defdisplayFile(self,filename=None,rev=None,status=None):iffilenameisNone:filename,status=self._filename,self._statuselse:self._filename,self._status=filename,statusifisinstance(filename,(unicode,QString)):filename=hglib.fromunicode(filename)self.clearMarkup()iffilenameisNone:self.restrictModes(False,False,False)returnifrevisnotNone:self._p_rev=revifself._p_revisnotNone:ctx2=self.repo[self._p_rev]else:ctx2=Nonefd=FileData(self._ctx,ctx2,filename,status)iffd.elabel:self.extralabel.setText(fd.elabel)self.extralabel.show()else:self.extralabel.hide()self.filenamelabel.setText(fd.flabel)ifnotfd.isValid():self.sci.setText(fd.error)self.restrictModes(False,False,False)returncandiff=bool(fd.diff)canfile=bool(fd.contents)canann=canfileandtype(self._ctx.rev())isintifnotcandiffornotcanfile:self.restrictModes(candiff,canfile,canann)else:self.actionDiffMode.setEnabled(True)self.actionFileMode.setEnabled(True)self.actionAnnMode.setEnabled(True)ifself._lostMode:self._mode=self._lostModeifself._lostMode==DiffMode:self.actionDiffMode.trigger()elifself._lostMode==FileMode:self.actionFileMode.trigger()elifself._lostMode==AnnMode:self.actionAnnMode.trigger()self._lostMode=Noneself.blk.setVisible(self._mode==FileMode)self.sci.setAnnotationEnabled(self._mode==AnnMode)ifself._mode==DiffMode:self.sci.setMarginWidth(1,0)lexer=lexers.get_diff_lexer(self)self.sci.setLexer(lexer)# trim first three lines, for example:# diff -r f6bfc41af6d7 -r c1b18806486d tortoisehg/hgqt/thgrepo.py# --- a/tortoisehg/hgqt/thgrepo.py# +++ b/tortoisehg/hgqt/thgrepo.pyiffd.diff:out=fd.diff.split('\n',3)iflen(out)==4:self.sci.setText(hglib.tounicode(out[3]))else:# there was an error or rename without diffsself.sci.setText(hglib.tounicode(fd.diff))eliffd.contentsisNone:returnelifself._mode==AnnMode:self.sci.setSource(filename,self._ctx.rev())else:lexer=lexers.get_lexer(filename,fd.contents,self)self.sci.setLexer(lexer)self.sci.setText(fd.contents)self.sci._updatemarginwidth()self.highlightText(*self._lastSearch)uf=hglib.tounicode(self._filename)self.fileDisplayed.emit(uf,fd.contentsorQString())ifself._mode==FileModeandfd.contentsandfd.olddata:# Update blk marginifself.timer.isActive():self.timer.stop()self._fd=fdself.actionNextDiff.setEnabled(False)self.actionPrevDiff.setEnabled(False)self.blk.syncPageStep()self.timer.start()## These four functions are used by Shift+Cursor actions in revdetails#defnextLine(self):x,y=self.sci.getCursorPosition()self.sci.setCursorPosition(x+1,y)defprevLine(self):x,y=self.sci.getCursorPosition()self.sci.setCursorPosition(x-1,y)defnextCol(self):x,y=self.sci.getCursorPosition()self.sci.setCursorPosition(x,y+1)defprevCol(self):x,y=self.sci.getCursorPosition()self.sci.setCursorPosition(x,y-1) @pyqtSlot(unicode, object)
@pyqtSlot(unicode, object, int)
def sourceChanged(self, path, rev, line=None):
- if rev != self._ctx.rev():
+ if rev != self._ctx.rev() and type(rev) is int:
self.revisionSelected.emit(rev)
@pyqtSlot(unicode, object, int)
defeditSelected(self,path,rev,line):"""Open editor to show the specified file"""path=hglib.fromunicode(path)base=visdiff.snapshot(self.repo,[path],self.repo[rev])[0]files=[os.path.join(base,path)]pattern=hglib.fromunicode(self._lastSearch[0])qtlib.editfiles(self.repo,files,line,pattern,self)@pyqtSlot(unicode,bool,bool,bool)deffind(self,exp,icase=True,wrap=False,forward=True):self.sci.find(exp,icase,wrap,forward)@pyqtSlot(unicode,bool)defhighlightText(self,match,icase=False):self._lastSearch=match,icaseself.sci.highlightText(match,icase)defverticalScrollBar(self):returnself.sci.verticalScrollBar()## file mode diff markers#deftimerBuildDiffMarkers(self):'show modified and added lines in the self.blk margin'self.sci.setUpdatesEnabled(False)self.blk.setUpdatesEnabled(False)ifself._fd:olddata=self._fd.olddata.splitlines()newdata=self._fd.contents.splitlines()diff=difflib.SequenceMatcher(None,olddata,newdata)self._opcodes=diff.get_opcodes()self._fd=Noneself._diffs=[]fortag,alo,ahi,blo,bhiinself._opcodes[:30]:iftag=='replace':self._diffs.append([blo,bhi])self.blk.addBlock('x',blo,bhi)foriinrange(blo,bhi):self.sci.markerAdd(i,self.markertriangle)eliftag=='insert':self._diffs.append([blo,bhi])self.blk.addBlock('+',blo,bhi)foriinrange(blo,bhi):self.sci.markerAdd(i,self.markerplus)eliftagin('equal','delete'):passelse:raiseValueError,'unknown tag %r'%(tag,)self._opcodes=self._opcodes[30:]ifnotself._opcodes:self.actionNextDiff.setEnabled(bool(self._diffs))self.actionPrevDiff.setEnabled(False)self.timer.stop()self.sci.setUpdatesEnabled(True)self.blk.setUpdatesEnabled(True)defnextDiff(self):ifself._mode==DiffModeornotself._diffs:self.actionNextDiff.setEnabled(False)self.actionPrevDiff.setEnabled(False)returnrow,column=self.sci.getCursorPosition()fori,(lo,hi)inenumerate(self._diffs):iflo>row:last=(i==(len(self._diffs)-1))self.sci.setCursorPosition(lo,0)self.sci.verticalScrollBar().setValue(lo)breakelse:last=Trueself.actionNextDiff.setEnabled(notlast)self.actionPrevDiff.setEnabled(True)defprevDiff(self):ifself._mode==DiffModeornotself._diffs:self.actionNextDiff.setEnabled(False)self.actionPrevDiff.setEnabled(False)returnrow,column=self.sci.getCursorPosition()fori,(lo,hi)inenumerate(reversed(self._diffs)):ifhi<row:first=(i==(len(self._diffs)-1))self.sci.setCursorPosition(lo,0)self.sci.verticalScrollBar().setValue(lo)breakelse:first=Trueself.actionNextDiff.setEnabled(True)self.actionPrevDiff.setEnabled(notfirst)defnDiffs(self):returnlen(self._diffs)classFileData(object):def__init__(self,ctx,ctx2,wfile,status=None):self.contents=Noneself.error=Noneself.olddata=Noneself.diff=Noneself.flabel=u''self.elabel=u''self.readStatus(ctx,ctx2,wfile,status)defcheckMaxDiff(self,ctx,wfile):p=_('File or diffs not displayed: ')try:fctx=ctx.filectx(wfile)ifctx.rev()isNone:size=fctx.size()else:# fctx.size() can read all data into memory in rename cases so# we read the size directly from the filelog, this is deeper# under the API than I prefer to go, but seems necessarysize=fctx._filelog.rawsize(fctx.filerev())except(EnvironmentError,error.LookupError),e:self.error=p+hglib.tounicode(str(e))returnNoneifsize>ctx._repo.maxdiff:self.error=p+_('File is larger than the specified max size.\n')returnNonetry:data=fctx.data()if'\0'indata:self.error=p+_('File is binary.\n')returnNoneexceptEnvironmentError,e:self.error=p+hglib.tounicode(str(e))returnNonereturnfctx,datadefisValid(self):returnself.errorisNonedefreadStatus(self,ctx,ctx2,wfile,status):defgetstatus(repo,n1,n2,wfile):m=match.exact(repo.root,repo.getcwd(),[wfile])modified,added,removed=repo.status(n1,n2,match=m)[:3]ifwfileinmodified:return'M'ifwfileinadded:return'A'ifwfileinremoved:return'R'ifwfileinctx:return'C'returnNonerepo=ctx._repoself.flabel+=u'<b>%s</b>'%hglib.tounicode(wfile)ifisinstance(ctx,patchctx.patchctx):self.diff=ctx.thgmqpatchdata(wfile)flags=ctx.flags(wfile)ifflagsin('x','-'):lbl=_("exec mode has been <font color='red'>%s</font>")change=(flags=='x')and_('set')or_('unset')self.elabel=lbl%changeelifflags=='l':self.flabel+=_(' <i>(is a symlink)</i>')returnabsfile=repo.wjoin(wfile)if(wfileinctxand'l'inctx.flags(wfile))or \
os.path.islink(absfile):ifwfileinctx:data=ctx[wfile].data()else:data=os.readlink(absfile)self.contents=hglib.tounicode(data)self.flabel+=_(' <i>(is a symlink)</i>')returnifstatusisNone:status=getstatus(repo,ctx.p1().node(),ctx.node(),wfile)ifctx2isNone:ctx2=ctx.p1()ifstatus=='S':try:frommercurialimportsubrepo,commandsassert(ctx.rev()isNone)srev=ctx.substate.get(wfile,subrepo.nullstate)[1]sub=ctx.sub(wfile)ifisinstance(sub,subrepo.hgsubrepo):srepo=sub._reposactual=srepo['.'].hex()else:self.error=_('Not a Mercurial subrepo, not previewable')returnout=[]_ui=uimod.ui()_ui.pushbuffer()commands.status(_ui,srepo)data=_ui.popbuffer()ifdata:out.append(_('File Status:')+u'\n')out.append(hglib.tounicode(data))out.append(u'\n')ifsrev=='':out.append(_('New subrepository')+u'\n\n')elifsrev!=sactual:out.append(_('Revision has changed from:')+u'\n\n')opts={'date':None,'user':None,'rev':[srev]}_ui.pushbuffer()commands.log(_ui,srepo,**opts)out.append(hglib.tounicode(_ui.popbuffer()))out.append(_('To:')+u'\n')opts['rev']=[sactual]_ui.pushbuffer()commands.log(_ui,srepo,**opts)out.append(hglib.tounicode(_ui.popbuffer()))self.contents=u''.join(out)self.flabel+=_(' <i>(is a dirty sub-repository)</i>')lbl=u' <a href="subrepo:%s">%s...</a>'self.flabel+=lbl%(hglib.tounicode(srepo.root),_('open'))except(EnvironmentError,error.RepoError,util.Abort),e:self.error=_('Error previewing subrepo: %s')% \
hglib.tounicode(str(e))return# TODO: elif check if a subdirectory (for manifest tool)mde=_('File or diffs not displayed: ')+ \
_('File is larger than the specified max size.\n')ifstatusin('R','!'):ifwfileinctx.p1():fctx=ctx.p1()[wfile]iffctx._filelog.rawsize(fctx.filerev())>ctx._repo.maxdiff:self.error=mdeelse:olddata=fctx.data()if'\0'inolddata:self.error='binary file'else:self.contents=hglib.tounicode(olddata)self.flabel+=_(' <i>(was deleted)</i>')else:self.flabel+=_(' <i>(was added, now missing)</i>')returnifstatusin('I','?','C'):try:ifos.path.getsize(repo.wjoin(wfile))>ctx._repo.maxdiff:self.error=mdeelse:data=open(repo.wjoin(wfile),'r').read()if'\0'indata:self.error='binary file'else:self.contents=hglib.tounicode(data)ifstatusin('I','?'):self.flabel+=_(' <i>(is unversioned)</i>')exceptEnvironmentError,e:self.error=hglib.tounicode(str(e))returnifstatusin('M','A'):res=self.checkMaxDiff(ctx,wfile)ifresisNone:returnfctx,newdata=resself.contents=hglib.tounicode(newdata)change=Noneforpfctxinfctx.parents():if'x'infctx.flags()and'x'notinpfctx.flags():change=_('set')elif'x'notinfctx.flags()and'x'inpfctx.flags():change=_('unset')ifchange:lbl=_("exec mode has been <font color='red'>%s</font>")self.elabel=lbl%changeifstatus=='A':renamed=fctx.renamed()ifnotrenamed:self.flabel+=_(' <i>(was added)</i>')returnoldname,node=renamedfr=hglib.tounicode(oldname)self.flabel+=_(' <i>(renamed from %s)</i>')%frolddata=repo.filectx(oldname,fileid=node).data()elifstatus=='M':ifwfilenotinctx2:# merge situation where file was added in other branchself.flabel+=_(' <i>(was added)</i>')returnoldname=wfileolddata=ctx2[wfile].data()else:returnself.olddata=hglib.tounicode(olddata)newdate=util.datestr(ctx.date())olddate=util.datestr(ctx2.date())revs=[str(ctx),str(ctx2)]diffopts=patch.diffopts(repo.ui,{})diffopts.git=Falseself.diff=mdiff.unidiff(olddata,olddate,newdata,newdate,oldname,wfile,revs,diffopts)
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.