From 04560921c35380d1664e0a6cb9e645ae04ede1a9 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 16 May 2018 12:03:02 +0900 Subject: [PATCH] RefAdvertiser: Add send(Collection) and deprecate send(Map) Bug: 534731 Change-Id: If15032a34dc62f420569e2b2b6d8e14e2dfed522 Signed-off-by: David Pursehouse --- .../eclipse/jgit/transport/RefAdvertiser.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index b4d7803467..1bde49df29 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -53,12 +53,12 @@ import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import java.util.SortedMap; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -66,7 +66,6 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefComparator; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.util.RefMap; /** * Support for the start of {@link org.eclipse.jgit.transport.UploadPack} and @@ -287,9 +286,30 @@ public abstract class RefAdvertiser { * @throws java.io.IOException * the underlying output stream failed to write out an * advertisement record. + * @deprecated use {@link #send(Collection)} instead. */ + @Deprecated public Set send(Map refs) throws IOException { - for (Ref ref : getSortedRefs(refs)) { + return send(refs.values()); + } + + /** + * Format an advertisement for the supplied refs. + * + * @param refs + * zero or more refs to format for the client. The collection is + * sorted before display if necessary, and therefore may appear + * in any order. + * @return set of ObjectIds that were advertised to the client. + * @throws java.io.IOException + * the underlying output stream failed to write out an + * advertisement record. + * @since 5.0 + */ + public Set send(Collection refs) throws IOException { + for (Ref ref : RefComparator.sort(refs)) { + // TODO(jrn) revive the SortedMap optimization e.g. by introducing + // SortedList ObjectId objectId = ref.getObjectId(); if (objectId == null) { continue; @@ -331,13 +351,6 @@ public abstract class RefAdvertiser { return sent; } - private Iterable getSortedRefs(Map all) { - if (all instanceof RefMap - || (all instanceof SortedMap && ((SortedMap) all).comparator() == null)) - return all.values(); - return RefComparator.sort(all.values()); - } - /** * Advertise one object is available using the magic {@code .have}. *

-- 2.39.5