Steve Borho committed 51c8bfc

hggtk/changeset: add 'save at revision' option

* hg cat only works on revisions that include modifications to the
file, so I expanded the check for annotation to include this feature
* Checking for revlog.LookupError() also catches revisions where the
file has been deleted (removed from the manifest but not changed otherwise)
* This was added as the second item in the context menu to avoid making it
the default action when a row is activated in the file list.

Comments (0)

Files changed (1)


 from mercurial.i18n import _
 from mercurial.node import *
-from mercurial import cmdutil, util, ui, hg, commands, patch
+from mercurial import cmdutil, util, ui, hg, commands, patch, revlog
 from gdialog import *
 from hgcmd import CmdDialog
         _menu = gtk.Menu()
         _menu.append(create_menu('_view at revision', self._view_file_rev))
+        self._save_menu = create_menu('_save at revision', self._save_file_rev)
+        _menu.append(self._save_menu)
         _menu.append(create_menu('_file history', self._file_history))
         self._ann_menu = create_menu('_annotate file', self._ann_file)
         # cannot be annotated at this revision (since this changeset
         # does not appear in the filelog)
         ctx = self.repo.changectx(self.currev)
-        fctx = ctx.filectx(self.curfile)
-        can_annotate = fctx.filelog().linkrev(fctx.filenode()) == ctx.rev()
-        self._ann_menu.set_sensitive(can_annotate)
+        try:
+            fctx = ctx.filectx(self.curfile)
+            has_filelog = fctx.filelog().linkrev(fctx.filenode()) == ctx.rev()
+        except revlog.LookupError:
+            has_filelog = False
+        self._ann_menu.set_sensitive(has_filelog)
+        self._save_menu.set_sensitive(has_filelog)
         return True
     def _file_row_act(self, tree, path, column) :
         return True
+    def _save_file_rev(self, menuitem):
+        file, ext = os.path.splitext(os.path.basename(self.curfile))
+        filename = "%s@%d%s" % (file, self.currev, ext)
+        fd = NativeSaveFileDialogWrapper(Title = "Save file to",
+                                         InitialDir=self.cwd,
+                                         FileName=filename)
+        result =
+        if result:
+            import Queue
+            import hglib
+            q = Queue.Queue()
+            cpath = util.canonpath(self.repo.root, self.cwd, self.curfile)
+            hglib.hgcmd_toq(self.repo.root, q, 'cat', '--rev',
+                str(self.currev), '--output', result, cpath)
     def _view_file_rev(self, menuitem):
         '''User selected view file revision from the file list context menu'''
-        # TODO
         rev = self.currev
         parents = self.parents
         if len(parents) == 0:
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
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.