Browse Source

Include push certificates in RefUpdate

This may be used by e.g. a custom reflog implementation to record
this information along with the ref update.

Change-Id: I44adbfad704b76f9c1beced6e1ce82eaf71410d2
stable-4.1
Dave Borowitz 10 years ago
parent
commit
fc6790a5d7
  1. 32
      org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java
  2. 29
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java
  3. 1
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java

32
org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java

@ -59,6 +59,7 @@ import java.util.List;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.PushCertificate;
import org.eclipse.jgit.transport.ReceiveCommand; import org.eclipse.jgit.transport.ReceiveCommand;
/** /**
@ -85,6 +86,9 @@ public class BatchRefUpdate {
/** Should the result value be appended to {@link #refLogMessage}. */ /** Should the result value be appended to {@link #refLogMessage}. */
private boolean refLogIncludeResult; private boolean refLogIncludeResult;
/** Push certificate associated with this update. */
private PushCertificate pushCert;
/** /**
* Initialize a new batch update. * Initialize a new batch update.
* *
@ -195,6 +199,33 @@ public class BatchRefUpdate {
return refLogMessage == null; return refLogMessage == null;
} }
/**
* Set a push certificate associated with this update.
* <p>
* This usually includes commands to update the refs in this batch, but is not
* required to.
*
* @param cert
* push certificate, may be null.
* @since 4.1
*/
public void setPushCertificate(PushCertificate cert) {
pushCert = cert;
}
/**
* Set the push certificate associated with this update.
* <p>
* This usually includes commands to update the refs in this batch, but is not
* required to.
*
* @return push certificate, may be null.
* @since 4.1
*/
protected PushCertificate getPushCertificate() {
return pushCert;
}
/** @return commands this update will process. */ /** @return commands this update will process. */
public List<ReceiveCommand> getCommands() { public List<ReceiveCommand> getCommands() {
return Collections.unmodifiableList(commands); return Collections.unmodifiableList(commands);
@ -377,6 +408,7 @@ public class BatchRefUpdate {
ru.setRefLogIdent(refLogIdent); ru.setRefLogIdent(refLogIdent);
ru.setRefLogMessage(refLogMessage, refLogIncludeResult); ru.setRefLogMessage(refLogMessage, refLogIncludeResult);
} }
ru.setPushCertificate(pushCert);
switch (cmd.getType()) { switch (cmd.getType()) {
case DELETE: case DELETE:
if (!ObjectId.zeroId().equals(cmd.getOldId())) if (!ObjectId.zeroId().equals(cmd.getOldId()))

29
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java

@ -52,6 +52,7 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.PushCertificate;
/** /**
* Creates, updates or deletes any reference. * Creates, updates or deletes any reference.
@ -165,6 +166,9 @@ public abstract class RefUpdate {
/** Result of the update operation. */ /** Result of the update operation. */
private Result result = Result.NOT_ATTEMPTED; private Result result = Result.NOT_ATTEMPTED;
/** Push certificate associated with this update. */
private PushCertificate pushCert;
private final Ref ref; private final Ref ref;
/** /**
@ -413,6 +417,31 @@ public abstract class RefUpdate {
oldValue = old; oldValue = old;
} }
/**
* Set a push certificate associated with this update.
* <p>
* This usually includes a command to update this ref, but is not required to.
*
* @param cert
* push certificate, may be null.
* @since 4.1
*/
public void setPushCertificate(PushCertificate cert) {
pushCert = cert;
}
/**
* Set the push certificate associated with this update.
* <p>
* This usually includes a command to update this ref, but is not required to.
*
* @return push certificate, may be null.
* @since 4.1
*/
protected PushCertificate getPushCertificate() {
return pushCert;
}
/** /**
* Get the status of this update. * Get the status of this update.
* <p> * <p>

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

@ -1479,6 +1479,7 @@ public abstract class BaseReceivePack {
batch.setRefLogMessage("push", true); //$NON-NLS-1$ batch.setRefLogMessage("push", true); //$NON-NLS-1$
batch.addCommand(toApply); batch.addCommand(toApply);
try { try {
batch.setPushCertificate(getPushCertificate());
batch.execute(walk, updating); batch.execute(walk, updating);
} catch (IOException err) { } catch (IOException err) {
for (ReceiveCommand cmd : toApply) { for (ReceiveCommand cmd : toApply) {

Loading…
Cancel
Save