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.
# rejects.py - TortoiseHg patch reject editor## Copyright 2011 Steve Borho <steve@borho.org>## This software may be used and distributed according to the terms# of the GNU General Public License, incorporated herein by reference.importcStringIOimportosfrommercurialimporthg,util,patch,commandsfromhgextimportrecordfromtortoisehg.utilimporthglibfromtortoisehg.util.patchctximportpatchctxfromtortoisehg.hgqt.i18nimport_fromtortoisehg.hgqtimportqtlib,qscilib,lexersfromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*fromPyQt4importQsciqsci=Qsci.QsciScintillaclassRejectsDialog(QDialog):def__init__(self,path,parent):super(RejectsDialog,self).__init__(parent)self.setWindowTitle(_('Merge rejected patch chunks into %s')%hglib.tounicode(path))self.setWindowFlags(Qt.Window)self.path=pathself.setLayout(QVBoxLayout())editor=qscilib.Scintilla()editor.setBraceMatching(qsci.SloppyBraceMatch)editor.setFolding(qsci.BoxedTreeFoldStyle)editor.installEventFilter(qscilib.KeyPressInterceptor(self))editor.setContextMenuPolicy(Qt.CustomContextMenu)editor.customContextMenuRequested.connect(self.menuRequested)self.baseLineColor=editor.markerDefine(qsci.Background,-1)editor.setMarkerBackgroundColor(QColor('lightblue'),self.baseLineColor)self.layout().addWidget(editor,3)searchbar=qscilib.SearchToolBar(self,hidable=True)searchbar.searchRequested.connect(editor.find)searchbar.conditionChanged.connect(editor.highlightText)searchbar.hide()defshowsearchbar():searchbar.show()searchbar.setFocus(Qt.OtherFocusReason)QShortcut(QKeySequence.Find,self,showsearchbar)self.layout().addWidget(searchbar)hbox=QHBoxLayout()hbox.setContentsMargins(2,2,2,2)self.layout().addLayout(hbox,1)self.chunklist=QListWidget(self)self.updating=Trueself.chunklist.currentRowChanged.connect(self.showChunk)hbox.addWidget(self.chunklist,1)bvbox=QVBoxLayout()bvbox.setContentsMargins(2,2,2,2)self.resolved=tb=QToolButton()tb.setIcon(qtlib.geticon('thg-success'))tb.setToolTip(_('Mark this chunk as resolved, goto next unresolved'))tb.pressed.connect(self.resolveCurrentChunk)self.unresolved=tb=QToolButton()tb.setIcon(qtlib.geticon('thg-warning'))tb.setToolTip(_('Mark this chunk as unresolved'))tb.pressed.connect(self.unresolveCurrentChunk)bvbox.addStretch(1)bvbox.addWidget(self.resolved,0)bvbox.addWidget(self.unresolved,0)bvbox.addStretch(1)hbox.addLayout(bvbox,0)self.editor=editorself.rejectbrowser=RejectBrowser(self)hbox.addWidget(self.rejectbrowser,5)BB=QDialogButtonBoxbb=QDialogButtonBox(BB.Save|BB.Cancel)bb.accepted.connect(self.accept)bb.rejected.connect(self.reject)self.layout().addWidget(bb)self.saveButton=bb.button(BB.Save)s=QSettings()self.restoreGeometry(s.value('rejects/geometry').toByteArray())self.editor.loadSettings(s,'rejects/editor')self.rejectbrowser.loadSettings(s,'rejects/rejbrowse')f=QFile(path) f.open(QIODevice.ReadOnly)
editor.read(f)
editor.setModified(False)
+ f.seek(0) lexer = lexers.get_lexer(path, f.readData(1024), self)
editor.setLexer(lexer)
editor.setMarginLineNumbers(1, True)
editor.setMarginWidth(1,str(editor.lines())+'X') buf = cStringIO.StringIO()
try:
buf.write('diff -r aaaaaaaaaaaa -r bbbbbbbbbbb %s\n' % path)
- buf.write(open(path + '.rej', 'r').read())
+ buf.write(open(path + '.rej', 'rb').read())
buf.seek(0)
except IOError, e:
pass
try:header=record.parsepatch(buf)[0]self.chunks=header.hunksexcept(patch.PatchError,IndexError),e:self.chunks=[]forchunkinself.chunks:chunk.resolved=Falseself.updateChunkList()self.saveButton.setDisabled(len(self.chunks))self.resolved.setDisabled(True)self.unresolved.setDisabled(True)QTimer.singleShot(0,lambda:self.chunklist.setCurrentRow(0))defmenuRequested(self,point):point=self.editor.mapToGlobal(point)returnself.editor.createStandardContextMenu().exec_(point)defupdateChunkList(self):self.updating=Trueself.chunklist.clear()forchunkinself.chunks:self.chunklist.addItem('@@ %d%s'%(chunk.fromline,chunk.resolvedand'(resolved)'or'(unresolved)'))self.updating=False@pyqtSlot()defresolveCurrentChunk(self):row=self.chunklist.currentRow()chunk=self.chunks[row]chunk.resolved=Trueself.updateChunkList()fori,chunkinenumerate(self.chunks):ifnotchunk.resolved:self.chunklist.setCurrentRow(i)returnelse:self.chunklist.setCurrentRow(row)self.saveButton.setEnabled(True)@pyqtSlot()defunresolveCurrentChunk(self):row=self.chunklist.currentRow()chunk=self.chunks[row]chunk.resolved=Falseself.updateChunkList()self.chunklist.setCurrentRow(row)self.saveButton.setEnabled(False)@pyqtSlot(int)defshowChunk(self,row):ifrow==-1orself.updating:return buf = cStringIO.StringIO()
chunk = self.chunks[row]
chunk.write(buf)
- self.rejectbrowser.showChunk(buf.getvalue().splitlines()[1:])
+ self.rejectbrowser.showChunk(buf.getvalue().splitlines(True)[1:])
self.editor.setCursorPosition(chunk.fromline-1, 0)
self.editor.ensureLineVisible(chunk.fromline-1)
self.editor.markerDeleteAll(-1)
self.editor.markerAdd(chunk.fromline-1,self.baseLineColor)self.resolved.setEnabled(notchunk.resolved)self.unresolved.setEnabled(chunk.resolved)defsaveSettings(self):s=QSettings()s.setValue('rejects/geometry',self.saveGeometry())self.editor.saveSettings(s,'rejects/editor')self.rejectbrowser.saveSettings(s,'rejects/rejbrowse')defaccept(self):# If the editor has been modified, we implicitly accept the changesacceptresolution=self.editor.isModified()ifnotacceptresolution:action=QMessageBox.warning(self,_("Warning"),_("You have marked all rejected patch chunks as resolved yet you " \
"have not modified the file on the edit panel.\n\n" \
"This probably means that no code from any of the rejected patch " \
"chunks made it into the file.\n\n"\
"Are you sure that you want to leave the file as is and " \
"consider all the rejected patch chunks as resolved?\n\n" \
"Doing so may delete them from a shelve, for example, which " \
"would mean that you would lose them forever!\n\n""Click Yes to accept the file as is or No to continue resolving " \
"the rejected patch chunks."),QMessageBox.Yes,QMessageBox.No)ifaction==QMessageBox.Yes:acceptresolution=Trueifacceptresolution:f=QFile(self.path)f.open(QIODevice.WriteOnly)self.editor.write(f)self.saveSettings()super(RejectsDialog,self).accept()defreject(self):self.saveSettings()super(RejectsDialog,self).reject()classRejectBrowser(qscilib.Scintilla):'Display a rejected diff hunk in an easily copy/pasted format'def__init__(self,parent):super(RejectBrowser,self).__init__(parent)self.setFrameStyle(0)self.setReadOnly(True)self.setUtf8(True)self.installEventFilter(qscilib.KeyPressInterceptor(self))self.setContextMenuPolicy(Qt.CustomContextMenu)self.customContextMenuRequested.connect(self.menuRequested)self.setCaretLineVisible(False)self.setMarginType(1,qsci.SymbolMargin)self.setMarginLineNumbers(1,False)self.setMarginWidth(1,QFontMetrics(self.font()).width('XX'))self.setMarginSensitivity(1,True)self.addedMark=self.markerDefine(qsci.Plus,-1)self.removedMark=self.markerDefine(qsci.Minus,-1)self.addedColor=self.markerDefine(qsci.Background,-1)self.removedColor=self.markerDefine(qsci.Background,-1)self.setMarkerBackgroundColor(QColor('lightgreen'),self.addedColor)self.setMarkerBackgroundColor(QColor('cyan'),self.removedColor)mask=(1<<self.addedMark)|(1<<self.removedMark)| \
(1<<self.addedColor)|(1<<self.removedColor)self.setMarginMarkerMask(1,mask)lexer=lexers.get_diff_lexer(self)self.setLexer(lexer)defmenuRequested(self,point):point=self.mapToGlobal(point)returnself.createStandardContextMenu().exec_(point)defshowChunk(self,lines):utext=[]added=[]removed=[]fori,lineinenumerate(lines):utext.append(hglib.tounicode(line[1:]))ifline[0]=='+':added.append(i) elif line[0] == '-':
removed.append(i)
self.markerDeleteAll(-1)
- self.setText(u'\n'.join(utext))
+ self.setText(u''.join(utext))
for i in added:
self.markerAdd(i, self.addedMark)
self.markerAdd(i, self.addedColor)
foriinremoved:self.markerAdd(i,self.removedMark)self.markerAdd(i,self.removedColor)defrun(ui,*pats,**opts):iflen(pats)!=1:qtlib.ErrorMsgBox(_('Filename required'),_('You must provide the path to a file'))importsys;sys.exit()path=pats[0]ifpath.endswith('.rej'):path=path[:-4]dlg=RejectsDialog(path,None)returndlg
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.