git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitk: Add a "Save file as" menu item

From
AAAndreas Amann <a.amann@ucc.ie>
Date
Jul 21, 2013, 12:38 UTC
Message-ID
<87ppuculyi.fsf@msstf091.ucc.ie>

Previously, there was no easy way to save a particular file from the currently selected revision.

This patch adds a menu item "Save file as" to the file list popup menu, which opens a file selection dialog to determine the name under which a file should be saved. The default filename is of the form "[shortid] basename". If the current revision is the index, the default pattern is of the form "[index] basename". This works for both, the "Patch" and "Tree" view. The menu item is disabled for the "local uncommitted changes" fake revision.

Signed-off-by: Andreas Amann <andreas.amann@web.de>
---
 gitk | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff --git a/gitk b/gitk
index 5cd00d8..dbedaf6 100755
--- a/gitk
+++ b/gitk
@@ -2595,6 +2595,7 @@ proc makewindow {} {
 	{mc "Highlight this too" command {flist_hl 0}}
 	{mc "Highlight this only" command {flist_hl 1}}
 	{mc "External diff" command {external_diff}}
+	{mc "Save file as" command {save_file_as}}
 	{mc "Blame parent commit" command {external_blame 1}}
     }
     $flist_menu configure -tearoff 0
@@ -3378,6 +3379,7 @@ proc sel_flist {w x y} {
 proc pop_flist_menu {w X Y x y} {
     global ctext cflist cmitmode flist_menu flist_menu_file
     global treediffs diffids
+    global nullid
 
     stopfinding
     set l [lindex [split [$w index "@$x,$y"] "."] 0]
@@ -3395,6 +3397,12 @@ proc pop_flist_menu {w X Y x y} {
     }
     # Disable "External diff" item in tree mode
     $flist_menu entryconf 2 -state $xdiffstate
+    set savefilestate "normal"
+    if {[lindex $diffids 0] eq $nullid} {
+	set savefilestate "disabled"
+    }
+    # Disable "Save file as" item for worktree
+    $flist_menu entryconf 3 -state $savefilestate
     tk_popup $flist_menu $X $Y
 }
 
@@ -3496,6 +3504,28 @@ proc external_diff_get_one_file {diffid filename diffdir} {
 	       "revision $diffid"]
 }
 
+proc save_file_as {} {
+    global nullid nullid2
+    global flist_menu_file
+    global diffids
+
+    set diffid [lindex $diffids 0]
+    if {$diffid == $nullid} {
+	return
+    } elseif {$diffid == $nullid2} {
+	set diffidtext "\[index\]"
+	set diffid ""
+    } else {
+	set diffidtext "\[[shortids $diffid]\]"
+    }
+    set difffile "$diffidtext [file tail $flist_menu_file]"
+    set difffile [tk_getSaveFile -initialfile $difffile -title "Save file as" -parent .]
+    if {$difffile eq {}} {
+	return
+    }
+    save_file_from_commit $diffid:$flist_menu_file $difffile "revision $diffid"
+}
+
 proc external_diff {} {
     global nullid nullid2
     global flist_menu_file
-- 
1.8.3.1
Next: Peter Krefting
Message 1 of 5 in “gitk: Add a "Save file as" menu item”
  1. gitk: Add a "Save file as" menu itemAndreas Amann, Jul 21, 2013
  2. Peter KreftingJul 21, 2013
  3. Andreas AmannJul 21, 2013
  4. gitk: Add a "Save file as" menu itemAndreas Amann, Jul 21, 2013
  5. gitk: Add a "Save file as" menu itemAndreas Amann, Jul 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.