Kiln » TortoiseHg » TortoiseHg
Clone URL:  
rebase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# rebase.py - Rebase dialog for TortoiseHg # # 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. from PyQt4.QtCore import * from PyQt4.QtGui import * import os from mercurial import util, merge as mergemod from tortoisehg.util import hglib from tortoisehg.hgqt.i18n import _ from tortoisehg.hgqt import qtlib, csinfo, cmdui, resolve, commit, thgrepo BB = QDialogButtonBox class RebaseDialog(QDialog): showMessage = pyqtSignal(QString) def __init__(self, repo, parent, **opts): super(RebaseDialog, self).__init__(parent) self.setWindowIcon(qtlib.geticon('hg-rebase')) f = self.windowFlags() self.setWindowFlags(f & ~Qt.WindowContextHelpButtonHint) self.repo = repo self.opts = opts self.aborted = False box = QVBoxLayout() box.setSpacing(8) box.setContentsMargins(*(6,)*4) self.setLayout(box) style = csinfo.panelstyle(selectable=True) srcb = QGroupBox( _('Rebase changeset and descendants')) srcb.setLayout(QVBoxLayout()) srcb.layout().setContentsMargins(*(2,)*4) s = opts.get('source', '.') source = csinfo.create(self.repo, s, style, withupdate=True) srcb.layout().addWidget(source) self.layout().addWidget(srcb) destb = QGroupBox( _('To rebase destination')) destb.setLayout(QVBoxLayout()) destb.layout().setContentsMargins(*(2,)*4) d = opts.get('dest', '.') dest = csinfo.create(self.repo, d, style, withupdate=True) destb.layout().addWidget(dest) self.destcsinfo = dest self.layout().addWidget(destb) sep = qtlib.LabeledSeparator(_('Options')) self.layout().addWidget(sep) self.keepchk = QCheckBox(_('Keep original changesets')) self.keepchk.setChecked(opts.get('keep', False)) self.layout().addWidget(self.keepchk) self.keepbrancheschk = QCheckBox(_('Keep original branch names')) self.keepbrancheschk.setChecked(opts.get('keepbranches', False)) self.layout().addWidget(self.keepbrancheschk) self.detachchk = QCheckBox(_('Force detach of rebased changesets ' 'from their original branch')) self.detachchk.setChecked(opts.get('detach', True)) self.layout().addWidget(self.detachchk) self.autoresolvechk = QCheckBox(_('Automatically resolve merge conflicts ' 'where possible')) self.autoresolvechk.setChecked( repo.ui.configbool('tortoisehg', 'autoresolve', False)) self.layout().addWidget(self.autoresolvechk) if 'hgsubversion' in repo.extensions(): self.svnchk = QCheckBox(_('Rebase unpublished onto Subversion head ' '(override source, destination)')) self.layout().addWidget(self.svnchk) else: self.svnchk = None self.cmd = cmdui.Widget(True, True, self) self.cmd.commandFinished.connect(self.commandFinished) self.showMessage.connect(self.cmd.stbar.showMessage) self.cmd.stbar.linkActivated.connect(self.linkActivated) self.layout().addWidget(self.cmd, 2) bbox = QDialogButtonBox() self.cancelbtn = bbox.addButton(QDialogButtonBox.Cancel) self.cancelbtn.clicked.connect(self.reject) self.rebasebtn = bbox.addButton(_('Rebase'), QDialogButtonBox.ActionRole) self.rebasebtn.clicked.connect(self.rebase) self.abortbtn = bbox.addButton(_('Abort'), QDialogButtonBox.ActionRole) self.abortbtn.clicked.connect(self.abort) self.layout().addWidget(bbox) self.bbox = bbox if self.checkResolve() or not (s or d): for w in (srcb, destb, sep, self.keepchk, self.detachchk, self.keepbrancheschk): w.setHidden(True) self.cmd.setShowOutput(True) else: self.showMessage.emit(_('Checking...')) self.abortbtn.setEnabled(False) self.rebasebtn.setEnabled(False) QTimer.singleShot(0, self.checkStatus) self.setMinimumWidth(480) self.setMaximumHeight(800) self.resize(0, 340) self.setWindowTitle(_('Rebase - %s') % self.repo.displayname) def checkStatus(self): repo = self.repo class CheckThread(QThread): def __init__(self, parent): QThread.__init__(self, parent) self.dirty = False def run(self): wctx = repo[None] if len(wctx.parents()) > 1: self.dirty = True elif wctx.dirty(): self.dirty = True else: for r, p, status in thgrepo.recursiveMergeStatus(repo): if status == 'u': self.dirty = True break def completed(): self.th.wait() if self.th.dirty: self.rebasebtn.setEnabled(False) txt = _('Before rebase, you must <a href="commit">' '<b>commit</b></a> or <a href="discard">' '<b>discard</b></a> changes.') else: self.rebasebtn.setEnabled(True) txt = _('You may continue the rebase') self.showMessage.emit(txt) self.th = CheckThread(self) self.th.finished.connect(completed) self.th.start() def rebase(self): self.rebasebtn.setEnabled(False) self.cancelbtn.setShown(False) self.keepchk.setEnabled(False) self.keepbrancheschk.setEnabled(False) self.detachchk.setEnabled(False) cmdline = ['rebase', '--repository', self.repo.root] cmdline += ['--config', 'ui.merge=internal:' + (self.autoresolvechk.isChecked() and 'merge' or 'fail')] if os.path.exists(self.repo.join('rebasestate')): cmdline += ['--continue'] else: if self.keepchk.isChecked(): cmdline += ['--keep'] if self.keepbrancheschk.isChecked(): cmdline += ['--keepbranches'] if self.detachchk.isChecked(): cmdline += ['--detach'] if self.svnchk is not None and self.svnchk.isChecked(): cmdline += ['--svn'] else: source = self.opts.get('source') dest = self.opts.get('dest') cmdline += ['--source', str(source), '--dest', str(dest)] self.repo.incrementBusyCount() self.cmd.run(cmdline) def abort(self): cmdline = ['rebase', '--repository', self.repo.root, '--abort'] self.repo.incrementBusyCount() self.aborted = True self.cmd.run(cmdline) def commandFinished(self, ret): self.repo.decrementBusyCount() if self.checkResolve() is False: msg = _('Rebase is complete') if self.aborted: msg = _('Rebase aborted') self.showMessage.emit(msg) self.rebasebtn.setEnabled(True) self.rebasebtn.setText(_('Close')) self.rebasebtn.clicked.disconnect(self.rebase) self.rebasebtn.clicked.connect(self.accept) def checkResolve(self): for root, path, status in thgrepo.recursiveMergeStatus(self.repo): if status == 'u': txt = _('Rebase generated merge <b>conflicts</b> that must ' 'be <a href="resolve"><b>resolved</b></a>') self.rebasebtn.setEnabled(False) break else: self.rebasebtn.setEnabled(True) txt = _('You may continue the rebase') self.showMessage.emit(txt) if os.path.exists(self.repo.join('rebasestate')): self.abortbtn.setEnabled(True) self.rebasebtn.setText('Continue') return True else: self.abortbtn.setEnabled(False) return False def linkActivated(self, cmd): if cmd == 'resolve': dlg = resolve.ResolveDialog(self.repo, self) dlg.exec_() self.checkResolve() elif cmd == 'commit': dlg = commit.CommitDialog(self.repo, [], {}, self) dlg.finished.connect(dlg.deleteLater) dlg.exec_() self.destcsinfo.update(self.repo['.']) self.checkStatus() elif cmd == 'discard': labels = [(QMessageBox.Yes, _('&Discard')), (QMessageBox.No, _('Cancel'))] if not qtlib.QuestionMsgBox(_('Confirm Discard'), _('Discard outstanding changes to working directory?'), labels=labels, parent=self): return def finished(ret): self.repo.decrementBusyCount() if ret == 0: self.checkStatus() cmdline = ['update', '--clean', '--repository', self.repo.root, '--rev', '.'] self.runner = cmdui.Runner(True, self) self.runner.commandFinished.connect(finished) self.repo.incrementBusyCount() self.runner.run(cmdline) def reject(self): if os.path.exists(self.repo.join('rebasestate')): main = _('Exiting with an unfinished rebase is not recommended.') text = _('Consider aborting the rebase first.') labels = ((QMessageBox.Yes, _('&Exit')), (QMessageBox.No, _('Cancel'))) if not qtlib.QuestionMsgBox(_('Confirm Exit'), main, text, labels=labels, parent=self): return super(RebaseDialog, self).reject() def run(ui, *pats, **opts): from tortoisehg.util import paths repo = thgrepo.repository(ui, path=paths.find_root()) if os.path.exists(repo.join('rebasestate')): qtlib.InfoMsgBox(_('Rebase already in progress'), _('Resuming rebase already in progress')) elif not opts['source'] or not opts['dest']: qtlib.ErrorMsgBox(_('Abort'), _('You must provide source and dest arguments')) import sys; sys.exit() return RebaseDialog(repo, None, **opts)