Write() public method

public Write ( ObjectId id ) : void
id ObjectId
return void
Beispiel #1
0
        protected override RefUpdateResult doUpdate(RefUpdateResult status)
        {
            _lock.setNeedStatInformation(true);
            _lock.Write(NewObjectId);

            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(RefUpdateResult.LOCK_FAILURE);
            }
            _database.stored(this, _lock.CommitLastModified);
            return(status);
        }
            protected override void writeFile(string name, byte[] content)
            {
                _lck.setNeedStatInformation(true);
                try
                {
                    _lck.Write(content);
                }
                catch (IOException ioe)
                {
                    throw new ObjectWritingException("Unable to write " + name,
                                                     ioe);
                }
                try
                {
                    _lck.waitForStatChange();
                }
                catch (ThreadAbortException)
                {
                    _lck.Unlock();
                    throw new ObjectWritingException("Interrupted writing "
                                                     + name);
                }
                if (!_lck.Commit())
                {
                    throw new ObjectWritingException("Unable to write " + name);
                }

                _packedRefs.compareAndSet(_oldPackedList, new PackedRefList(_refs,
                                                                            content.Length, _lck.CommitLastModified));
            }
Beispiel #3
0
        private RefUpdateResult UpdateRepositoryStore(LockFile @lock, RefUpdateResult status)
        {
            if (status == RefUpdateResult.NoChange)
            {
                return(status);
            }

            @lock.NeedStatInformation = true;
            @lock.Write(_newValue);

            string msg = GetRefLogMessage();

            if (msg != null)
            {
                if (_refLogIncludeResult)
                {
                    string strResult = ToResultString(status);
                    if (strResult != null)
                    {
                        msg = !string.IsNullOrEmpty(msg) ? msg + ": " + strResult : strResult;
                    }
                }

                RefLogWriter.append(this, msg);
            }

            if ([email protected]())
            {
                return(RefUpdateResult.LockFailure);
            }

            _db.Stored(_ref.OriginalName, _ref.Name, _newValue, @lock.CommitLastModified);
            return(status);
        }
Beispiel #4
0
        /// <summary>
        /// Create the <code>pack-*.keep</code> file, with the given message.
        /// </summary>
        /// <param name="msg">message to store in the file.</param>
        /// <returns>
        /// true if the keep file was successfully written; false otherwise.
        /// </returns>
        /// <exception cref="IOException">
		/// The keep file could not be written.
        /// </exception>
        public bool Lock(string msg)
        {
            if (msg == null) 
				return false;
			
            if (!msg.EndsWith("\n")) msg += "\n";
            using(LockFile lf = new LockFile(_keepFile))
			{
	            if (!lf.Lock()) 
					return false;
	            lf.Write(Constants.encode(msg));
	            return lf.Commit();
			}
        }
Beispiel #5
0
		protected override void writeFile(string file, byte[] content) {
			FileInfo p = PathUtil.CombineFilePath(_db.Directory, file);
			LockFile lck = new LockFile(p);
			if (!lck.Lock())
				throw new ObjectWritingException("Can't write " + p);
			try {
				lck.Write(content);
			}
			catch (IOException) {
				throw new ObjectWritingException("Can't write " + p);
			}
			if (!lck.Commit())
				throw new ObjectWritingException("Can't write " + p);
		}
Beispiel #6
0
        public void save()
        {
            byte[] o = Constants.encode(toText());
            using (LockFile lf = new LockFile(getFile()))
            {
                if (!lf.Lock())
                {
                    throw new IOException("Cannot lock " + getFile());
                }

                lf.Write(o);
                if (!lf.Commit())
                {
                    throw new IOException("Cannot commit write to " + getFile());
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Create the <code>pack-*.keep</code> file, with the given message.
        /// </summary>
        /// <param name="msg">message to store in the file.</param>
        /// <returns>
        /// true if the keep file was successfully written; false otherwise.
        /// </returns>
        /// <exception cref="IOException">
        /// The keep file could not be written.
        /// </exception>
        public bool Lock(string msg)
        {
            if (msg == null)
            {
                return(false);
            }
            if (!msg.EndsWith("\n"))
            {
                msg += "\n";
            }
            var lf = new LockFile(_keepFile);

            if (!lf.Lock())
            {
                return(false);
            }
            lf.Write(Constants.encode(msg));
            return(lf.Commit());
        }
Beispiel #8
0
        private static void LockAndWriteFile(FileInfo file, byte[] content)
        {
            string name = file.Name;
            var    lck  = new LockFile(file);

            if (!lck.Lock())
            {
                throw new ObjectWritingException("Unable to lock " + name);
            }

            try
            {
                lck.Write(content);
            }
            catch (IOException ioe)
            {
                throw new ObjectWritingException("Unable to write " + name, ioe);
            }
            if (!lck.Commit())
            {
                throw new ObjectWritingException("Unable to write " + name);
            }
        }
Beispiel #9
0
 public void save()
 {
     byte[] o = Constants.encode(toText());
     LockFile lf = new LockFile(getFile());
     if (!lf.Lock())
         throw new IOException("Cannot lock " + getFile());
     try
     {
         lf.Write(o);
         if (!lf.Commit())
             throw new IOException("Cannot commit write to " + getFile());
     }
     finally
     {
         lf.Unlock();
     }
 }
Beispiel #10
0
        private RefUpdateResult UpdateRepositoryStore(LockFile @lock, RefUpdateResult status)
        {
            if (status == RefUpdateResult.NoChange) return status;

            @lock.NeedStatInformation = true;
            @lock.Write(_newValue);

            string msg = GetRefLogMessage();

            if (msg != null)
            {
                if (_refLogIncludeResult)
                {
                    string strResult = ToResultString(status);
                    if (strResult != null)
                    {
                        msg = !string.IsNullOrEmpty(msg) ? msg + ": " + strResult : strResult;
                    }
                }

                RefLogWriter.append(this, msg);
            }

            if ([email protected]())
            {
                return RefUpdateResult.LockFailure;
            }

            _db.Stored(_ref.OriginalName, _ref.Name, _newValue, @lock.CommitLastModified);
            return status;
        }
Beispiel #11
0
        }

        private static void LockAndWriteFile(FileInfo file, byte[] content)
        {
            string name = file.Name;
            using (LockFile lck = new LockFile(file))
            {
                if (!lck.Lock())
                {
                    throw new ObjectWritingException("Unable to lock " + name);
                }

                try
                {
                    lck.Write(content);
                }
                catch (IOException ioe)
                {
                    throw new ObjectWritingException("Unable to write " + name, ioe);
                }
                if (!lck.Commit())
                {
                    throw new ObjectWritingException("Unable to write " + name);
                }