/// <exception cref="System.IO.IOException"></exception> protected internal override RefUpdate.Result DoUpdate(RefUpdate.Result status) { WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY); Lock.SetFSync(wc.GetFSyncRefFiles()); Lock.SetNeedStatInformation(true); Lock.Write(GetNewObjectId()); string msg = GetRefLogMessage(); if (msg != null) { if (IsRefLogIncludingResult()) { string strResult = ToResultString(status); if (strResult != null) { if (msg.Length > 0) { msg = msg + ": " + strResult; } else { msg = strResult; } } } database.Log(this, msg, true); } if (!Lock.Commit()) { return(RefUpdate.Result.LOCK_FAILURE); } database.Stored(this, Lock.GetCommitSnapshot()); return(status); }
/// <exception cref="System.IO.IOException"></exception> private NGit.Storage.File.ReflogWriter Log(string refName, byte[] rec) { FilePath log = LogFor(refName); bool write = forceWrite || (IsLogAllRefUpdates() && ShouldAutoCreateLog(refName)) || log.IsFile(); if (!write) { return(this); } WriteConfig wc = GetRepository().GetConfig().Get(WriteConfig.KEY); FileOutputStream @out; try { @out = new FileOutputStream(log, true); } catch (FileNotFoundException err) { FilePath dir = log.GetParentFile(); if (dir.Exists()) { throw; } if (!dir.Mkdirs() && !dir.IsDirectory()) { throw new IOException(MessageFormat.Format(JGitText.Get().cannotCreateDirectory, dir)); } @out = new FileOutputStream(log, true); } try { if (wc.GetFSyncRefFiles()) { FileChannel fc = @out.GetChannel(); ByteBuffer buf = ByteBuffer.Wrap(rec); while (0 < buf.Remaining()) { fc.Write(buf); } fc.Force(true); } else { @out.Write(rec); } } finally { @out.Close(); } return(this); }
/// <exception cref="System.IO.IOException"></exception> protected internal override RefUpdate.Result DoLink(string target) { WriteConfig wc = database.GetRepository().GetConfig().Get(WriteConfig.KEY); Lock.SetFSync(wc.GetFSyncRefFiles()); Lock.SetNeedStatInformation(true); Lock.Write(Constants.Encode(RefDirectory.SYMREF + target + '\n')); string msg = GetRefLogMessage(); if (msg != null) { database.Log(this, msg, false); } if (!Lock.Commit()) { return(RefUpdate.Result.LOCK_FAILURE); } database.StoredSymbolicRef(this, Lock.GetCommitSnapshot(), target); if (GetRef().GetStorage() == RefStorage.NEW) { return(RefUpdate.Result.NEW); } return(RefUpdate.Result.FORCED); }
internal ObjectDirectoryInserter(FileObjectDatabase dest, Config cfg) { db = dest; config = cfg.Get(WriteConfig.KEY); }