diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index e06ff65ee..6c19b7b7f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -714,26 +714,27 @@ public int compare(PackExt o1, PackExt o2) { JGitText.get().cannotCreateIndexfile, tmpIdx.getPath())); // write the packfile - @SuppressWarnings("resource" /* java 7 */) - FileChannel channel = new FileOutputStream(tmpPack).getChannel(); + FileOutputStream fos = new FileOutputStream(tmpPack); + FileChannel channel = fos.getChannel(); OutputStream channelStream = Channels.newOutputStream(channel); try { pw.writePack(pm, pm, channelStream); } finally { channel.force(true); channelStream.close(); - channel.close(); + fos.close(); } // write the packindex - FileChannel idxChannel = new FileOutputStream(tmpIdx).getChannel(); + fos = new FileOutputStream(tmpIdx); + FileChannel idxChannel = fos.getChannel(); OutputStream idxStream = Channels.newOutputStream(idxChannel); try { pw.writeIndex(idxStream); } finally { idxChannel.force(true); idxStream.close(); - idxChannel.close(); + fos.close(); } if (pw.prepareBitmapIndex(pm)) { @@ -745,14 +746,15 @@ public int compare(PackExt o1, PackExt o2) { JGitText.get().cannotCreateIndexfile, tmpBitmapIdx.getPath())); - idxChannel = new FileOutputStream(tmpBitmapIdx).getChannel(); + fos = new FileOutputStream(tmpBitmapIdx); + idxChannel = fos.getChannel(); idxStream = Channels.newOutputStream(idxChannel); try { pw.writeBitmapIndex(idxStream); } finally { idxChannel.force(true); idxStream.close(); - idxChannel.close(); + fos.close(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/DefaultNoteMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/DefaultNoteMerger.java index 9624e49e9..db4944851 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/DefaultNoteMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/DefaultNoteMerger.java @@ -82,8 +82,12 @@ public Note merge(Note base, Note ours, Note theirs, ObjectReader reader, ObjectLoader lt = reader.open(theirs.getData()); UnionInputStream union = new UnionInputStream(lo.openStream(), lt.openStream()); - ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, - lo.getSize() + lt.getSize(), union); - return new Note(ours, noteData); + try { + ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, + lo.getSize() + lt.getSize(), union); + return new Note(ours, noteData); + } finally { + union.close(); + } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java index d70148861..36d429a02 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java @@ -148,6 +148,9 @@ private Session createSession(CredentialsProvider credentialsProvider, FS fs, String user, final String pass, String host, int port, final OpenSshConfig.Host hc) throws JSchException { final Session session = createSession(hc, user, host, port, fs); + // We retry already in getSession() method. JSch must not retry + // on its own. + session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$ if (pass != null) session.setPassword(pass); final String strictHostKeyCheckingPolicy = hc diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index fe55e2377..5885e7b52 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -471,12 +471,14 @@ private HttpConnection connect(final String service) if (authMethod == HttpAuthMethod.NONE) throw new TransportException(uri, MessageFormat.format( JGitText.get().authenticationNotSupported, uri)); - if (1 < authAttempts - || !authMethod.authorize(uri, - getCredentialsProvider())) { + CredentialsProvider credentialsProvider = getCredentialsProvider(); + if (3 < authAttempts + || !authMethod.authorize(uri, credentialsProvider)) { + credentialsProvider.reset(uri); throw new TransportException(uri, JGitText.get().notAuthorized); } + credentialsProvider.reset(uri); authAttempts++; continue; @@ -504,7 +506,7 @@ final HttpConnection httpOpen(URL u) throws IOException { /** * Open an HTTP connection. - * + * * @param method * @param u * @return the connection