diff options
author | Ivan Frade <ifrade@google.com> | 2018-10-15 12:19:41 -0700 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2018-10-15 16:37:22 -0700 |
commit | 1a0b48fecd6ec7654d58b5ca8695b9a346655f04 (patch) | |
tree | e5567e5871a198088161d0ecb9dee58f34d90c3e | |
parent | 8460ab8e879e4f9fe55f9e3a3c412c7c5369b5f9 (diff) | |
download | jgit-1a0b48fecd6ec7654d58b5ca8695b9a346655f04.tar.gz jgit-1a0b48fecd6ec7654d58b5ca8695b9a346655f04.zip |
Create FetchRequest superclass with common elements
Some code apply to both, v1 and v2 requests, so it should receive
just a request instance.
Move all common fields to an abstract superclass that can be passed
to "version neutral" functions.
Change-Id: I47c22fb12065bc93767f78175e2b36cc43ccb5c5
Signed-off-by: Ivan Frade <ifrade@google.com>
3 files changed, 150 insertions, 101 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchRequest.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchRequest.java new file mode 100644 index 0000000000..a960b4a4b5 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchRequest.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2018, Google LLC. + * 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.Set; + +import org.eclipse.jgit.annotations.NonNull; +import org.eclipse.jgit.lib.ObjectId; + +/** + * Common fields between v0/v1/v2 fetch requests. + */ +abstract class FetchRequest { + + final Set<ObjectId> wantIds; + + final int depth; + + final Set<ObjectId> clientShallowCommits; + + final long filterBlobLimit; + + final Set<String> clientCapabilities; + + /** + * Initialize the common fields of a fetch request. + * + * @param wantIds + * list of want ids + * @param depth + * how deep to go in the tree + * @param clientShallowCommits + * commits the client has without history + * @param filterBlobLimit + * to exclude blobs on certain conditions + * @param clientCapabilities + * capabilities sent in the request + */ + FetchRequest(Set<ObjectId> wantIds, int depth, + Set<ObjectId> clientShallowCommits, long filterBlobLimit, + Set<String> clientCapabilities) { + if (wantIds == null || clientShallowCommits == null + || clientCapabilities == null) { + throw new NullPointerException(); + } + + this.wantIds = wantIds; + this.depth = depth; + this.clientShallowCommits = clientShallowCommits; + this.filterBlobLimit = filterBlobLimit; + this.clientCapabilities = clientCapabilities; + } + + /** + * @return object ids in the "want" (and "want-ref") lines of the request + */ + @NonNull + Set<ObjectId> getWantIds() { + return wantIds; + } + + /** + * @return the depth set in a "deepen" line. 0 by default. + */ + int getDepth() { + return depth; + } + + /** + * Shallow commits the client already has. + * + * These are sent by the client in "shallow" request lines. + * + * @return set of commits the client has declared as shallow. + */ + @NonNull + Set<ObjectId> getClientShallowCommits() { + return clientShallowCommits; + } + + /** + * @return the blob limit set in a "filter" line (-1 if not set) + */ + long getFilterBlobLimit() { + return filterBlobLimit; + } + + /** + * Capabilities that the client wants enabled from the server. + * + * Capabilities are options that tune the expected response from the server, + * like "thin-pack", "no-progress" or "ofs-delta". This list should be a + * subset of the capabilities announced by the server in its first response. + * + * These options are listed and well-defined in the git protocol + * specification. + * + * @return capabilities sent by the client + */ + @NonNull + Set<String> getClientCapabilities() { + return clientCapabilities; + } +}
\ No newline at end of file diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java index 4f1f979119..a40c734718 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV0Request.java @@ -51,46 +51,13 @@ import org.eclipse.jgit.lib.ObjectId; /** * Fetch request in the V0/V1 protocol. */ -final class FetchV0Request { - - final Set<ObjectId> wantIds; - - final int depth; - - final Set<ObjectId> clientShallowCommits; - - final long filterBlobLimit; - - final Set<String> clientCapabilities; +final class FetchV0Request extends FetchRequest { FetchV0Request(Set<ObjectId> wantIds, int depth, Set<ObjectId> clientShallowCommits, long filterBlobLimit, Set<String> clientCapabilities) { - this.wantIds = wantIds; - this.depth = depth; - this.clientShallowCommits = clientShallowCommits; - this.filterBlobLimit = filterBlobLimit; - this.clientCapabilities = clientCapabilities; - } - - Set<ObjectId> getWantIds() { - return wantIds; - } - - int getDepth() { - return depth; - } - - Set<ObjectId> getClientShallowCommits() { - return clientShallowCommits; - } - - long getFilterBlobLimit() { - return filterBlobLimit; - } - - Set<String> getClientCapabilities() { - return clientCapabilities; + super(wantIds, depth, clientShallowCommits, filterBlobLimit, + clientCapabilities); } static final class Builder { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java index 64f7170df5..7d84b19a4e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java @@ -60,25 +60,15 @@ import org.eclipse.jgit.lib.ObjectId; * * @since 5.1 */ -public final class FetchV2Request { +public final class FetchV2Request extends FetchRequest { private final List<ObjectId> peerHas; private final TreeMap<String, ObjectId> wantedRefs; - private final Set<ObjectId> wantIds; - - private final Set<ObjectId> clientShallowCommits; - private final int deepenSince; private final List<String> deepenNotRefs; - private final int depth; - - private final long filterBlobLimit; - - private final Set<String> clientCapabilities; - private final boolean doneReceived; private FetchV2Request(List<ObjectId> peerHas, @@ -86,16 +76,12 @@ public final class FetchV2Request { Set<ObjectId> clientShallowCommits, int deepenSince, List<String> deepenNotRefs, int depth, long filterBlobLimit, boolean doneReceived, Set<String> clientCapabilities) { + super(wantIds, depth, clientShallowCommits, filterBlobLimit, clientCapabilities); this.peerHas = peerHas; this.wantedRefs = wantedRefs; - this.wantIds = wantIds; - this.clientShallowCommits = clientShallowCommits; this.deepenSince = deepenSince; this.deepenNotRefs = deepenNotRefs; - this.depth = depth; - this.filterBlobLimit = filterBlobLimit; this.doneReceived = doneReceived; - this.clientCapabilities = clientCapabilities; } /** @@ -111,27 +97,7 @@ public final class FetchV2Request { */ @NonNull Map<String, ObjectId> getWantedRefs() { - return this.wantedRefs; - } - - /** - * @return object ids received in the "want" and "want-ref" lines - */ - @NonNull - Set<ObjectId> getWantIds() { - return wantIds; - } - - /** - * Shallow commits the client already has. - * - * These are sent by the client in "shallow" request lines. - * - * @return set of commits the client has declared as shallow. - */ - @NonNull - Set<ObjectId> getClientShallowCommits() { - return clientShallowCommits; + return wantedRefs; } /** @@ -154,40 +120,12 @@ public final class FetchV2Request { } /** - * @return the depth set in a "deepen" line. 0 by default. - */ - int getDepth() { - return depth; - } - - /** - * @return the blob limit set in a "filter" line (-1 if not set) - */ - long getFilterBlobLimit() { - return filterBlobLimit; - } - - /** * @return true if the request had a "done" line */ boolean wasDoneReceived() { return doneReceived; } - /** - * Options that tune the expected response from the server, like - * "thin-pack", "no-progress" or "ofs-delta" - * - * These are options listed and well-defined in the git protocol - * specification - * - * @return options found in the request lines - */ - @NonNull - Set<String> getClientCapabilities() { - return clientCapabilities; - } - /** @return A builder of {@link FetchV2Request}. */ static Builder builder() { return new Builder(); |