2 * Copyright (C) 2008 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.transport
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Collection
;
21 import java
.util
.Collections
;
22 import java
.util
.List
;
24 import java
.util
.SortedMap
;
25 import java
.util
.TreeMap
;
27 import org
.spearce
.jgit
.lib
.Ref
;
30 * Final status after a successful fetch from a remote repository.
32 * @see Transport#fetch(org.spearce.jgit.lib.ProgressMonitor, Collection)
34 public class FetchResult
{
35 private final SortedMap
<String
, TrackingRefUpdate
> updates
;
37 private final List
<FetchHeadRecord
> forMerge
;
39 private Map
<String
, Ref
> advertisedRefs
;
42 updates
= new TreeMap
<String
, TrackingRefUpdate
>();
43 forMerge
= new ArrayList
<FetchHeadRecord
>();
44 advertisedRefs
= Collections
.<String
, Ref
> emptyMap();
47 void add(final TrackingRefUpdate u
) {
48 updates
.put(u
.getLocalName(), u
);
51 void add(final FetchHeadRecord r
) {
56 void setAdvertisedRefs(final Map
<String
, Ref
> ar
) {
61 * Get the complete list of refs advertised by the remote.
63 * The returned refs may appear in any order. If the caller needs these to
64 * be sorted, they should be copied into a new array or List and then sorted
65 * by the caller as necessary.
67 * @return available/advertised refs. Never null. Not modifiable. The
68 * collection can be empty if the remote side has no refs (it is an
69 * empty/newly created repository).
71 public Collection
<Ref
> getAdvertisedRefs() {
72 return advertisedRefs
.values();
76 * Get a single advertised ref by name.
78 * The name supplied should be valid ref name. To get a peeled value for a
79 * ref (aka <code>refs/tags/v1.0^{}</code>) use the base name (without
80 * the <code>^{}</code> suffix) and look at the peeled object id.
83 * name of the ref to obtain.
84 * @return the requested ref; null if the remote did not advertise this ref.
86 public final Ref
getAdvertisedRef(final String name
) {
87 return advertisedRefs
.get(name
);
91 * Get the status of all local tracking refs that were updated.
93 * @return unmodifiable collection of local updates. Never null. Empty if
94 * there were no local tracking refs updated.
96 public Collection
<TrackingRefUpdate
> getTrackingRefUpdates() {
97 return Collections
.unmodifiableCollection(updates
.values());
101 * Get the status for a specific local tracking ref update.
104 * name of the local ref (e.g. "refs/remotes/origin/master").
105 * @return status of the local ref; null if this local ref was not touched
108 public TrackingRefUpdate
getTrackingRefUpdate(final String localName
) {
109 return updates
.get(localName
);