git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [EGIT PATCH 1/2] Refactor SSH key loading so we don't duplicate keys
@ 2008-08-15 17:35 Shawn O. Pearce
  2008-08-15 17:35 ` [EGIT PATCH 2/2] Honor ~/.ssh/config whenever possible during SSH based transport Shawn O. Pearce
  0 siblings, 1 reply; 4+ messages in thread
From: Shawn O. Pearce @ 2008-08-15 17:35 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git

We only want to read each private key once, so we cache the
names of the keys we have processed before, adding keys which
we have not yet seen.  This allows us to alter add keys on
the fly and avoid duplication.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../jgit/transport/DefaultSshSessionFactory.java   |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
index b4578d4..0484fc0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
@@ -78,6 +78,8 @@
 	/** IANA assigned port number for SSH. */
 	private static final int SSH_PORT = 22;
 
+	private Set<String> loadedIdentities;
+
 	private JSch userJSch;
 
 	@Override
@@ -106,10 +108,10 @@ public String run() {
 
 	private JSch getUserJSch() throws JSchException {
 		if (userJSch == null) {
-			final JSch sch = new JSch();
-			knownHosts(sch);
-			identities(sch);
-			userJSch = sch;
+			loadedIdentities = new HashSet<String>();
+			userJSch = new JSch();
+			knownHosts(userJSch);
+			identities();
 		}
 		return userJSch;
 	}
@@ -133,7 +135,7 @@ private void knownHosts(final JSch sch) throws JSchException {
 		}
 	}
 
-	private void identities(final JSch sch) throws JSchException {
+	private void identities() throws JSchException {
 		final File home = FS.userHome();
 		if (home == null)
 			return;
@@ -149,10 +151,16 @@ private void identities(final JSch sch) throws JSchException {
 			final File k = new File(sshdir, n.substring(0, n.length() - 4));
 			if (!k.isFile())
 				continue;
-			sch.addIdentity(k.getAbsolutePath());
+			addIdentity(k);
 		}
 	}
 
+	private void addIdentity(final File identityFile) throws JSchException {
+		final String path = identityFile.getAbsolutePath();
+		if (loadedIdentities.add(path))
+			userJSch.addIdentity(path);
+	}
+
 	private static class AWT_UserInfo implements UserInfo,
 			UIKeyboardInteractive {
 		private String passwd;
-- 
1.6.0.rc3.250.g8dd0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-08-20 20:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-15 17:35 [EGIT PATCH 1/2] Refactor SSH key loading so we don't duplicate keys Shawn O. Pearce
2008-08-15 17:35 ` [EGIT PATCH 2/2] Honor ~/.ssh/config whenever possible during SSH based transport Shawn O. Pearce
2008-08-20 20:34   ` Robin Rosenberg
2008-08-20 20:38     ` Shawn O. Pearce

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).