# [PATCH 1/2] git-gui: move gitk launcher into a separate file

2 messages from 2009-05-02 to 2009-05-02. Participants: Markus Heidelberg.
Thread: https://gitlist.dev/t/19155

## Markus Heidelberg, 2009-05-02 09:20

Subject: [PATCH 1/2] git-gui: move gitk launcher into a separate file
Message-ID: <1241256054-14117-1-git-send-email-markus.heidelberg@web.de>
URL: https://gitlist.dev/e/1241256054-14117-1-git-send-email-markus.heidelberg%40web.de

```

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
 git-gui.sh   |   39 ---------------------------------------
 lib/gitk.tcl |   41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 39 deletions(-)
 create mode 100644 lib/gitk.tcl

diff --git a/git-gui.sh b/git-gui.sh
index 14b92ba..6ff04c4 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1902,45 +1902,6 @@ proc incr_font_size {font {amt 1}} {
 ##
 ## ui commands
 
-set starting_gitk_msg [mc "Starting gitk... please wait..."]
-
-proc do_gitk {revs} {
-	# -- Always start gitk through whatever we were loaded with.  This
-	#    lets us bypass using shell process on Windows systems.
-	#
-	set exe [_which gitk -script]
-	set cmd [list [info nameofexecutable] $exe]
-	if {$exe eq {}} {
-		error_popup [mc "Couldn't find gitk in PATH"]
-	} else {
-		global env
-
-		if {[info exists env(GIT_DIR)]} {
-			set old_GIT_DIR $env(GIT_DIR)
-		} else {
-			set old_GIT_DIR {}
-		}
-
-		set pwd [pwd]
-		cd [file dirname [gitdir]]
-		set env(GIT_DIR) [file tail [gitdir]]
-
-		eval exec $cmd $revs &
-
-		if {$old_GIT_DIR eq {}} {
-			unset env(GIT_DIR)
-		} else {
-			set env(GIT_DIR) $old_GIT_DIR
-		}
-		cd $pwd
-
-		ui_status $::starting_gitk_msg
-		after 10000 {
-			ui_ready $starting_gitk_msg
-		}
-	}
-}
-
 proc do_explore {} {
 	set explorer {}
 	if {[is_Cygwin] || [is_Windows]} {
diff --git a/lib/gitk.tcl b/lib/gitk.tcl
new file mode 100644
index 0000000..fcbb73d
--- /dev/null
+++ b/lib/gitk.tcl
@@ -0,0 +1,41 @@
+# git-gui gitk launcher
+# Copyright (C) 2006, 2007 Shawn Pearce
+
+set starting_gitk_msg [mc "Starting gitk... please wait..."]
+
+proc do_gitk {revs} {
+	# -- Always start gitk through whatever we were loaded with.  This
+	#    lets us bypass using shell process on Windows systems.
+	#
+	set exe [_which gitk -script]
+	set cmd [list [info nameofexecutable] $exe]
+	if {$exe eq {}} {
+		error_popup [mc "Couldn't find gitk in PATH"]
+	} else {
+		global env
+
+		if {[info exists env(GIT_DIR)]} {
+			set old_GIT_DIR $env(GIT_DIR)
+		} else {
+			set old_GIT_DIR {}
+		}
+
+		set pwd [pwd]
+		cd [file dirname [gitdir]]
+		set env(GIT_DIR) [file tail [gitdir]]
+
+		eval exec $cmd $revs &
+
+		if {$old_GIT_DIR eq {}} {
+			unset env(GIT_DIR)
+		} else {
+			set env(GIT_DIR) $old_GIT_DIR
+		}
+		cd $pwd
+
+		ui_status $::starting_gitk_msg
+		after 10000 {
+			ui_ready $starting_gitk_msg
+		}
+	}
+}
-- 
1.6.3.rc3.79.g777c

```

## Markus Heidelberg, 2009-05-02 09:20

Subject: [PATCH 2/2] git-gui: add menu item to select a branch to visualize with gitk
Message-ID: <1241256054-14117-2-git-send-email-markus.heidelberg@web.de>
URL: https://gitlist.dev/e/1241256054-14117-2-git-send-email-markus.heidelberg%40web.de
In-Reply-To: <1241256054-14117-1-git-send-email-markus.heidelberg@web.de>

```
Previously it was only possible to either visualize the history of the
current branch or of all branches. This new menu item "Visualize Branch
History..." is similar to the existing "Browse Branch Files..." item.

The gitk_open class was straight copied from the browser_open class with
merely adjusting the UI text and the command to execute.

Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
 git-gui.sh   |    3 +++
 lib/gitk.tcl |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index 6ff04c4..9ceaf6f 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2310,6 +2310,9 @@ set ui_browse_current [.mbar.repository index last]
 	-command {do_gitk $current_branch}
 set ui_visualize_current [.mbar.repository index last]
 .mbar.repository add command \
+	-label [mc "Visualize Branch History..."] \
+	-command gitk_open::dialog
+.mbar.repository add command \
 	-label [mc "Visualize All Branch History"] \
 	-command {do_gitk --all}
 .mbar.repository add separator
diff --git a/lib/gitk.tcl b/lib/gitk.tcl
index fcbb73d..251ab45 100644
--- a/lib/gitk.tcl
+++ b/lib/gitk.tcl
@@ -39,3 +39,56 @@ proc do_gitk {revs} {
 		}
 	}
 }
+
+class gitk_open {
+
+field w              ; # widget path
+field w_rev          ; # mega-widget to pick the initial revision
+
+constructor dialog {} {
+	make_toplevel top w
+	wm title $top [append "[appname] ([reponame]): " [mc "Visualize Branch History"]]
+	if {$top ne {.}} {
+		wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
+	}
+
+	label $w.header \
+		-text [mc "Visualize Branch History"] \
+		-font font_uibold
+	pack $w.header -side top -fill x
+
+	frame $w.buttons
+	button $w.buttons.browse -text [mc Visualize] \
+		-default active \
+		-command [cb _open]
+	pack $w.buttons.browse -side right
+	button $w.buttons.cancel -text [mc Cancel] \
+		-command [list destroy $w]
+	pack $w.buttons.cancel -side right -padx 5
+	pack $w.buttons -side bottom -fill x -pady 10 -padx 10
+
+	set w_rev [::choose_rev::new $w.rev [mc Revision]]
+	$w_rev bind_listbox <Double-Button-1> [cb _open]
+	pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
+
+	bind $w <Visibility> [cb _visible]
+	bind $w <Key-Escape> [list destroy $w]
+	bind $w <Key-Return> [cb _open]\;break
+	tkwait window $w
+}
+
+method _open {} {
+	if {[catch {$w_rev commit_or_die} err]} {
+		return
+	}
+	set name [$w_rev get]
+	destroy $w
+	do_gitk $name
+}
+
+method _visible {} {
+	grab $w
+	$w_rev focus_filter
+}
+
+}
-- 
1.6.3.rc3.79.g777c

```
