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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html| Peter Zijlstra | [RFC][PATCH 7/7] lockdep: spin_lock_nest_lock() |
| Gabriel C | Re: 2.6.24-rc2-mm1 |
| Andrew Morton | Re: [PATCH 2.6.21] cramfs: add cramfs Linear XIP |
| Jiri Kosina | Re: 2.6.21-rc5-mm4 |
git: | |
| Gregory Haskins | [RFC PATCH 00/17] virtual-bus |
| Jarek Poplawski | Re: [PATCH] pkt_sched: Destroy gen estimators under rtnl_lock(). |
| David Miller | [GIT]: Networking |
| Gerrit Renker | [PATCH 0/37] dccp: Feature negotiation - last call for comments |
