Update README.txt
[GitSharp.git] / GitSharp / Commands / AbstractFetchCommand.cs
blob6d913ec1d5e166b3f7044d71455559dd8a6900b3
1 /*
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 using System;
38 using GitSharp.Core;
39 using GitSharp.Core.Transport;
41 namespace GitSharp.Commands
43 public abstract class AbstractFetchCommand : AbstractCommand
45 protected bool verbose;
47 protected void showFetchResult(GitSharp.Core.Transport.Transport tn, FetchResult r)
49 bool shownURI = false;
50 foreach (TrackingRefUpdate u in r.TrackingRefUpdates)
52 if (!verbose && u.Result == RefUpdate.RefUpdateResult.NO_CHANGE)
53 continue;
55 char type = shortTypeOf(u.Result);
56 string longType = longTypeOf(u);
57 string src = AbbreviateRef(u.RemoteName, false);
58 string dst = AbbreviateRef(u.LocalName, true);
60 if (!shownURI)
62 OutputStream.Write("From ");
63 OutputStream.WriteLine(tn.Uri);
64 shownURI = true;
67 OutputStream.WriteLine(" " + type + " " + longType + " " + src + " -> " + dst);
71 private string longTypeOf(TrackingRefUpdate u)
73 RefUpdate.RefUpdateResult r = u.Result;
74 if (r == RefUpdate.RefUpdateResult.LOCK_FAILURE)
75 return "[lock fail]";
76 if (r == RefUpdate.RefUpdateResult.IO_FAILURE)
77 return "[i/o error]";
78 if (r == RefUpdate.RefUpdateResult.REJECTED)
79 return "[rejected]";
80 if (ObjectId.ZeroId.Equals(u.NewObjectId))
81 return "[deleted]";
83 if (r == RefUpdate.RefUpdateResult.NEW)
85 if (u.RemoteName.StartsWith(Constants.R_HEADS))
86 return "[new branch]";
87 if (u.LocalName.StartsWith(Constants.R_TAGS))
88 return "[new tag]";
89 return "[new]";
92 if (r == RefUpdate.RefUpdateResult.FORCED)
94 string aOld = u.OldObjectId.Abbreviate(Repository).name();
95 string aNew = u.NewObjectId.Abbreviate(Repository).name();
96 return aOld + "..." + aNew;
99 if (r == RefUpdate.RefUpdateResult.FAST_FORWARD)
101 string aOld = u.OldObjectId.Abbreviate(Repository).name();
102 string aNew = u.NewObjectId.Abbreviate(Repository).name();
103 return aOld + ".." + aNew;
106 if (r == RefUpdate.RefUpdateResult.NO_CHANGE)
107 return "[up to date]";
109 return "[" + r + "]";
112 private static char shortTypeOf(RefUpdate.RefUpdateResult r)
114 switch (r)
116 case RefUpdate.RefUpdateResult.LOCK_FAILURE:
117 case RefUpdate.RefUpdateResult.IO_FAILURE:
118 case RefUpdate.RefUpdateResult.REJECTED:
119 return '!';
121 case RefUpdate.RefUpdateResult.NEW:
122 return '*';
124 case RefUpdate.RefUpdateResult.FORCED:
125 return '+';
127 case RefUpdate.RefUpdateResult.NO_CHANGE:
128 return '=';
130 default:
131 return ' ';