~ubuntu-branches/ubuntu/quantal/monodevelop/quantal

« back to all changes in this revision

Viewing changes to contrib/NGit/NGit/RefRename.cs

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2011-06-29 06:56:25 UTC
  • mfrom: (1.8.1 upstream) (1.3.11 experimental)
  • Revision ID: james.westby@ubuntu.com-20110629065625-7xx19c4vb95j65pl
Tags: 2.5.92+dfsg-1ubuntu1
* Merge from Debian experimental:
 - Dropped patches & changes to debian/control for Moonlight
   + debian/patches/remove_support_for_moonlight.patch,
   + debian/patches/dont_add_moonlight_to_core_addins.patch,
 - Remaining patches:
   + debian/patches/no_appmenu:

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.IO;
 
45
using NGit;
 
46
using Sharpen;
 
47
 
 
48
namespace NGit
 
49
{
 
50
        /// <summary>A RefUpdate combination for renaming a reference.</summary>
 
51
        /// <remarks>
 
52
        /// A RefUpdate combination for renaming a reference.
 
53
        /// <p>
 
54
        /// If the source reference is currently pointed to by
 
55
        /// <code>HEAD</code>
 
56
        /// , then the
 
57
        /// HEAD symbolic reference is updated to point to the new destination.
 
58
        /// </remarks>
 
59
        public abstract class RefRename
 
60
        {
 
61
                /// <summary>Update operation to read and delete the source reference.</summary>
 
62
                /// <remarks>Update operation to read and delete the source reference.</remarks>
 
63
                protected internal readonly RefUpdate source;
 
64
 
 
65
                /// <summary>Update operation to create/overwrite the destination reference.</summary>
 
66
                /// <remarks>Update operation to create/overwrite the destination reference.</remarks>
 
67
                protected internal readonly RefUpdate destination;
 
68
 
 
69
                private RefUpdate.Result result = RefUpdate.Result.NOT_ATTEMPTED;
 
70
 
 
71
                /// <summary>Initialize a new rename operation.</summary>
 
72
                /// <remarks>Initialize a new rename operation.</remarks>
 
73
                /// <param name="src">operation to read and delete the source.</param>
 
74
                /// <param name="dst">operation to create (or overwrite) the destination.</param>
 
75
                protected internal RefRename(RefUpdate src, RefUpdate dst)
 
76
                {
 
77
                        source = src;
 
78
                        destination = dst;
 
79
                        string cmd = string.Empty;
 
80
                        if (source.GetName().StartsWith(Constants.R_HEADS) && destination.GetName().StartsWith
 
81
                                (Constants.R_HEADS))
 
82
                        {
 
83
                                cmd = "Branch: ";
 
84
                        }
 
85
                        SetRefLogMessage(cmd + "renamed " + Repository.ShortenRefName(source.GetName()) +
 
86
                                 " to " + Repository.ShortenRefName(destination.GetName()));
 
87
                }
 
88
 
 
89
                /// <returns>identity of the user making the change in the reflog.</returns>
 
90
                public virtual PersonIdent GetRefLogIdent()
 
91
                {
 
92
                        return destination.GetRefLogIdent();
 
93
                }
 
94
 
 
95
                /// <summary>Set the identity of the user appearing in the reflog.</summary>
 
96
                /// <remarks>
 
97
                /// Set the identity of the user appearing in the reflog.
 
98
                /// <p>
 
99
                /// The timestamp portion of the identity is ignored. A new identity with the
 
100
                /// current timestamp will be created automatically when the rename occurs
 
101
                /// and the log record is written.
 
102
                /// </remarks>
 
103
                /// <param name="pi">
 
104
                /// identity of the user. If null the identity will be
 
105
                /// automatically determined based on the repository
 
106
                /// configuration.
 
107
                /// </param>
 
108
                public virtual void SetRefLogIdent(PersonIdent pi)
 
109
                {
 
110
                        destination.SetRefLogIdent(pi);
 
111
                }
 
112
 
 
113
                /// <summary>Get the message to include in the reflog.</summary>
 
114
                /// <remarks>Get the message to include in the reflog.</remarks>
 
115
                /// <returns>
 
116
                /// message the caller wants to include in the reflog; null if the
 
117
                /// rename should not be logged.
 
118
                /// </returns>
 
119
                public virtual string GetRefLogMessage()
 
120
                {
 
121
                        return destination.GetRefLogMessage();
 
122
                }
 
123
 
 
124
                /// <summary>Set the message to include in the reflog.</summary>
 
125
                /// <remarks>Set the message to include in the reflog.</remarks>
 
126
                /// <param name="msg">the message to describe this change.</param>
 
127
                public virtual void SetRefLogMessage(string msg)
 
128
                {
 
129
                        if (msg == null)
 
130
                        {
 
131
                                DisableRefLog();
 
132
                        }
 
133
                        else
 
134
                        {
 
135
                                destination.SetRefLogMessage(msg, false);
 
136
                        }
 
137
                }
 
138
 
 
139
                /// <summary>Don't record this rename in the ref's associated reflog.</summary>
 
140
                /// <remarks>Don't record this rename in the ref's associated reflog.</remarks>
 
141
                public virtual void DisableRefLog()
 
142
                {
 
143
                        destination.SetRefLogMessage(string.Empty, false);
 
144
                }
 
145
 
 
146
                /// <returns>result of rename operation</returns>
 
147
                public virtual RefUpdate.Result GetResult()
 
148
                {
 
149
                        return result;
 
150
                }
 
151
 
 
152
                /// <returns>the result of the new ref update</returns>
 
153
                /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 
154
                public virtual RefUpdate.Result Rename()
 
155
                {
 
156
                        try
 
157
                        {
 
158
                                result = DoRename();
 
159
                                return result;
 
160
                        }
 
161
                        catch (IOException err)
 
162
                        {
 
163
                                result = RefUpdate.Result.IO_FAILURE;
 
164
                                throw;
 
165
                        }
 
166
                }
 
167
 
 
168
                /// <returns>the result of the rename operation.</returns>
 
169
                /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 
170
                protected internal abstract RefUpdate.Result DoRename();
 
171
 
 
172
                /// <returns>
 
173
                /// true if the
 
174
                /// <code>Constants#HEAD</code>
 
175
                /// reference needs to be linked
 
176
                /// to the new destination name.
 
177
                /// </returns>
 
178
                /// <exception cref="System.IO.IOException">
 
179
                /// the current value of
 
180
                /// <code>HEAD</code>
 
181
                /// cannot be read.
 
182
                /// </exception>
 
183
                protected internal virtual bool NeedToUpdateHEAD()
 
184
                {
 
185
                        Ref head = source.GetRefDatabase().GetRef(Constants.HEAD);
 
186
                        if (head.IsSymbolic())
 
187
                        {
 
188
                                head = head.GetTarget();
 
189
                                return head.GetName().Equals(source.GetName());
 
190
                        }
 
191
                        return false;
 
192
                }
 
193
        }
 
194
}