diff options
| author | Junio C Hamano <gitster@pobox.com> | 2008-11-01 22:31:46 -0700 | 
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2008-11-01 22:31:46 -0700 | 
| commit | f6576f4c0c6fa3b2d979faf28936c09480dedaab (patch) | |
| tree | 26bb4d7d46d6e67a050eaa467e88e1a251ee309a /git-gui/lib/sshkey.tcl | |
| parent | 933bb3ae5e6c83288ec7c80c2282984f4927cb48 (diff) | |
| parent | 9d83c6aa44d2ff68111865b6f72e7321e54a8972 (diff) | |
| download | git-f6576f4c0c6fa3b2d979faf28936c09480dedaab.tar.gz | |
Merge git://repo.or.cz/git-gui
* git://repo.or.cz/git-gui: (27 commits)
  git-gui: Update German translation.
  git-gui: Do not munge conflict marker lines in a normal diff
  git-gui: Add a simple implementation of SSH_ASKPASS.
  git-gui: Add a dialog that shows the OpenSSH public key.
  git-gui: Mark-up strings in show_{other,unmerged}_diff() for localization
  git-gui: Show a round number of bytes of large untracked text files
  git-gui: Fix the blame viewer destroy handler.
  git-gui: Add a search command to the blame viewer.
  git-gui: Fix the blame window shape.
  git-gui: Fix switch statement in lib/merge.tcl
  git-gui: Fix fetching from remotes when adding them
  git-gui: Fix removing non-pushable remotes
  git-gui: Make input boxes in init/clone/open dialogs consistent
  git-gui: Avoid using the term URL when specifying repositories
  git-gui: gui.autoexplore makes explorer to pop up automatically after picking
  git-gui: Add Explore Working Copy to the Repository menu
  git-gui: Use git web--browser for web browsing
  git-gui: mkdir -p when initializing new remote repository
  git-gui: Add support for removing remotes
  git-gui: Add support for adding remotes
  ...
Diffstat (limited to 'git-gui/lib/sshkey.tcl')
| -rw-r--r-- | git-gui/lib/sshkey.tcl | 126 | 
1 files changed, 126 insertions, 0 deletions
diff --git a/git-gui/lib/sshkey.tcl b/git-gui/lib/sshkey.tcl new file mode 100644 index 0000000000..82a1a80ff4 --- /dev/null +++ b/git-gui/lib/sshkey.tcl @@ -0,0 +1,126 @@ +# git-gui about git-gui dialog +# Copyright (C) 2006, 2007 Shawn Pearce + +proc find_ssh_key {} { +	foreach name {~/.ssh/id_dsa.pub ~/.ssh/id_rsa.pub ~/.ssh/identity.pub} { +		if {[file exists $name]} { +			set fh    [open $name r] +			set cont  [read $fh] +			close $fh +			return [list $name $cont] +		} +	} + +	return {} +} + +proc do_ssh_key {} { +	global sshkey_title have_tk85 sshkey_fd + +	set w .sshkey_dialog +	if {[winfo exists $w]} { +		raise $w +		return +	} + +	toplevel $w +	wm transient $w . + +	set finfo [find_ssh_key] +	if {$finfo eq {}} { +		set sshkey_title [mc "No keys found."] +		set gen_state   normal +	} else { +		set sshkey_title [mc "Found a public key in: %s" [lindex $finfo 0]] +		set gen_state   disabled +	} + +	frame $w.header -relief flat +	label $w.header.lbl -textvariable sshkey_title -anchor w +	button $w.header.gen -text [mc "Generate Key"] \ +		-command [list make_ssh_key $w] -state $gen_state +	pack $w.header.lbl -side left -expand 1 -fill x +	pack $w.header.gen -side right +	pack $w.header -fill x -pady 5 -padx 5 + +	text $w.contents -width 60 -height 10 -wrap char -relief sunken +	pack $w.contents -fill both -expand 1 +	if {$have_tk85} { +		$w.contents configure -inactiveselectbackground darkblue +	} + +	frame $w.buttons +	button $w.buttons.close -text [mc Close] \ +		-default active -command [list destroy $w] +	pack $w.buttons.close -side right +	button $w.buttons.copy -text [mc "Copy To Clipboard"] \ +		-command [list tk_textCopy $w.contents] +	pack $w.buttons.copy -side left +	pack $w.buttons -side bottom -fill x -pady 5 -padx 5 + +	if {$finfo ne {}} { +		$w.contents insert end [lindex $finfo 1] sel +	} +	$w.contents configure -state disabled + +	bind $w <Visibility> "grab $w; focus $w.buttons.close" +	bind $w <Key-Escape> "destroy $w" +	bind $w <Key-Return> "destroy $w" +	bind $w <Destroy> kill_sshkey +	wm title $w [mc "Your OpenSSH Public Key"] +	tk::PlaceWindow $w widget . +	tkwait window $w +} + +proc make_ssh_key {w} { +	global sshkey_title sshkey_output sshkey_fd + +	set sshkey_title [mc "Generating..."] +	$w.header.gen configure -state disabled + +	set cmdline [list sh -c {echo | ssh-keygen -q -t rsa -f ~/.ssh/id_rsa 2>&1}] + +	if {[catch { set sshkey_fd [_open_stdout_stderr $cmdline] } err]} { +		error_popup [mc "Could not start ssh-keygen:\n\n%s" $err] +		return +	} + +	set sshkey_output {} +	fconfigure $sshkey_fd -blocking 0 +	fileevent $sshkey_fd readable [list read_sshkey_output $sshkey_fd $w] +} + +proc kill_sshkey {} { +	global sshkey_fd +	if {![info exists sshkey_fd]} return +	catch { kill_file_process $sshkey_fd } +	catch { close $sshkey_fd } +} + +proc read_sshkey_output {fd w} { +	global sshkey_fd sshkey_output sshkey_title + +	set sshkey_output "$sshkey_output[read $fd]" +	if {![eof $fd]} return + +	fconfigure $fd -blocking 1 +	unset sshkey_fd + +	$w.contents configure -state normal +	if {[catch {close $fd} err]} { +		set sshkey_title [mc "Generation failed."] +		$w.contents insert end $err +		$w.contents insert end "\n" +		$w.contents insert end $sshkey_output +	} else { +		set finfo [find_ssh_key] +		if {$finfo eq {}} { +			set sshkey_title [mc "Generation succeded, but no keys found."] +			$w.contents insert end $sshkey_output +		} else { +			set sshkey_title [mc "Your key is in: %s" [lindex $finfo 0]] +			$w.contents insert end [lindex $finfo 1] sel +		} +	} +	$w.contents configure -state disable +}  | 
