~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/NGit/NGit.Revwalk/RevObject.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This code is derived from jgit (http://eclipse.org/jgit).
 
3
Copyright owners are documented in jgit's IP log.
 
4
 
 
5
This program and the accompanying materials are made available
 
6
under the terms of the Eclipse Distribution License v1.0 which
 
7
accompanies this distribution, is reproduced below, and is
 
8
available at http://www.eclipse.org/org/documents/edl-v10.php
 
9
 
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or
 
13
without modification, are permitted provided that the following
 
14
conditions are met:
 
15
 
 
16
- Redistributions of source code must retain the above copyright
 
17
  notice, this list of conditions and the following disclaimer.
 
18
 
 
19
- Redistributions in binary form must reproduce the above
 
20
  copyright notice, this list of conditions and the following
 
21
  disclaimer in the documentation and/or other materials provided
 
22
  with the distribution.
 
23
 
 
24
- Neither the name of the Eclipse Foundation, Inc. nor the
 
25
  names of its contributors may be used to endorse or promote
 
26
  products derived from this software without specific prior
 
27
  written permission.
 
28
 
 
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
42
*/
 
43
 
 
44
using System.Text;
 
45
using NGit;
 
46
using NGit.Revwalk;
 
47
using Sharpen;
 
48
 
 
49
namespace NGit.Revwalk
 
50
{
 
51
        /// <summary>Base object type accessed during revision walking.</summary>
 
52
        /// <remarks>Base object type accessed during revision walking.</remarks>
 
53
        [System.Serializable]
 
54
        public abstract class RevObject : ObjectIdOwnerMap.Entry
 
55
        {
 
56
                internal const int PARSED = 1;
 
57
 
 
58
                internal int flags;
 
59
 
 
60
                protected internal RevObject(AnyObjectId name) : base(name)
 
61
                {
 
62
                }
 
63
 
 
64
                /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 
65
                /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 
66
                /// <exception cref="System.IO.IOException"></exception>
 
67
                internal abstract void ParseHeaders(RevWalk walk);
 
68
 
 
69
                /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 
70
                /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 
71
                /// <exception cref="System.IO.IOException"></exception>
 
72
                internal abstract void ParseBody(RevWalk walk);
 
73
 
 
74
                /// <summary>Get Git object type.</summary>
 
75
                /// <remarks>
 
76
                /// Get Git object type. See
 
77
                /// <see cref="NGit.Constants">NGit.Constants</see>
 
78
                /// .
 
79
                /// </remarks>
 
80
                /// <returns>object type</returns>
 
81
                public abstract int Type
 
82
                {
 
83
                        get;
 
84
                }
 
85
 
 
86
                /// <summary>Get the name of this object.</summary>
 
87
                /// <remarks>Get the name of this object.</remarks>
 
88
                /// <returns>unique hash of this object.</returns>
 
89
                public ObjectId Id
 
90
                {
 
91
                        get
 
92
                        {
 
93
                                return this;
 
94
                        }
 
95
                }
 
96
 
 
97
                /// <summary>Test to see if the flag has been set on this object.</summary>
 
98
                /// <remarks>Test to see if the flag has been set on this object.</remarks>
 
99
                /// <param name="flag">the flag to test.</param>
 
100
                /// <returns>true if the flag has been added to this object; false if not.</returns>
 
101
                public bool Has(RevFlag flag)
 
102
                {
 
103
                        return (flags & flag.mask) != 0;
 
104
                }
 
105
 
 
106
                /// <summary>Test to see if any flag in the set has been set on this object.</summary>
 
107
                /// <remarks>Test to see if any flag in the set has been set on this object.</remarks>
 
108
                /// <param name="set">the flags to test.</param>
 
109
                /// <returns>
 
110
                /// true if any flag in the set has been added to this object; false
 
111
                /// if not.
 
112
                /// </returns>
 
113
                public bool HasAny(RevFlagSet set)
 
114
                {
 
115
                        return (flags & set.mask) != 0;
 
116
                }
 
117
 
 
118
                /// <summary>Test to see if all flags in the set have been set on this object.</summary>
 
119
                /// <remarks>Test to see if all flags in the set have been set on this object.</remarks>
 
120
                /// <param name="set">the flags to test.</param>
 
121
                /// <returns>
 
122
                /// true if all flags of the set have been added to this object;
 
123
                /// false if some or none have been added.
 
124
                /// </returns>
 
125
                public bool HasAll(RevFlagSet set)
 
126
                {
 
127
                        return (flags & set.mask) == set.mask;
 
128
                }
 
129
 
 
130
                /// <summary>Add a flag to this object.</summary>
 
131
                /// <remarks>
 
132
                /// Add a flag to this object.
 
133
                /// <p>
 
134
                /// If the flag is already set on this object then the method has no effect.
 
135
                /// </remarks>
 
136
                /// <param name="flag">the flag to mark on this object, for later testing.</param>
 
137
                public void Add(RevFlag flag)
 
138
                {
 
139
                        flags |= flag.mask;
 
140
                }
 
141
 
 
142
                /// <summary>Add a set of flags to this object.</summary>
 
143
                /// <remarks>Add a set of flags to this object.</remarks>
 
144
                /// <param name="set">the set of flags to mark on this object, for later testing.</param>
 
145
                public void Add(RevFlagSet set)
 
146
                {
 
147
                        flags |= set.mask;
 
148
                }
 
149
 
 
150
                /// <summary>Remove a flag from this object.</summary>
 
151
                /// <remarks>
 
152
                /// Remove a flag from this object.
 
153
                /// <p>
 
154
                /// If the flag is not set on this object then the method has no effect.
 
155
                /// </remarks>
 
156
                /// <param name="flag">the flag to remove from this object.</param>
 
157
                public void Remove(RevFlag flag)
 
158
                {
 
159
                        flags &= ~flag.mask;
 
160
                }
 
161
 
 
162
                /// <summary>Remove a set of flags from this object.</summary>
 
163
                /// <remarks>Remove a set of flags from this object.</remarks>
 
164
                /// <param name="set">the flag to remove from this object.</param>
 
165
                public void Remove(RevFlagSet set)
 
166
                {
 
167
                        flags &= ~set.mask;
 
168
                }
 
169
 
 
170
                public override string ToString()
 
171
                {
 
172
                        StringBuilder s = new StringBuilder();
 
173
                        s.Append(Constants.TypeString(Type));
 
174
                        s.Append(' ');
 
175
                        s.Append(Name);
 
176
                        s.Append(' ');
 
177
                        AppendCoreFlags(s);
 
178
                        return s.ToString();
 
179
                }
 
180
 
 
181
                /// <param name="s">buffer to append a debug description of core RevFlags onto.</param>
 
182
                protected internal virtual void AppendCoreFlags(StringBuilder s)
 
183
                {
 
184
                        s.Append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-');
 
185
                        s.Append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-');
 
186
                        s.Append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-');
 
187
                        s.Append((flags & RevWalk.UNINTERESTING) != 0 ? 'u' : '-');
 
188
                        s.Append((flags & RevWalk.SEEN) != 0 ? 's' : '-');
 
189
                        s.Append((flags & RevWalk.PARSED) != 0 ? 'p' : '-');
 
190
                }
 
191
        }
 
192
}