From 9e496c8060d6dfce0ee68b545d5d8255716dceac Mon Sep 17 00:00:00 2001 From: Marek Zawirski Date: Sun, 17 Aug 2008 22:43:53 +0200 Subject: [PATCH] Add another RemoteRefUpdate constructor, useful for 2-stage push New constructor base on existing RemoteRefUpdate instance, providing deep copy of object, but allowing change of expectedOldObjectId. It may be useful for copying ref updates during one-to-many push or 2-stage push, with first 1st step being dry run, 2nd being actual push. Signed-off-by: Marek Zawirski [Ed. amended follow up patch] Signed-off-by: Robin Rosenberg --- .../spearce/jgit/transport/RemoteRefUpdate.java | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java index 5afb8a46..fd193000 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java @@ -123,7 +123,7 @@ public class RemoteRefUpdate { private final TrackingRefUpdate trackingRefUpdate; - private String srcRef; + private final String srcRef; private final boolean forceUpdate; @@ -133,13 +133,15 @@ public class RemoteRefUpdate { private String message; + private final Repository localDb; + /** * Construct remote ref update request by providing an update specification. * Object is created with default {@link Status#NOT_ATTEMPTED} status and no * message. * - * @param db - * repository to push from. + * @param localDb + * local repository to push from. * @param srcRef * source revision - any string resolvable by * {@link Repository#resolve(String)}. This resolves to the new @@ -171,30 +173,54 @@ public class RemoteRefUpdate { * @throws IllegalArgumentException * if some required parameter was null */ - public RemoteRefUpdate(final Repository db, final String srcRef, + public RemoteRefUpdate(final Repository localDb, final String srcRef, final String remoteName, final boolean forceUpdate, final String localName, final ObjectId expectedOldObjectId) throws IOException { if (remoteName == null) throw new IllegalArgumentException("Remote name can't be null."); this.srcRef = srcRef; - this.newObjectId = (srcRef == null ? ObjectId.zeroId() : db + this.newObjectId = (srcRef == null ? ObjectId.zeroId() : localDb .resolve(srcRef)); if (newObjectId == null) throw new IOException("Source ref " + srcRef + " doesn't resolve to any object."); this.remoteName = remoteName; this.forceUpdate = forceUpdate; - if (localName != null && db != null) - trackingRefUpdate = new TrackingRefUpdate(db, localName, + if (localName != null && localDb != null) + trackingRefUpdate = new TrackingRefUpdate(localDb, localName, remoteName, forceUpdate, newObjectId, "push"); else trackingRefUpdate = null; + this.localDb = localDb; this.expectedOldObjectId = expectedOldObjectId; this.status = Status.NOT_ATTEMPTED; } /** + * Create a new instance of this object basing on existing instance for + * configuration. State (like {@link #getMessage()}, {@link #getStatus()}) + * of base object is not shared. Expected old object id is set up from + * scratch, as this constructor may be used for 2-stage push: first one + * being dry run, second one being actual push. + * + * @param base + * configuration base. + * @param newExpectedOldObjectId + * new expected object id value. + * @throws IOException + * when I/O error occurred during creating + * {@link TrackingRefUpdate} for local tracking branch or srcRef + * of base object no longer can be resolved to any object. + */ + public RemoteRefUpdate(final RemoteRefUpdate base, + final ObjectId newExpectedOldObjectId) throws IOException { + this(base.localDb, base.srcRef, base.remoteName, base.forceUpdate, + (base.trackingRefUpdate == null ? null : base.trackingRefUpdate + .getLocalName()), newExpectedOldObjectId); + } + + /** * @return expectedOldObjectId required to be advertised by remote side, as * set in constructor; may be null. */ -- 2.11.4.GIT