diff --git a/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleCredentialsProvider.java b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleCredentialsProvider.java index 91034fd2c..a01fd86b4 100644 --- a/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleCredentialsProvider.java +++ b/org.eclipse.jgit.console/src/org/eclipse/jgit/console/ConsoleCredentialsProvider.java @@ -48,8 +48,10 @@ package org.eclipse.jgit.console; import java.io.Console; import org.eclipse.jgit.errors.UnsupportedCredentialItem; +import org.eclipse.jgit.transport.ChainingCredentialsProvider; import org.eclipse.jgit.transport.CredentialItem; import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.NetRCCredentialsProvider; import org.eclipse.jgit.transport.URIish; /** Interacts with the user during authentication by using the text console. */ @@ -60,7 +62,9 @@ public class ConsoleCredentialsProvider extends CredentialsProvider { if (c.cons == null) throw new NoClassDefFoundError( ConsoleText.get().noSystemConsoleAvailable); - CredentialsProvider.setDefault(c); + CredentialsProvider cp = new ChainingCredentialsProvider( + new NetRCCredentialsProvider(), c); + CredentialsProvider.setDefault(cp); } private final Console cons = System.console(); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java index 1842b725e..93fcd66c5 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java @@ -80,6 +80,11 @@ class LsRemote extends TextBuiltin { } } + @Override + protected boolean requiresRepository() { + return false; + } + private void show(final AnyObjectId id, final String name) throws IOException { outw.print(id.name()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java index aba48bc35..873b2cda4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java @@ -54,6 +54,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -224,6 +225,25 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { // shouldn't throw anything } + /** + * Try to pass non-existing object as uninteresting, with ignoring setting. + * Use a repo with bitmap indexes because then PackWriter will use + * PackWriterBitmapWalker which had problems with this situation. + * + * @throws IOException + * @throws ParseException + */ + @Test + public void testIgnoreNonExistingObjectsWithBitmaps() throws IOException, + ParseException { + final ObjectId nonExisting = ObjectId + .fromString("0000000000000000000000000000000000000001"); + new GC(db).gc(); + createVerifyOpenPack(EMPTY_SET_OBJECT, + Collections.singleton(nonExisting), false, true, true); + // shouldn't throw anything + } + /** * Create pack basing on only interesting objects, then precisely verify * content. No delta reuse here. @@ -604,8 +624,17 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { final Set uninterestings, final boolean thin, final boolean ignoreMissingUninteresting) throws MissingObjectException, IOException { + createVerifyOpenPack(interestings, uninterestings, thin, + ignoreMissingUninteresting, false); + } + + private void createVerifyOpenPack(final Set interestings, + final Set uninterestings, final boolean thin, + final boolean ignoreMissingUninteresting, boolean useBitmaps) + throws MissingObjectException, IOException { NullProgressMonitor m = NullProgressMonitor.INSTANCE; writer = new PackWriter(config, db.newObjectReader()); + writer.setUseBitmaps(useBitmaps); writer.setThin(thin); writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting); writer.preparePack(m, interestings, uninterestings); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 79dc11ead..164934704 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -1847,9 +1847,10 @@ public class PackWriter { Set have) throws MissingObjectException, IncorrectObjectTypeException, IOException { - BitmapBuilder haveBitmap = bitmapWalker.findObjects(have, null); + BitmapBuilder haveBitmap = bitmapWalker.findObjects(have, null, true); bitmapWalker.reset(); - BitmapBuilder wantBitmap = bitmapWalker.findObjects(want, haveBitmap); + BitmapBuilder wantBitmap = bitmapWalker.findObjects(want, haveBitmap, + false); BitmapBuilder needBitmap = wantBitmap.andNot(haveBitmap); if (useCachedPacks && reuseSupport != null @@ -2049,7 +2050,7 @@ public class PackWriter { walker = bitmapPreparer.newBitmapWalker(); BitmapBuilder bitmap = walker.findObjects( - Collections.singleton(cmit), null); + Collections.singleton(cmit), null, false); if (last != null && cmit.isReuseWalker() && !bitmap.contains(last)) throw new IllegalStateException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapWalker.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapWalker.java index 2e9ce1ddc..63a91cd82 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapWalker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriterBitmapWalker.java @@ -78,7 +78,7 @@ final class PackWriterBitmapWalker { this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm; } - BitmapBuilder findObjects(Set start, BitmapBuilder seen) + BitmapBuilder findObjects(Set start, BitmapBuilder seen, boolean ignoreMissingStart) throws MissingObjectException, IncorrectObjectTypeException, IOException { final BitmapBuilder bitmapResult = bitmapIndex.newBitmapBuilder(); @@ -91,9 +91,15 @@ final class PackWriterBitmapWalker { boolean marked = false; for (ObjectId obj : start) { - if (!bitmapResult.contains(obj)) { - walker.markStart(walker.parseAny(obj)); - marked = true; + try { + if (!bitmapResult.contains(obj)) { + walker.markStart(walker.parseAny(obj)); + marked = true; + } + } catch (MissingObjectException e) { + if (ignoreMissingStart) + continue; + throw e; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ChainingCredentialsProvider.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ChainingCredentialsProvider.java new file mode 100644 index 000000000..3e0ee2f64 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ChainingCredentialsProvider.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2014, Matthias Sohn + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.transport; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.jgit.errors.UnsupportedCredentialItem; + +/** + * A credentials provider chaining multiple credentials providers + * + * @since 3.5 + */ +public class ChainingCredentialsProvider extends CredentialsProvider { + + private List credentialProviders; + + /** + * Create a new chaining credential provider. This provider tries to + * retrieve credentials from the chained credential providers in the order + * they are given here. If multiple providers support the requested items + * and have non-null credentials the first of them will be used. + * + * @param providers + * credential providers asked for credentials in the order given + * here + */ + public ChainingCredentialsProvider(CredentialsProvider... providers) { + this.credentialProviders = new ArrayList( + Arrays.asList(providers)); + for (CredentialsProvider p : providers) + credentialProviders.add(p); + } + + /** + * @return {@code true} if any of the credential providers in the list is + * interactive, otherwise {@code false} + * @see org.eclipse.jgit.transport.CredentialsProvider#isInteractive() + */ + @Override + public boolean isInteractive() { + for (CredentialsProvider p : credentialProviders) + if (p.isInteractive()) + return true; + return false; + } + + /** + * @return {@code true} if any of the credential providers in the list + * supports the requested items, otherwise {@code false} + * @see org.eclipse.jgit.transport.CredentialsProvider#supports(org.eclipse.jgit.transport.CredentialItem[]) + */ + @Override + public boolean supports(CredentialItem... items) { + for (CredentialsProvider p : credentialProviders) + if (p.supports(items)) + return true; + return false; + } + + /** + * Populates the credential items with the credentials provided by the first + * credential provider in the list which populates them with non-null values + * + * @return {@code true} if any of the credential providers in the list + * supports the requested items, otherwise {@code false} + * @see org.eclipse.jgit.transport.CredentialsProvider#supports(org.eclipse.jgit.transport.CredentialItem[]) + */ + @Override + public boolean get(URIish uri, CredentialItem... items) + throws UnsupportedCredentialItem { + for (CredentialsProvider p : credentialProviders) { + if (p.supports(items)) { + p.get(uri, items); + if (isAnyNull(items)) + continue; + return true; + } + } + return false; + } + + private boolean isAnyNull(CredentialItem... items) { + for (CredentialItem i : items) + if (i == null) + return true; + return false; + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 837bd58d8..3ad1db2d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -311,10 +311,14 @@ public abstract class Transport { public static Transport open(final Repository local, final String remote, final Operation op) throws NotSupportedException, URISyntaxException, TransportException { - final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); - if (doesNotExist(cfg)) - return open(local, new URIish(remote), null); - return open(local, cfg, op); + if (local != null) { + final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); + if (doesNotExist(cfg)) + return open(local, new URIish(remote), null); + return open(local, cfg, op); + } else + return open(new URIish(remote)); + } /** 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 cc07b8547..82d1737b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -264,9 +264,6 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } http = local.getConfig().get(HTTP_KEY); proxySelector = ProxySelector.getDefault(); - - if (getCredentialsProvider() == null) - setCredentialsProvider(new NetRCCredentialsProvider()); } /**