Allow DirCacheEntry instances to be created with stage > 0
[egit/charleso.git] / org.spearce.jgit / src / org / spearce / jgit / transport / OperationResult.java
blobf078f39f1e4ff10790234840961507d72cdfe472
1 /*
2 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or
9 * without modification, are permitted provided that the following
10 * conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
20 * - Neither the name of the Git Development Community nor the
21 * names of its contributors may be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
30 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 package org.spearce.jgit.transport;
42 import java.util.Collection;
43 import java.util.Collections;
44 import java.util.Map;
45 import java.util.SortedMap;
46 import java.util.TreeMap;
48 import org.spearce.jgit.lib.Ref;
50 /**
51 * Class holding result of operation on remote repository. This includes refs
52 * advertised by remote repo and local tracking refs updates.
54 public abstract class OperationResult {
56 protected Map<String, Ref> advertisedRefs = Collections.emptyMap();
58 protected URIish uri;
60 protected final SortedMap<String, TrackingRefUpdate> updates = new TreeMap<String, TrackingRefUpdate>();
62 /**
63 * Get the URI this result came from.
64 * <p>
65 * Each transport instance connects to at most one URI at any point in time.
67 * @return the URI describing the location of the remote repository.
69 public URIish getURI() {
70 return uri;
73 /**
74 * Get the complete list of refs advertised by the remote.
75 * <p>
76 * The returned refs may appear in any order. If the caller needs these to
77 * be sorted, they should be copied into a new array or List and then sorted
78 * by the caller as necessary.
80 * @return available/advertised refs. Never null. Not modifiable. The
81 * collection can be empty if the remote side has no refs (it is an
82 * empty/newly created repository).
84 public Collection<Ref> getAdvertisedRefs() {
85 return Collections.unmodifiableCollection(advertisedRefs.values());
88 /**
89 * Get a single advertised ref by name.
90 * <p>
91 * The name supplied should be valid ref name. To get a peeled value for a
92 * ref (aka <code>refs/tags/v1.0^{}</code>) use the base name (without
93 * the <code>^{}</code> suffix) and look at the peeled object id.
95 * @param name
96 * name of the ref to obtain.
97 * @return the requested ref; null if the remote did not advertise this ref.
99 public final Ref getAdvertisedRef(final String name) {
100 return advertisedRefs.get(name);
104 * Get the status of all local tracking refs that were updated.
106 * @return unmodifiable collection of local updates. Never null. Empty if
107 * there were no local tracking refs updated.
109 public Collection<TrackingRefUpdate> getTrackingRefUpdates() {
110 return Collections.unmodifiableCollection(updates.values());
114 * Get the status for a specific local tracking ref update.
116 * @param localName
117 * name of the local ref (e.g. "refs/remotes/origin/master").
118 * @return status of the local ref; null if this local ref was not touched
119 * during this operation.
121 public TrackingRefUpdate getTrackingRefUpdate(final String localName) {
122 return updates.get(localName);
125 protected void setAdvertisedRefs(final URIish u, final Map<String, Ref> ar) {
126 uri = u;
127 advertisedRefs = ar;
130 protected void add(final TrackingRefUpdate u) {
131 updates.put(u.getLocalName(), u);