コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <summary>Save the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Save the configuration as a Git text style configuration file.
        /// <p>
        /// <b>Warning:</b> Although this method uses the traditional Git file
        /// locking approach to protect against concurrent writes of the
        /// configuration file, it does not ensure that the file has not been
        /// modified since the last read, which means updates performed by other
        /// objects accessing the same backing file may be lost.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be written.</exception>
        public override void Save()
        {
            byte[]   @out = Constants.Encode(ToText());
            LockFile lf   = new LockFile(GetFile(), fs);

            if (!lf.Lock())
            {
                throw new LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
コード例 #3
0
        /// <summary>Save the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Save the configuration as a Git text style configuration file.
        /// <p>
        /// <b>Warning:</b> Although this method uses the traditional Git file
        /// locking approach to protect against concurrent writes of the
        /// configuration file, it does not ensure that the file has not been
        /// modified since the last read, which means updates performed by other
        /// objects accessing the same backing file may be lost.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be written.</exception>
        public override void Save()
        {
            byte[] @out;
            string text = ToText();

            if (utf8Bom)
            {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                bos.Write(unchecked ((int)(0xEF)));
                bos.Write(unchecked ((int)(0xBB)));
                bos.Write(unchecked ((int)(0xBF)));
                bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
                                                                ()));
                @out = bos.ToByteArray();
            }
            else
            {
                @out = Constants.Encode(text);
            }
            LockFile lf = new LockFile(GetFile(), fs);

            if (!lf.Lock())
            {
                throw new LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
コード例 #4
0
ファイル: FileBasedConfig.cs プロジェクト: LunarLanding/ngit
		/// <summary>Save the configuration as a Git text style configuration file.</summary>
		/// <remarks>
		/// Save the configuration as a Git text style configuration file.
		/// <p>
		/// <b>Warning:</b> Although this method uses the traditional Git file
		/// locking approach to protect against concurrent writes of the
		/// configuration file, it does not ensure that the file has not been
		/// modified since the last read, which means updates performed by other
		/// objects accessing the same backing file may be lost.
		/// </remarks>
		/// <exception cref="System.IO.IOException">the file could not be written.</exception>
		public override void Save()
		{
			byte[] @out;
			string text = ToText();
			if (utf8Bom)
			{
				ByteArrayOutputStream bos = new ByteArrayOutputStream();
				bos.Write(unchecked((int)(0xEF)));
				bos.Write(unchecked((int)(0xBB)));
				bos.Write(unchecked((int)(0xBF)));
				bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
					()));
				@out = bos.ToByteArray();
			}
			else
			{
				@out = Constants.Encode(text);
			}
			LockFile lf = new LockFile(GetFile(), fs);
			if (!lf.Lock())
			{
				throw new LockFailedException(GetFile());
			}
			try
			{
				lf.SetNeedSnapshot(true);
				lf.Write(@out);
				if (!lf.Commit())
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
						()));
				}
			}
			finally
			{
				lf.Unlock();
			}
			snapshot = lf.GetCommitSnapshot();
			hash = Hash(@out);
			// notify the listeners
			FireConfigChangedEvent();
		}
コード例 #5
0
ファイル: FileBasedConfig.cs プロジェクト: kenji-tan/ngit
 /// <summary>Save the configuration as a Git text style configuration file.</summary>
 /// <remarks>
 /// Save the configuration as a Git text style configuration file.
 /// <p>
 /// <b>Warning:</b> Although this method uses the traditional Git file
 /// locking approach to protect against concurrent writes of the
 /// configuration file, it does not ensure that the file has not been
 /// modified since the last read, which means updates performed by other
 /// objects accessing the same backing file may be lost.
 /// </remarks>
 /// <exception cref="System.IO.IOException">the file could not be written.</exception>
 public override void Save()
 {
     byte[] @out = Constants.Encode(ToText());
     LockFile lf = new LockFile(GetFile(), fs);
     if (!lf.Lock())
     {
         throw new LockFailedException(GetFile());
     }
     try
     {
         lf.SetNeedSnapshot(true);
         lf.Write(@out);
         if (!lf.Commit())
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                 ()));
         }
     }
     finally
     {
         lf.Unlock();
     }
     snapshot = lf.GetCommitSnapshot();
     hash = Hash(@out);
     // notify the listeners
     FireConfigChangedEvent();
 }