Implement "jgit upload-pack" to support fetching from jgit
[egit/qmx.git] / org.spearce.jgit / src / org / spearce / jgit / transport / TrackingRefUpdate.java
blobac7472879d55201e6d5cbf3bd27ddb7009e7cd81
1 /*
2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
9 * conditions are met:
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
22 * written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org.spearce.jgit.transport;
41 import java.io.IOException;
43 import org.spearce.jgit.lib.AnyObjectId;
44 import org.spearce.jgit.lib.ObjectId;
45 import org.spearce.jgit.lib.RefUpdate;
46 import org.spearce.jgit.lib.Repository;
47 import org.spearce.jgit.lib.RefUpdate.Result;
48 import org.spearce.jgit.revwalk.RevWalk;
50 /** Update of a locally stored tracking branch. */
51 public class TrackingRefUpdate {
52 private final String remoteName;
54 private final RefUpdate update;
56 TrackingRefUpdate(final Repository db, final RefSpec spec,
57 final AnyObjectId nv, final String msg) throws IOException {
58 this(db, spec.getDestination(), spec.getSource(), spec.isForceUpdate(),
59 nv, msg);
62 TrackingRefUpdate(final Repository db, final String localName,
63 final String remoteName, final boolean forceUpdate,
64 final AnyObjectId nv, final String msg) throws IOException {
65 this.remoteName = remoteName;
66 update = db.updateRef(localName);
67 update.setForceUpdate(forceUpdate);
68 update.setNewObjectId(nv);
69 update.setRefLogMessage(msg, true);
72 /**
73 * Get the name of the remote ref.
74 * <p>
75 * Usually this is of the form "refs/heads/master".
77 * @return the name used within the remote repository.
79 public String getRemoteName() {
80 return remoteName;
83 /**
84 * Get the name of the local tracking ref.
85 * <p>
86 * Usually this is of the form "refs/remotes/origin/master".
88 * @return the name used within this local repository.
90 public String getLocalName() {
91 return update.getName();
94 /**
95 * Get the new value the ref will be (or was) updated to.
97 * @return new value. Null if the caller has not configured it.
99 public ObjectId getNewObjectId() {
100 return update.getNewObjectId();
104 * The old value of the ref, prior to the update being attempted.
105 * <p>
106 * This value may differ before and after the update method. Initially it is
107 * populated with the value of the ref before the lock is taken, but the old
108 * value may change if someone else modified the ref between the time we
109 * last read it and when the ref was locked for update.
111 * @return the value of the ref prior to the update being attempted; null if
112 * the updated has not been attempted yet.
114 public ObjectId getOldObjectId() {
115 return update.getOldObjectId();
119 * Get the status of this update.
121 * @return the status of the update.
123 public Result getResult() {
124 return update.getResult();
127 void update(final RevWalk walk) throws IOException {
128 update.update(walk);
131 void delete(final RevWalk walk) throws IOException {
132 update.delete(walk);