o $top}
}

proc incr_font_size {font {amt 1}} {
	set sz [font configure $font -size]
	incr sz $amt
	font configure $font -size $sz
	font configure ${font}bold -size $sz
	font configure ${font}italic -size $sz
}

######################################################################
##
## ui commands

set starting_gitk_msg [mc "Starting gitk... please wait..."]

proc do_gitk {revs {is_submodule false}} {
	global current_diff_path file_states current_diff_side ui_index
	global _gitworktree

	# -- 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]

		if {!$is_submodule} {
			if {![is_bare]} {
				cd $_gitworktree
			}
			set env(GIT_DIR) [file normalize [gitdir]]
		} else {
			cd $current_diff_path
			if {$revs eq {--}} {
				set s $file_states($current_diff_path)
				set old_sha1 {}
				set new_sha1 {}
				switch -glob -- [lindex $s 0] {
				M_ { set old_sha1 [lindex [lindex $s 2] 1] }
				_M { set old_sha1 [lindex [lindex $s 3] 1] }
				MM {
					if {$current_diff_side eq $ui_index} {
						set old_sha1 [lindex [lindex $s 2] 1]
						set new_sha1 [lindex [lindex $s 3] 1]
					} else {
						set old_sha1 [lindex [lindex $s 3] 1]
					}
				}
				}
				set revs $old_sha1...$new_sha1
			}
			if {[info exists env(GIT_DIR)]} {
				unset env(GIT_DIR)
			}
		}
		eval exec $cmd $revs "--" "--" &

		if {$old_GIT_DIR ne {}} {
			set env(GIT_DIR) $old_GIT_DIR
		}
		cd $pwd

		ui_status $::starting_gitk_msg
		after 10000 {
			ui_ready $starting_gitk_msg
		}
	}
}

proc do_git_gui {} {
	global current_diff_path

	# -- Always start git gui through whatever we were loaded with.  This
	#    lets us bypass using shell process on Windows systems.
	#
	set exe [list [_which git]]
	if {$exe eq {}} {
		error_popup [mc "Couldn't find git gui in PATH"]
	} else {
		global env

		if {[info exists env(GIT_DIR)]} {
			set old_GIT_DIR $env(GIT_DIR)
			unset env(GIT_DIR)
		} else {
			set old_GIT_DIR {}
		}

		set pwd [pwd]
		cd $current_diff_path

		eval exec $exe gui &

		if {$old_GIT_DIR ne {}} {
			set env(GIT_DIR) $old_GIT_DIR
		}
		cd $pwd

		ui_status $::starting_gitk_msg
		after 10000 {
			ui_ready $starting_gitk_msg
		}
	}
}

proc do_explore {} {
	global _gitworktree
	set explorer {}
	if {[is_Cygwin] || [is_Windows]} {
		set explorer "explorer.exe"
	} elseif {[is_MacOSX]} {
		set explorer "open"
	} else {
		# freedesktop.org-conforming system is our best shot
		set explorer "xdg-open"
	}
	eval exec $explorer [list [file nativename $_gitworktree]] &
}

set is_quitting 0
set ret_code    1

proc terminate_me {win} {
	global ret_code
	if {$win ne {.}} return
	exit $ret_code
}

proc do_quit {{rc {1}}} {
	global ui_comm is_quitting repo_config commit_type
	global GITGUI_BCK_exists GITGUI