David Golub avatar David Golub committed 0d4be5a

repowidget: allow custom patch file name when exporting a single patch

Comments (0)

Files changed (1)

tortoisehg/hgqt/repowidget.py

     def exportRevisions(self, revisions):
         if not revisions:
             revisions = [self.rev]
-        udir = QFileDialog.getExistingDirectory(self, _('Export patch'),
-                                               hglib.tounicode(self.repo.root))
-        if not udir:
-            return
-        strdir = hglib.fromunicode(udir)
-        epath = os.path.join(strdir,
-                             hglib.fromunicode(self.repo.shortname)+'_%r.patch')
-
+        if len(revisions) == 1:
+            ret = QFileDialog.getSaveFileName(self, _('Export patch'),
+                                              hglib.tounicode(self.repo.root),
+                                              _('Patch Files (*.patch)'))
+            if not ret:
+                return
+            epath = str(ret)
+            strdir = os.path.dirname(epath)
+            udir = hglib.tounicode(strdir)
+            custompath = True
+        else:
+            udir = QFileDialog.getExistingDirectory(self, _('Export patch'),
+                                                   hglib.tounicode(self.repo.root))
+            if not udir:
+                return
+            strdir = hglib.fromunicode(udir)
+            epath = os.path.join(strdir,
+                                 hglib.fromunicode(self.repo.shortname)+'_%r.patch')
+            custompath = False
+            
         cmdline = ['export', '--repository', self.repo.root, '--verbose',
                    '--output', epath]
 
         existingRevisions = []
         for rev in revisions:
-            if os.path.exists(epath % rev):
-                if os.path.isfile(epath % rev):
+            if custompath:
+                path = epath
+            else:
+                path = epath % rev
+            if os.path.exists(path):
+                if os.path.isfile(path):
                     existingRevisions.append(rev)
                 else:
                     QMessageBox.warning(self,
             if buttonNames[res] == _("Replace"):
                 # Remove the existing patch files
                 for rev in existingRevisions:
-                    os.remove(epath % rev)
+                    if custompath:
+                        os.remove(epath)
+                    else:
+                        os.remove(epath % rev)
             elif buttonNames[res] == _("Abort"):
                 return
 
             # Show a message box with a link to the export folder and to the
             # exported file
             rev = revisions[0]
-            patchfilename = os.path.normpath(epath % rev)
-            patchdirname = os.path.normpath(strdir)
+            patchfilename = os.path.normpath(epath)
+            patchdirname = os.path.normpath(os.path.dirname(epath))
             patchshortname = os.path.basename(patchfilename)
             if patchdirname.endswith(os.path.sep):
                 patchdirname = patchdirname[:-1]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.