Commits

Yuya Nishihara committed 47fadf1 Draft

filectxactions: run "hg cat" by asynchronous command runner

Benefits:
- it can show command outputs in log widget
- dirty chdir hack is no longer necessary

Comments (0)

Files changed (1)

tortoisehg/hgqt/filectxactions.py

 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 
-from mercurial import commands, util
-
 from tortoisehg.hgqt import cmdcore, cmdui, qtlib, revert, visdiff
 from tortoisehg.hgqt import filedata
 from tortoisehg.hgqt.i18n import _
     @actionSlot(_('&Save at Revision...'), None, 'Shift+Ctrl+S',
                 _('Save file as it appeared at this revision'))
     def saveFile(self):
-        if self._curfd.isNull():
-            return
-        repo = self._fdRepoAgent().rawRepo()
-
+        cmdlines = []
         for fd in self._selfds:
             wfile = hglib.fromunicode(fd.absoluteFilePath())
             wfile, ext = os.path.splitext(os.path.basename(wfile))
                 ";;".join(extfilter))
             if not result:
                 continue
-            cwd = os.getcwd()
-            try:
-                os.chdir(repo.root)
-                try:
-                    curfile = hglib.fromunicode(fd.canonicalFilePath())
-                    commands.cat(repo.ui, repo, curfile, rev=fd.rev(),
-                                 output=hglib.fromunicode(result))
-                except (util.Abort, IOError), e:
-                    QMessageBox.critical(self.parent(),
-                                         _('Unable to save file'),
-                                         hglib.tounicode(str(e)))
-            finally:
-                os.chdir(cwd)
+            cmdlines.append(hglib.buildcmdargs(
+                'cat', fd.canonicalFilePath(), rev=fd.rev(), output=result))
+
+        if cmdlines:
+            self._runCommandSequence(cmdlines)
 
     @actionSlot(_('&Edit Local'), 'edit-file', None,
                 _('Edit current file in working copy'))