Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

sync: introduce simple perfarce support

Changeset de6dc7634d6d

Parent c947c77a16b3

by Steve Borho

Changes to 2 files · Browse files at de6dc7634d6d Showing diff from parent c947c77a16b3 Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​p4pending.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,97 @@
+# p4pending.py - Display pending p4 changelists, created by perfarce extension +# +# 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. + +import os + +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +from mercurial import error + +from tortoisehg.util import hglib +from tortoisehg.hgqt.i18n import _ +from tortoisehg.hgqt import qtlib, cslist, cmdui + + +class PerforcePending(QDialog): + 'Dialog for selecting a revision' + def __init__(self, repo, pending, parent): + QDialog.__init__(self, parent) + self.repo = repo + self.pending = pending # dict of changelist -> hash tuple + + layout = QVBoxLayout() + self.setLayout(layout) + + clcombo = QComboBox() + layout.addWidget(clcombo) + + self.cslist = cslist.ChangesetList() + layout.addWidget(self.cslist) + + self.cmd = cmdui.Widget() + self.cmd.commandFinished.connect(self.commandFinished) + self.cmd.setVisible(False) + layout.addWidget(self.cmd) + + BB = QDialogButtonBox + bb = QDialogButtonBox(BB.Ok|BB.Cancel|BB.Discard) + bb.rejected.connect(self.reject) + bb.button(BB.Discard).setText('Revert') + bb.button(BB.Discard).setAutoDefault(False) + bb.button(BB.Discard).clicked.connect(self.revert) + bb.button(BB.Discard).setEnabled(False) + bb.button(BB.Ok).setText('Submit') + bb.button(BB.Ok).setAutoDefault(True) + bb.button(BB.Ok).clicked.connect(self.submit) + bb.button(BB.Ok).setEnabled(False) + layout.addWidget(bb) + self.bb = bb + + clcombo.activated[QString].connect(self.p4clActivated) + for changelist in self.pending: + clcombo.addItem(changelist) + + self.setWindowTitle(_('Pending Perforce Changelists - %s') % + repo.displayname) + + @pyqtSlot(QString) + def p4clActivated(self, curcl): + 'User has selected a changelist, fill cslist' + curcl = hglib.fromunicode(curcl) + try: + hashes = self.pending[curcl] + revs = [self.repo[hash] for hash in hashes] + except error.Abort, e: + revs = [] + self.cslist.clear() + self.cslist.update(self.repo, revs) + sensitive = not curcl.endswith('(submitted)') + self.bb.button(QDialogButtonBox.Ok).setEnabled(sensitive) + self.bb.button(QDialogButtonBox.Discard).setEnabled(sensitive) + self.curcl = curcl + + def submit(self): + assert(self.curcl.endswith('(pending)')) + cmdline = ['p4submit', '--verbose', self.curcl[:-10]] + self.repo.incrementBusyCount() + self.cmd.setVisible(True) + self.cmd.show_output(True) + self.cmd.run(cmdline) + + def revert(self): + assert(self.curcl.endswith('(pending)')) + cmdline = ['p4revert', '--verbose', self.curcl[:-10]] + self.repo.incrementBusyCount() + self.cmd.setVisible(True) + self.cmd.show_output(True) + self.cmd.run(cmdline) + + def commandFinished(self, wrapper): + self.repo.decrementBusyCount() + if wrapper.data == 0: + self.reject()
 
99
100
101
 
 
 
 
 
 
102
103
104
 
123
124
125
126
 
127
128
129
 
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
 
326
327
328
329
 
330
331
332
 
352
353
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
356
357
358
359
 
360
361
362
 
99
100
101
102
103
104
105
106
107
108
109
110
 
129
130
131
 
132
133
134
135
 
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
 
333
334
335
 
336
337
338
339
 
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
 
405
406
407
408
@@ -99,6 +99,12 @@
  hbox.addWidget(self.authbutton)   self.postpullbutton = QPushButton()   hbox.addWidget(self.postpullbutton) + if 'perfarce' in self.repo.extensions(): + self.p4pbutton = QPushButton(_('p4pending')) + self.p4pbutton.clicked.connect(self.p4pending) + hbox.addWidget(self.p4pbutton) + else: + self.p4pbutton = None   layout.addLayout(hbox)     self.tv.clicked.connect(self.pathSelected) @@ -123,7 +129,7 @@
    self.opbuttons = (self.inbutton, self.pullbutton,   self.outbutton, self.pushbutton, - self.emailbutton) + self.emailbutton, self.p4pbutton)     cmd = cmdui.Widget(not embedded, self)   cmd.commandStarted.connect(self.commandStarted) @@ -146,25 +152,26 @@
    def commandStarted(self):   for b in self.opbuttons: - b.setEnabled(False) + if b: b.setEnabled(False)   if not self.embedded:   self.cmd.show_output(True)   self.cmd.setVisible(True)     def commandFinished(self, wrapper):   for b in self.opbuttons: - b.setEnabled(True) + if b: b.setEnabled(True)   if self.finishfunc:   output = self.cmd.get_rawoutput()   if wrapper.data is None:   # An exception ocurred, command did not finish   self.finishfunc(-1, output) + self.makeLogVisible.emit(True)   else:   self.finishfunc(wrapper.data, output)     def commandCanceled(self):   for b in self.opbuttons: - b.setEnabled(True) + if b: b.setEnabled(True)     def configChanged(self):   'Repository is reporting its config files have changed' @@ -326,7 +333,7 @@
  def finished(ret, output):   self.showMessage.emit(_('Pull finished, ret %d') % ret)   self.finishfunc = finished - cmdline = ['--repository', self.root, 'pull'] + cmdline = ['--repository', self.root, 'pull', '--verbose']   if self.cachedpp == 'rebase':   cmdline.append('--rebase')   elif self.cachedpp == 'update': @@ -352,11 +359,50 @@
  self.finishfunc = None   self.run(['--repository', self.root, 'outgoing'])   + def p4pending(self): + def finished(ret, output): + pending = {} + if ret == 0: + for line in output.splitlines(): + try: + hashes = line.split(' ') + changelist = hashes.pop(0) + if len(hashes)>1 and len(hashes[0])==1: + state = hashes.pop(0) + if state == 's': + changelist = _('%s (submitted)') % changelist + elif state == 'p': + changelist = _('%s (pending)') % changelist + else: + if changelist == 'submitted': + changelist = _('Submitted') + str(submitted) + submitted += 1 + else: + changelist = _('%s (pending)') % changelist + pending[changelist] = hashes + except (ValueError, IndexError): + text = _('Unable to parse p4pending output') + if pending: + text = _('%d pending changelists found') % len(pending) + else: + text = _('No pending Perforce changelists') + elif ret is None: + text = _('Aborted p4pending') + else: + text = _('Unable to determine pending changesets') + self.showMessage.emit(text) + if pending: + from tortoisehg.hgqt.p4pending import PerforcePending + dlg = PerforcePending(self.repo, pending, self) + dlg.exec_() + self.finishfunc = finished + self.run(['--repository', self.root, 'p4pending', '--verbose']) +   def pushclicked(self):   def finished(ret, output):   self.showMessage.emit(_('Push finished, ret %d') % ret)   self.finishfunc = finished - self.run(['--repository', self.root, 'push']) + self.run(['--repository', self.root, 'push', '--verbose'])     def postpullclicked(self):   dlg = PostPullDialog(self.repo, self)