~ubuntu-branches/ubuntu/wily/monodevelop/wily

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-05-27 18:08:20 UTC
  • mfrom: (19.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20120527180820-fydl21qnbnfr8w2t
Tags: 3.0.2+dfsg-3
* [fcecfe7] Fix monodevelop-core-addins.pc.in to point to actual 
  installed location of assemblies.
* [26e1a07] DebSrc 3.0 does not support Quilt's -p parameter, so 
  manually adjust the path in the patch file.

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 NGit.Revwalk;
45
 
using Sharpen;
46
 
 
47
 
namespace NGit.Revwalk
48
 
{
49
 
        /// <summary>Replaces a RevCommit's parents until not colored with REWRITE.</summary>
50
 
        /// <remarks>
51
 
        /// Replaces a RevCommit's parents until not colored with REWRITE.
52
 
        /// <p>
53
 
        /// Before a RevCommit is returned to the caller its parents are updated to
54
 
        /// create a dense DAG. Instead of reporting the actual parents as recorded when
55
 
        /// the commit was created the returned commit will reflect the next closest
56
 
        /// commit that matched the revision walker's filters.
57
 
        /// <p>
58
 
        /// This generator is the second phase of a path limited revision walk and
59
 
        /// assumes it is receiving RevCommits from
60
 
        /// <see cref="RewriteTreeFilter">RewriteTreeFilter</see>
61
 
        /// ,
62
 
        /// after they have been fully buffered by
63
 
        /// <see cref="AbstractRevQueue">AbstractRevQueue</see>
64
 
        /// . The full
65
 
        /// buffering is necessary to allow the simple loop used within our own
66
 
        /// <see cref="Rewrite(RevCommit)">Rewrite(RevCommit)</see>
67
 
        /// to pull completely through a strand of
68
 
        /// <see cref="RevWalk.REWRITE">RevWalk.REWRITE</see>
69
 
        /// colored commits and come up with a simplification
70
 
        /// that makes the DAG dense. Not fully buffering the commits first would cause
71
 
        /// this loop to abort early, due to commits not being parsed and colored
72
 
        /// correctly.
73
 
        /// </remarks>
74
 
        /// <seealso cref="RewriteTreeFilter">RewriteTreeFilter</seealso>
75
 
        internal class RewriteGenerator : Generator
76
 
        {
77
 
                private const int REWRITE = RevWalk.REWRITE;
78
 
 
79
 
                /// <summary>
80
 
                /// For
81
 
                /// <see cref="Cleanup(RevCommit[])">Cleanup(RevCommit[])</see>
82
 
                /// to remove duplicate parents.
83
 
                /// </summary>
84
 
                private const int DUPLICATE = RevWalk.TEMP_MARK;
85
 
 
86
 
                private readonly Generator source;
87
 
 
88
 
                internal RewriteGenerator(Generator s)
89
 
                {
90
 
                        source = s;
91
 
                }
92
 
 
93
 
                internal override void ShareFreeList(BlockRevQueue q)
94
 
                {
95
 
                        source.ShareFreeList(q);
96
 
                }
97
 
 
98
 
                internal override int OutputType()
99
 
                {
100
 
                        return source.OutputType() & ~NEEDS_REWRITE;
101
 
                }
102
 
 
103
 
                /// <exception cref="NGit.Errors.MissingObjectException"></exception>
104
 
                /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
105
 
                /// <exception cref="System.IO.IOException"></exception>
106
 
                internal override RevCommit Next()
107
 
                {
108
 
                        for (; ; )
109
 
                        {
110
 
                                RevCommit c = source.Next();
111
 
                                if (c == null)
112
 
                                {
113
 
                                        return null;
114
 
                                }
115
 
                                bool rewrote = false;
116
 
                                RevCommit[] pList = c.parents;
117
 
                                int nParents = pList.Length;
118
 
                                for (int i = 0; i < nParents; i++)
119
 
                                {
120
 
                                        RevCommit oldp = pList[i];
121
 
                                        RevCommit newp = Rewrite(oldp);
122
 
                                        if (oldp != newp)
123
 
                                        {
124
 
                                                pList[i] = newp;
125
 
                                                rewrote = true;
126
 
                                        }
127
 
                                }
128
 
                                if (rewrote)
129
 
                                {
130
 
                                        c.parents = Cleanup(pList);
131
 
                                }
132
 
                                return c;
133
 
                        }
134
 
                }
135
 
 
136
 
                private RevCommit Rewrite(RevCommit p)
137
 
                {
138
 
                        for (; ; )
139
 
                        {
140
 
                                RevCommit[] pList = p.parents;
141
 
                                if (pList.Length > 1)
142
 
                                {
143
 
                                        // This parent is a merge, so keep it.
144
 
                                        //
145
 
                                        return p;
146
 
                                }
147
 
                                if ((p.flags & RevWalk.UNINTERESTING) != 0)
148
 
                                {
149
 
                                        // Retain uninteresting parents. They show where the
150
 
                                        // DAG was cut off because it wasn't interesting.
151
 
                                        //
152
 
                                        return p;
153
 
                                }
154
 
                                if ((p.flags & REWRITE) == 0)
155
 
                                {
156
 
                                        // This parent was not eligible for rewriting. We
157
 
                                        // need to keep it in the DAG.
158
 
                                        //
159
 
                                        return p;
160
 
                                }
161
 
                                if (pList.Length == 0)
162
 
                                {
163
 
                                        // We can't go back any further, other than to
164
 
                                        // just delete the parent entirely.
165
 
                                        //
166
 
                                        return null;
167
 
                                }
168
 
                                p = pList[0];
169
 
                        }
170
 
                }
171
 
 
172
 
                private RevCommit[] Cleanup(RevCommit[] oldList)
173
 
                {
174
 
                        // Remove any duplicate parents caused due to rewrites (e.g. a merge
175
 
                        // with two sides that both simplified back into the merge base).
176
 
                        // We also may have deleted a parent by marking it null.
177
 
                        //
178
 
                        int newCnt = 0;
179
 
                        for (int o = 0; o < oldList.Length; o++)
180
 
                        {
181
 
                                RevCommit p = oldList[o];
182
 
                                if (p == null)
183
 
                                {
184
 
                                        continue;
185
 
                                }
186
 
                                if ((p.flags & DUPLICATE) != 0)
187
 
                                {
188
 
                                        oldList[o] = null;
189
 
                                        continue;
190
 
                                }
191
 
                                p.flags |= DUPLICATE;
192
 
                                newCnt++;
193
 
                        }
194
 
                        if (newCnt == oldList.Length)
195
 
                        {
196
 
                                foreach (RevCommit p in oldList)
197
 
                                {
198
 
                                        p.flags &= ~DUPLICATE;
199
 
                                }
200
 
                                return oldList;
201
 
                        }
202
 
                        RevCommit[] newList = new RevCommit[newCnt];
203
 
                        newCnt = 0;
204
 
                        foreach (RevCommit p_1 in oldList)
205
 
                        {
206
 
                                if (p_1 != null)
207
 
                                {
208
 
                                        newList[newCnt++] = p_1;
209
 
                                        p_1.flags &= ~DUPLICATE;
210
 
                                }
211
 
                        }
212
 
                        return newList;
213
 
                }
214
 
        }
215
 
}