2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
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
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
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.
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
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.
45
using NGit.Storage.File;
48
namespace NGit.Storage.File
51
/// Updates any reference stored by
52
/// <see cref="RefDirectory">RefDirectory</see>
55
internal class RefDirectoryUpdate : RefUpdate
57
private readonly RefDirectory database;
59
private LockFile Lock;
61
internal RefDirectoryUpdate(RefDirectory r, Ref @ref) : base(@ref)
66
protected internal override RefDatabase GetRefDatabase()
71
protected internal override Repository GetRepository()
73
return database.GetRepository();
76
/// <exception cref="System.IO.IOException"></exception>
77
protected internal override bool TryLock(bool deref)
84
string name = dst.GetName();
85
Lock = new LockFile(database.FileFor(name), GetRepository().FileSystem);
88
dst = database.GetRef(name);
89
SetOldObjectId(dst != null ? dst.GetObjectId() : null);
98
protected internal override void Unlock()
107
/// <exception cref="System.IO.IOException"></exception>
108
protected internal override RefUpdate.Result DoUpdate(RefUpdate.Result status)
110
WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY);
111
Lock.SetFSync(wc.GetFSyncRefFiles());
112
Lock.SetNeedStatInformation(true);
113
Lock.Write(GetNewObjectId());
114
string msg = GetRefLogMessage();
117
if (IsRefLogIncludingResult())
119
string strResult = ToResultString(status);
120
if (strResult != null)
124
msg = msg + ": " + strResult;
132
database.Log(this, msg, true);
136
return RefUpdate.Result.LOCK_FAILURE;
138
database.Stored(this, Lock.GetCommitLastModified());
142
private string ToResultString(RefUpdate.Result status)
146
case RefUpdate.Result.FORCED:
148
return "forced-update";
151
case RefUpdate.Result.FAST_FORWARD:
153
return "fast forward";
156
case RefUpdate.Result.NEW:
169
/// <exception cref="System.IO.IOException"></exception>
170
protected internal override RefUpdate.Result DoDelete(RefUpdate.Result status)
172
if (GetRef().GetLeaf().GetStorage() != RefStorage.NEW)
174
database.Delete(this);
179
/// <exception cref="System.IO.IOException"></exception>
180
protected internal override RefUpdate.Result DoLink(string target)
182
WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY);
183
Lock.SetFSync(wc.GetFSyncRefFiles());
184
Lock.SetNeedStatInformation(true);
185
Lock.Write(Constants.Encode(RefDirectory.SYMREF + target + '\n'));
186
string msg = GetRefLogMessage();
189
database.Log(this, msg, false);
193
return RefUpdate.Result.LOCK_FAILURE;
195
database.StoredSymbolicRef(this, Lock.GetCommitLastModified(), target);
196
if (GetRef().GetStorage() == RefStorage.NEW)
198
return RefUpdate.Result.NEW;
200
return RefUpdate.Result.FORCED;