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

[PATCH v2] gitk: add menuitem for file checkout from this or parent commit

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Sep 30, 2010, 18:29 UTC
Message-ID
<20100930182949.GA15412@book.hvoigt.net>
In-Reply-To
<AANLkTinn-_Npv4+wGRkS6Sonf1VRV-cEMtHBEtyQeq8O@mail.gmail.com>

This is useful if a user wants to checkout a file from a certain commit. This is equivalent to

  git checkout $commit $file
Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
On Wed, Sep 29, 2010 at 03:48:03PM +0000, Ævar Arnfjörð Bjarmason wrote:
> But as Michele points out you probably shouldn't update these, some
> projects do, but it probably makes more sense to leave these updates
> up to translators.
Here is an updated version of that patch without the po changes.
 gitk |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/gitk b/gitk
index 45e3380..c582bb5 100755
--- a/gitk
+++ b/gitk
@@ -2497,6 +2497,8 @@ proc makewindow {} {
 	{mc "Highlight this only" command {flist_hl 1}}
 	{mc "External diff" command {external_diff}}
 	{mc "Blame parent commit" command {external_blame 1}}
+	{mc "Checkout from this commit" command {external_checkout}}
+	{mc "Checkout from parent commit" command {external_checkout 1}}
     }
     $flist_menu configure -tearoff 0
 
@@ -3533,6 +3535,20 @@ proc make_relative {f} {
 }
 
 proc external_blame {parent_idx {line {}}} {
+
+    set cmdline [list git gui blame]
+    if {$line ne {} && $line > 1} {
+	lappend cmdline "--line=$line"
+    }
+    run_command_on_selected_file $cmdline $parent_idx
+}
+
+proc external_checkout {{parent_idx 0}} {
+    set cmdline [list git checkout]
+    run_command_on_selected_file $cmdline $parent_idx
+}
+
+proc run_command_on_selected_file {cmdline parent_idx} {
     global flist_menu_file gitdir
     global nullid nullid2
     global parentlist selectedline currentid
@@ -3548,17 +3564,13 @@ proc external_blame {parent_idx {line {}}} {
 	return
     }
 
-    set cmdline [list git gui blame]
-    if {$line ne {} && $line > 1} {
-	lappend cmdline "--line=$line"
-    }
     set f [file join [file dirname $gitdir] $flist_menu_file]
-    # Unfortunately it seems git gui blame doesn't like
+    # Unfortunately some commands do not like
     # being given an absolute path...
     set f [make_relative $f]
     lappend cmdline $base_commit $f
     if {[catch {eval exec $cmdline &} err]} {
-	error_popup "[mc "git gui blame: command failed:"] $err"
+	error_popup "[mc "$cmdline: command failed:"] $err"
     }
 }
 
-- 
1.7.2.2.177.geec0d
Previous: Ævar Arnfjörð BjarmasonNext: Michele Ballabio
Message 5 of 8 in “gitk: add menuitem for file checkout from selected or parent commit”
  1. gitk: add menuitem for file checkout from selected or parent commitHeiko Voigt, Sep 28, 2010
  2. Ævar Arnfjörð BjarmasonSep 28, 2010
  3. Heiko VoigtSep 29, 2010
  4. Ævar Arnfjörð BjarmasonSep 29, 2010
  5. gitk: add menuitem for file checkout from this or parent commitHeiko Voigt, Sep 30, 2010
  6. Michele BallabioSep 29, 2010
  7. Paul MackerrasDec 11, 2010
  8. gitk: add menuitem for file checkout from this or parent commithvoigt, Dec 13, 2010

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.