diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2018-05-16 12:03:02 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2018-05-21 10:57:47 +0900 |
commit | 04560921c35380d1664e0a6cb9e645ae04ede1a9 (patch) | |
tree | b6bc90ef024364caaf83f3be52529c9d122ee61a | |
parent | f3ec7cf3f0436a79e252251a31dbc62694555897 (diff) | |
download | jgit-04560921c35380d1664e0a6cb9e645ae04ede1a9.tar.gz jgit-04560921c35380d1664e0a6cb9e645ae04ede1a9.zip |
RefAdvertiser: Add send(Collection<Ref>) and deprecate send(Map<String, Ref>)
Bug: 534731
Change-Id: If15032a34dc62f420569e2b2b6d8e14e2dfed522
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java | 33 |
1 files 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<ObjectId> send(Map<String, Ref> 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<ObjectId> send(Collection<Ref> 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<Ref> getSortedRefs(Map<String, Ref> 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}. * <p> |