[EGIT PATCH 12/31] Add another RemoteRefUpdate constructor, useful for 2-stage push
- From
- Marek Zawirski <marek.zawirski@gmail.com>
- Date
- Aug 17, 2008, 20:43 UTC
- Message-ID
- <1219005852-21496-13-git-send-email-marek.zawirski@gmail.com>
- In-Reply-To
- <1219005852-21496-12-git-send-email-marek.zawirski@gmail.com>
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 <marek.zawirski@gmail.com> --- .../spearce/jgit/transport/RemoteRefUpdate.java | 28 +++++++++++++++++++- 1 files changed, 27 insertions(+), 1 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 5afb8a4..42588c1 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,6 +133,8 @@ public class RemoteRefUpdate { private String message; + private final Repository db; + /** * Construct remote ref update request by providing an update specification. * Object is created with default {@link Status#NOT_ATTEMPTED} status and no @@ -190,11 +192,35 @@ public class RemoteRefUpdate { remoteName, forceUpdate, newObjectId, "push"); else trackingRefUpdate = null; + this.db = db; 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.db, 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. */
-- 1.5.6.3