Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

repowidget: export diff between two revisions to a file (closes #281)

Changeset 06d4cb7ebe05

Parent 7e2087c85e6a

by Phil Currier

Changes to one file · Browse files at 06d4cb7ebe05 Showing diff from parent 7e2087c85e6a Diff from another changeset...

 
15
16
17
18
 
19
20
21
 
1153
1154
1155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1156
1157
1158
 
1204
1205
1206
 
 
1207
1208
 
1209
1210
1211
 
1212
1213
1214
1215
 
 
 
1216
1217
1218
 
1493
1494
1495
1496
 
1497
1498
1499
1500
1501
 
1502
1503
1504
1505
1506
1507
 
 
1508
1509
1510
 
1515
1516
1517
1518
 
 
 
 
1519
1520
1521
 
15
16
17
 
18
19
20
21
 
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
 
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
 
1519
1520
1521
 
1522
1523
1524
1525
1526
 
1527
1528
1529
1530
1531
1532
 
1533
1534
1535
1536
1537
 
1542
1543
1544
 
1545
1546
1547
1548
1549
1550
1551
@@ -15,7 +15,7 @@
   from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib -from tortoisehg.hgqt.qtlib import QuestionMsgBox, InfoMsgBox +from tortoisehg.hgqt.qtlib import QuestionMsgBox, InfoMsgBox, WarningMsgBox  from tortoisehg.hgqt.qtlib import DemandWidget  from tortoisehg.hgqt.repomodel import HgRepoListModel  from tortoisehg.hgqt import cmdui, update, tag, backout, merge, visdiff @@ -1153,6 +1153,25 @@
    def exportPair():   self.exportRevisions(self.menuselection) + def exportDiff(): + root = self.repo.root + filename = '%s_%d_to_%d.diff' % (os.path.basename(root), + self.menuselection[0], + self.menuselection[1]) + file = QFileDialog.getSaveFileName(self, _('Write diff file'), + hglib.tounicode(os.path.join(root, filename))) + if not file: + return + diff = self.copyPatch(returnval=True) + f = None + try: + f = open(file, "wb") + f.write(diff) + except Exception, e: + WarningMsgBox(_('Repository Error'), + _('Unable to write diff file')) + finally: + if f: f.close()   def exportDagRange():   l = dagrange()   if l: @@ -1204,15 +1223,22 @@
  menu = QMenu(self)   for name, cb, icon in (   (_('Visual Diff...'), diffPair, 'visualdiff'), + (_('Export Diff...'), exportDiff, 'hg-export'), + (None, None, None),   (_('Export Selected...'), exportPair, 'hg-export'),   (_('Email Selected...'), emailPair, 'mail-forward'), + (None, None, None),   (_('Export DAG Range...'), exportDagRange, 'hg-export'),   (_('Email DAG Range...'), emailDagRange, 'mail-forward'),   (_('Bundle DAG Range...'), bundleDagRange, 'menurelocate'), + (None, None, None),   (_('Bisect - Good, Bad...'), bisectNormal, 'hg-bisect-good-bad'),   (_('Bisect - Bad, Good...'), bisectReverse, 'hg-bisect-bad-good'),   (_('Compress History...'), compressDlg, 'hg-compress')   ): + if name is None: + menu.addSeparator() + continue   a = QAction(name, self)   if icon:   a.setIcon(qtlib.getmenuicon(icon)) @@ -1493,18 +1519,19 @@
  cmdline.append(hglib.fromunicode(file))   self.runCommand(cmdline)   - def copyPatch(self): + def copyPatch(self, returnval=False):   from mercurial import commands   _ui = self.repo.ui   _ui.pushbuffer()   try: - if self.rev: + if self.rev and len(self.menuselection) == 1:   class Writable(object):   def write(self, *args, **opts): _ui.write(*args, **opts)   def close(self): pass   commands.export(_ui, self.repo, self.rev, output=Writable())   else: - commands.diff(_ui, self.repo) + revs = self.rev and self.menuselection or None + commands.diff(_ui, self.repo, rev=revs)   except NameError:   raise   except Exception, e: @@ -1515,7 +1542,10 @@
  traceback.print_exc()   return   output = _ui.popbuffer() - QApplication.clipboard().setText(hglib.tounicode(output)) + if returnval: + return output + else: + QApplication.clipboard().setText(hglib.tounicode(output))     def copyHash(self):   clip = QApplication.clipboard()