Move the BaseReceivePack implementation back into ReceivePack. This is a backward-incompatible change. For example, BaseReceivePack.FirstLine no longer exists and cannot be referenced. However, most of the code should just work by replacing BaseReceivePack with ReceivePack. Although this is an API change, it only affects callers using JGit as a server, and there are very few of those in the wild. Change-Id: I1ce92869435d5eebb7d671be44561e69c6233134 Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>tags/v5.6.0.201911271000-m3
ObjectId newId = | ObjectId newId = | ||||
ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); | ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); | ||||
String line = oldId.name() + " " + newId.name() + " refs/heads/master"; | String line = oldId.name() + " " + newId.name() + " refs/heads/master"; | ||||
ReceiveCommand cmd = BaseReceivePack.parseCommand(line); | |||||
ReceiveCommand cmd = ReceivePack.parseCommand(line); | |||||
parser.addCommand(cmd); | parser.addCommand(cmd); | ||||
parser.addCommand(line); | parser.addCommand(line); |
ReceivePack rp = super.createReceivePack(dst); | ReceivePack rp = super.createReceivePack(dst); | ||||
rp.setAdvertiseRefsHook(new AdvertiseRefsHook() { | rp.setAdvertiseRefsHook(new AdvertiseRefsHook() { | ||||
@Override | @Override | ||||
public void advertiseRefs(BaseReceivePack rp2) | |||||
public void advertiseRefs(ReceivePack rp2) | |||||
throws ServiceMayNotContinueException { | throws ServiceMayNotContinueException { | ||||
rp.setAdvertisedRefs(rp.getRepository().getAllRefs(), | rp.setAdvertisedRefs(rp.getRepository().getAllRefs(), | ||||
null); | null); |
import org.eclipse.jgit.lib.ObjectId; | import org.eclipse.jgit.lib.ObjectId; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
/** Tests for base receive-pack utilities. */ | |||||
public class BaseReceivePackTest { | |||||
/** Tests for receive-pack utilities. */ | |||||
public class ReceivePackTest { | |||||
@Test | @Test | ||||
public void parseCommand() throws Exception { | public void parseCommand() throws Exception { | ||||
String o = "0000000000000000000000000000000000000000"; | String o = "0000000000000000000000000000000000000000"; | ||||
String n = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; | String n = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; | ||||
String r = "refs/heads/master"; | String r = "refs/heads/master"; | ||||
ReceiveCommand cmd = BaseReceivePack.parseCommand(o + " " + n + " " + r); | |||||
ReceiveCommand cmd = ReceivePack.parseCommand(o + " " + n + " " + r); | |||||
assertEquals(ObjectId.zeroId(), cmd.getOldId()); | assertEquals(ObjectId.zeroId(), cmd.getOldId()); | ||||
assertEquals("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", | assertEquals("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", | ||||
cmd.getNewId().name()); | cmd.getNewId().name()); | ||||
private void assertParseCommandFails(String input) { | private void assertParseCommandFails(String input) { | ||||
try { | try { | ||||
BaseReceivePack.parseCommand(input); | |||||
ReceivePack.parseCommand(input); | |||||
fail(); | fail(); | ||||
} catch (PackProtocolException e) { | } catch (PackProtocolException e) { | ||||
// Expected. | // Expected. |
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
@Override | @Override | ||||
public void advertiseRefs(BaseReceivePack receivePack) | |||||
public void advertiseRefs(ReceivePack receivePack) | |||||
throws ServiceMayNotContinueException { | throws ServiceMayNotContinueException { | ||||
Map<String, Ref> refs = getAdvertisedRefs(receivePack.getRepository(), | Map<String, Ref> refs = getAdvertisedRefs(receivePack.getRepository(), | ||||
receivePack.getRevWalk()); | receivePack.getRevWalk()); |
/** | /** | ||||
* A simple hook that advertises the default refs. | * A simple hook that advertises the default refs. | ||||
* <p> | * <p> | ||||
* The method implementations do nothing to preserve the default behavior; see | |||||
* {@link UploadPack#setAdvertisedRefs(java.util.Map)} and | |||||
* The method implementations do nothing to preserve the default behavior; | |||||
* see {@link UploadPack#setAdvertisedRefs(java.util.Map)} and | |||||
* {@link ReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}. | * {@link ReceivePack#setAdvertisedRefs(java.util.Map,java.util.Set)}. | ||||
*/ | */ | ||||
AdvertiseRefsHook DEFAULT = new AdvertiseRefsHook() { | AdvertiseRefsHook DEFAULT = new AdvertiseRefsHook() { | ||||
} | } | ||||
@Override | @Override | ||||
public void advertiseRefs(BaseReceivePack receivePack) { | |||||
public void advertiseRefs(ReceivePack receivePack) { | |||||
// Do nothing. | // Do nothing. | ||||
} | } | ||||
}; | }; | ||||
* @throws org.eclipse.jgit.transport.ServiceMayNotContinueException | * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException | ||||
* abort; the message will be sent to the user. | * abort; the message will be sent to the user. | ||||
*/ | */ | ||||
void advertiseRefs(BaseReceivePack receivePack) | |||||
void advertiseRefs(ReceivePack receivePack) | |||||
throws ServiceMayNotContinueException; | throws ServiceMayNotContinueException; | ||||
} | } |
* modify the results of the previous hooks in the chain by calling | * 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.UploadPack#getAdvertisedRefs()}, or | ||||
* {@link org.eclipse.jgit.transport.ReceivePack#getAdvertisedRefs()} or | * {@link org.eclipse.jgit.transport.ReceivePack#getAdvertisedRefs()} or | ||||
* {@link org.eclipse.jgit.transport.BaseReceivePack#getAdvertisedObjects()}. | |||||
* {@link org.eclipse.jgit.transport.ReceivePack#getAdvertisedObjects()}. | |||||
*/ | */ | ||||
public class AdvertiseRefsHookChain implements AdvertiseRefsHook { | public class AdvertiseRefsHookChain implements AdvertiseRefsHook { | ||||
private final AdvertiseRefsHook[] hooks; | private final AdvertiseRefsHook[] hooks; | ||||
/** {@inheritDoc} */ | /** {@inheritDoc} */ | ||||
@Override | @Override | ||||
public void advertiseRefs(BaseReceivePack rp) | |||||
public void advertiseRefs(ReceivePack rp) | |||||
throws ServiceMayNotContinueException { | throws ServiceMayNotContinueException { | ||||
for (int i = 0; i < count; i++) | for (int i = 0; i < count; i++) | ||||
hooks[i].advertiseRefs(rp); | hooks[i].advertiseRefs(rp); |
package org.eclipse.jgit.transport; | package org.eclipse.jgit.transport; | ||||
import static org.eclipse.jgit.transport.BaseReceivePack.parseCommand; | |||||
import static org.eclipse.jgit.transport.ReceivePack.parseCommand; | |||||
import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_PUSH_CERT; | import static org.eclipse.jgit.transport.GitProtocolConstants.CAPABILITY_PUSH_CERT; | ||||
import java.io.EOFException; | import java.io.EOFException; |
/** | /** | ||||
* A command being processed by | * A command being processed by | ||||
* {@link org.eclipse.jgit.transport.BaseReceivePack}. | |||||
* {@link org.eclipse.jgit.transport.ReceivePack}. | |||||
* <p> | * <p> | ||||
* This command instance roughly translates to the server side representation of | * This command instance roughly translates to the server side representation of | ||||
* the {@link org.eclipse.jgit.transport.RemoteRefUpdate} created by the client. | * the {@link org.eclipse.jgit.transport.RemoteRefUpdate} created by the client. | ||||
/** | /** | ||||
* Create a new command for | * Create a new command for | ||||
* {@link org.eclipse.jgit.transport.BaseReceivePack}. | |||||
* {@link org.eclipse.jgit.transport.ReceivePack}. | |||||
* | * | ||||
* @param oldId | * @param oldId | ||||
* the expected old object id; must not be null. Use | * the expected old object id; must not be null. Use | ||||
/** | /** | ||||
* Create a new command for | * Create a new command for | ||||
* {@link org.eclipse.jgit.transport.BaseReceivePack}. | |||||
* {@link org.eclipse.jgit.transport.ReceivePack}. | |||||
* | * | ||||
* @param oldId | * @param oldId | ||||
* the old object id; must not be null. Use | * the old object id; must not be null. Use | ||||
* receive-pack session. | * receive-pack session. | ||||
* @since 2.0 | * @since 2.0 | ||||
*/ | */ | ||||
public void execute(BaseReceivePack rp) { | |||||
public void execute(ReceivePack rp) { | |||||
try { | try { | ||||
String expTarget = getOldSymref(); | String expTarget = getOldSymref(); | ||||
boolean detach = getNewSymref() != null | boolean detach = getNewSymref() != null |