Browse Source

Move BaseReceivePack#advertisedRefs getter and setter to ReceivePack

Another step toward merging BaseReceivePack into ReceivePack.

Change-Id: If861e28ce512f556e574352fa7d4a0df0984693f
Signed-off-by: Jonathan Nieder <jrn@google.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.3
Jonathan Nieder 6 years ago committed by Matthias Sohn
parent
commit
dbf6f9f692
  1. 12
      org.eclipse.jgit/.settings/.api_filters
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHook.java
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java
  4. 33
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
  5. 56
      org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

12
org.eclipse.jgit/.settings/.api_filters

@ -31,6 +31,12 @@
</filter>
</resource>
<resource path="src/org/eclipse/jgit/transport/BaseReceivePack.java" type="org.eclipse.jgit.transport.BaseReceivePack">
<filter id="421650549">
<message_arguments>
<message_argument value="org.eclipse.jgit.transport.BaseReceivePack"/>
<message_argument value="getAdvertisedRefs()"/>
</message_arguments>
</filter>
<filter id="421650549">
<message_arguments>
<message_argument value="org.eclipse.jgit.transport.BaseReceivePack"/>
@ -49,6 +55,12 @@
<message_argument value="getRevWalk()"/>
</message_arguments>
</filter>
<filter id="421650549">
<message_arguments>
<message_argument value="org.eclipse.jgit.transport.BaseReceivePack"/>
<message_argument value="setAdvertisedRefs(Map&lt;String,Ref&gt;, Set&lt;ObjectId&gt;)"/>
</message_arguments>
</filter>
<filter id="421650549">
<message_arguments>
<message_argument value="org.eclipse.jgit.transport.BaseReceivePack"/>

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHook.java

@ -53,7 +53,7 @@ public interface AdvertiseRefsHook {
* <p>
* The method implementations do nothing to preserve the default behavior; see
* {@link UploadPack#setAdvertisedRefs(java.util.Map)} and
* {@link BaseReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}.
* {@link ReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}.
*/
AdvertiseRefsHook DEFAULT = new AdvertiseRefsHook() {
@Override
@ -85,7 +85,7 @@ public interface AdvertiseRefsHook {
*
* @param receivePack
* instance on which to call
* {@link org.eclipse.jgit.transport.BaseReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}
* {@link org.eclipse.jgit.transport.ReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}
* if necessary.
* @throws org.eclipse.jgit.transport.ServiceMayNotContinueException
* abort; the message will be sent to the user.

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java

@ -52,7 +52,7 @@ import java.util.List;
* Hooks are run in the order passed to the constructor. A hook may inspect or
* modify the results of the previous hooks in the chain by calling
* {@link org.eclipse.jgit.transport.UploadPack#getAdvertisedRefs()}, or
* {@link org.eclipse.jgit.transport.BaseReceivePack#getAdvertisedRefs()} or
* {@link org.eclipse.jgit.transport.ReceivePack#getAdvertisedRefs()} or
* {@link org.eclipse.jgit.transport.BaseReceivePack#getAdvertisedObjects()}.
*/
public class AdvertiseRefsHookChain implements AdvertiseRefsHook {

33
org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java

@ -204,7 +204,7 @@ public abstract class BaseReceivePack {
private AdvertiseRefsHook advertiseRefsHook;
/** Filter used while advertising the refs to the client. */
private RefFilter refFilter;
RefFilter refFilter;
/** Timeout in seconds to wait for client interaction. */
private int timeout;
@ -239,10 +239,10 @@ public abstract class BaseReceivePack {
private PackParser parser;
/** The refs we advertised as existing at the start of the connection. */
private Map<String, Ref> refs;
Map<String, Ref> refs;
/** All SHA-1s shown to the client, which can be possible edges. */
private Set<ObjectId> advertisedHaves;
Set<ObjectId> advertisedHaves;
/** Capabilities requested by the client. */
private Set<String> enabledCapabilities;
@ -440,10 +440,10 @@ public abstract class BaseReceivePack {
*
* @return all refs which were advertised to the client, or null if
* {@link #setAdvertisedRefs(Map, Set)} has not been called yet.
* @deprecated use {@link ReceivePack#getAdvertisedRefs}
*/
public final Map<String, Ref> getAdvertisedRefs() {
return refs;
}
@Deprecated
public abstract Map<String, Ref> getAdvertisedRefs();
/**
* Set the refs advertised by this ReceivePack.
@ -461,25 +461,10 @@ public abstract class BaseReceivePack {
* explicit set of additional haves to claim as advertised. If
* null, assumes the default set of additional haves from the
* repository.
* @deprecated use {@link ReceivePack#setAdvertisedRefs}
*/
public void setAdvertisedRefs(Map<String, Ref> allRefs, Set<ObjectId> additionalHaves) {
refs = allRefs != null ? allRefs : db.getAllRefs();
refs = refFilter.filter(refs);
advertisedHaves.clear();
Ref head = refs.get(Constants.HEAD);
if (head != null && head.isSymbolic())
refs.remove(Constants.HEAD);
for (Ref ref : refs.values()) {
if (ref.getObjectId() != null)
advertisedHaves.add(ref.getObjectId());
}
if (additionalHaves != null)
advertisedHaves.addAll(additionalHaves);
else
advertisedHaves.addAll(db.getAdditionalHaves());
}
@Deprecated
public abstract void setAdvertisedRefs(Map<String, Ref> allRefs, Set<ObjectId> additionalHaves);
/**
* Get objects advertised to the client.

56
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java

@ -43,6 +43,7 @@
package org.eclipse.jgit.transport;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_ATOMIC;
import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_PUSH_OPTIONS;
import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_REPORT_STATUS;
@ -53,12 +54,16 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.UnpackException;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.ReceiveCommand.Result;
@ -113,6 +118,57 @@ public class ReceivePack extends BaseReceivePack {
return walk;
}
/**
* Get refs which were advertised to the client.
*
* @return all refs which were advertised to the client, or null if
* {@link #setAdvertisedRefs(Map, Set)} has not been called yet.
*/
@Override
public final Map<String, Ref> getAdvertisedRefs() {
return refs;
}
/**
* Set the refs advertised by this ReceivePack.
* <p>
* Intended to be called from a
* {@link org.eclipse.jgit.transport.PreReceiveHook}.
*
* @param allRefs
* explicit set of references to claim as advertised by this
* ReceivePack instance. This overrides any references that may
* exist in the source repository. The map is passed to the
* configured {@link #getRefFilter()}. If null, assumes all refs
* were advertised.
* @param additionalHaves
* explicit set of additional haves to claim as advertised. If
* null, assumes the default set of additional haves from the
* repository.
*/
@Override
public void setAdvertisedRefs(Map<String, Ref> allRefs, Set<ObjectId> additionalHaves) {
refs = allRefs != null ? allRefs : db.getAllRefs();
refs = refFilter.filter(refs);
advertisedHaves.clear();
Ref head = refs.get(HEAD);
if (head != null && head.isSymbolic()) {
refs.remove(HEAD);
}
for (Ref ref : refs.values()) {
if (ref.getObjectId() != null) {
advertisedHaves.add(ref.getObjectId());
}
}
if (additionalHaves != null) {
advertisedHaves.addAll(additionalHaves);
} else {
advertisedHaves.addAll(db.getAdditionalHaves());
}
}
/**
* Get the push certificate used to verify the pusher's identity.
* <p>

Loading…
Cancel
Save