Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete the ref.
        /// </summary>
        /// <param name="walk">
        /// a RevWalk instance this delete command can borrow to perform
        /// the merge test. The walk will be reset to perform the test.
        /// </param>
        /// <returns>the result status of the delete.</returns>
        public RefUpdateResult delete(RevWalk.RevWalk walk)
        {
            string myName = Ref.getLeaf().getName();

            if (myName.StartsWith(Constants.R_HEADS))
            {
                Ref head = getRefDatabase().getRef(Constants.HEAD);
                while (head.isSymbolic())
                {
                    head = head.getTarget();
                    if (myName.Equals(head.getName()))
                    {
                        return(result = RefUpdateResult.REJECTED_CURRENT_BRANCH);
                    }
                }
            }

            try
            {
                return(result = updateImpl(walk, new DeleteStore(this)));
            }
            catch (IOException)
            {
                result = RefUpdateResult.IO_FAILURE;
                throw;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
            public override RefUpdateResult Store(LockFile @lock, RefUpdateResult status)
            {
                var storage = RefUpdate._ref.StorageFormat;

                if (storage == Ref.Storage.New)
                {
                    return(status);
                }

                if (storage.IsPacked)
                {
                    RefUpdate._db.RemovePackedRef(RefUpdate._ref.Name);
                }

                int levels = Count(RefUpdate._ref.Name, '/') - 2;

                // Delete logs _before_ unlocking
                DirectoryInfo gitDir = RefUpdate._db.Repository.Directory;
                var           logDir = new DirectoryInfo(gitDir + "/" + Constants.LOGS);

                DeleteFileAndEmptyDir(new FileInfo(logDir + "/" + RefUpdate._ref.Name), levels);

                // We have to unlock before (maybe) deleting the parent directories
                @lock.Unlock();
                if (storage.IsLoose)
                {
                    DeleteFileAndEmptyDir(RefUpdate._looseFile, levels);
                }
                return(status);
            }
Ejemplo n.º 5
0
 protected override RefUpdateResult doDelete(RefUpdateResult status)
 {
     if (Ref.getLeaf().getStorage() != Storage.New)
     {
         _database.delete(this);
     }
     return(status);
 }
Ejemplo n.º 6
0
 public override RefUpdateResult execute(RefUpdateResult status)
 {
     if (status == RefUpdateResult.NO_CHANGE)
     {
         return(status);
     }
     return(_refUpdate.doUpdate(status));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Gracefully update the ref to the new value.
 /// <para/>
 /// Merge test will be performed according to <see cref="IsForceUpdate"/>.
 /// </summary>
 /// <param name="walk">
 /// a RevWalk instance this update command can borrow to perform
 /// the merge test. The walk will be reset to perform the test.
 /// </param>
 /// <returns>
 /// the result status of the update.
 /// </returns>
 public RefUpdateResult update(RevWalk.RevWalk walk)
 {
     requireCanDoUpdate();
     try
     {
         return(result = updateImpl(walk, new UpdateStore(this)));
     }
     catch (IOException x)
     {
         result = RefUpdateResult.IO_FAILURE;
         throw x;
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gracefully update the ref to the new value.
 /// </summary>
 /// <param name="walk">
 /// A <see cref="RevWalk"/> instance this update command can borrow to
 /// perform the merge test. The walk will be reset to perform the test.
 /// </param>
 /// <returns>The result status of the update.</returns>
 public RefUpdateResult Update(RevWalk.RevWalk walk)
 {
     RequireCanDoUpdate();
     try
     {
         return(Result = UpdateImpl(walk, new UpdateStore(this)));
     }
     catch (IOException)
     {
         Result = RefUpdateResult.IOFailure;
         throw;
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Replace this reference with a symbolic reference to another reference.
        /// <para/>
        /// This exact reference (not its traversed leaf) is replaced with a symbolic
        /// reference to the requested name.
        /// </summary>
        /// <param name="target">
        /// name of the new target for this reference. The new target name
        /// must be absolute, so it must begin with {@code refs/}.
        /// </param>
        /// <returns><see cref="RefUpdateResult.NEW"/> or <see cref="RefUpdateResult.FORCED"/> on success.</returns>
        public RefUpdateResult link(string target)
        {
            if (!target.StartsWith(Constants.R_REFS))
            {
                throw new ArgumentException("Not " + Constants.R_REFS);
            }
            if (getRefDatabase().isNameConflicting(Name))
            {
                return(RefUpdateResult.LOCK_FAILURE);
            }
            try
            {
                if (!tryLock(false))
                {
                    return(RefUpdateResult.LOCK_FAILURE);
                }

                Ref old = getRefDatabase().getRef(Name);
                if (old != null && old.isSymbolic())
                {
                    Ref dst = old.getTarget();
                    if (target.Equals(dst.getName()))
                    {
                        return(result = RefUpdateResult.NO_CHANGE);
                    }
                }

                if (old != null && old.getObjectId() != null)
                {
                    OldObjectId = (old.getObjectId());
                }

                Ref dst2 = getRefDatabase().getRef(target);
                if (dst2 != null && dst2.getObjectId() != null)
                {
                    NewObjectId = (dst2.getObjectId());
                }

                return(result = doLink(target));
            }
            catch (IOException)
            {
                result = RefUpdateResult.IO_FAILURE;
                throw;
            }
            finally
            {
                unlock();
            }
        }
Ejemplo n.º 10
0
        private static string toResultString(RefUpdateResult status)
        {
            switch (status)
            {
            case RefUpdateResult.FORCED:
                return("forced-update");

            case RefUpdateResult.FAST_FORWARD:
                return("fast forward");

            case RefUpdateResult.NEW:
                return("created");

            default:
                return(null);
            }
        }
Ejemplo n.º 11
0
        private static string ToResultString(RefUpdateResult status)
        {
            switch (status)
            {
            case RefUpdateResult.Forced:
                return("forced-update");

            case RefUpdateResult.FastForward:
                return("fast forward");

            case RefUpdateResult.New:
                return("created");

            default:
                return(null);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Delete the ref.
        /// </summary>
        /// <param name="walk">
        /// A <see cref="RevWalk"/> instance this Delete command can borrow to
        /// perform the merge test. The walk will be reset to perform the test.
        /// </param>
        /// <returns>The result status of the Delete.</returns>
        public RefUpdateResult Delete(RevWalk.RevWalk walk)
        {
            if (Name.StartsWith(Constants.R_HEADS))
            {
                Ref head = _db.ReadRef(Constants.HEAD);
                if (head != null && Name.Equals(head.Name))
                {
                    return(Result = RefUpdateResult.RejectedCurrentBranch);
                }
            }

            try
            {
                return(Result = UpdateImpl(walk, new DeleteStore(this)));
            }
            catch (IOException)
            {
                Result = RefUpdateResult.IOFailure;
                throw;
            }
        }
 protected abstract RefUpdateResult doUpdate(RefUpdateResult desiredResult);
Ejemplo n.º 14
0
 public override RefUpdateResult Store(LockFile lockFile, RefUpdateResult status)
 {
     return RefUpdate.UpdateRepositoryStore(lockFile, status);
 }
Ejemplo n.º 15
0
 public abstract RefUpdateResult Store(LockFile lockFile, RefUpdateResult status);
Ejemplo n.º 16
0
            public override RefUpdateResult Store(LockFile @lockFile, RefUpdateResult status)
            {
                var storage = RefUpdate._ref.StorageFormat;
                if (storage == Ref.Storage.New)
                {
                    return status;
                }

                if (storage.IsPacked)
                {
                    RefUpdate._db.RemovePackedRef(RefUpdate._ref.Name);
                }

                int levels = Count(RefUpdate._ref.Name, '/') - 2;

                // Delete logs _before_ unlocking
                DirectoryInfo gitDir = RefUpdate._db.Repository.Directory;
                var logDir = new DirectoryInfo(gitDir + "/" + Constants.LOGS);
                DeleteFileAndEmptyDir(new FileInfo(logDir + "/" + RefUpdate._ref.Name), levels);

                // We have to unlock before (maybe) deleting the parent directories
                lockFile.Unlock();
                if (storage.IsLoose)
                {
                    DeleteFileAndEmptyDir(RefUpdate._looseFile, levels);
                }
                return status;
            }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
0
        private static string ToResultString(RefUpdateResult status)
        {
            switch (status)
            {
                case RefUpdateResult.Forced:
                    return "forced-update";

                case RefUpdateResult.FastForward:
                    return "fast forward";

                case RefUpdateResult.New:
                    return "created";

                default:
                    return null;
            }
        }
 public override RefUpdateResult execute(RefUpdateResult status)
 {
     if (status == RefUpdateResult.NO_CHANGE)
         return status;
     return _refUpdate.doUpdate(status);
 }
Ejemplo n.º 20
0
 public override RefUpdateResult Store(LockFile lockFile, RefUpdateResult status)
 {
     return(RefUpdate.UpdateRepositoryStore(lockFile, status));
 }
Ejemplo n.º 21
0
 private RefUpdateResult updateStore(LockFile @lock, RefUpdateResult status)
 {
     if (status == RefUpdateResult.NoChange)
         return status;
     @lock.NeedStatInformation=(true);
     @lock.Write(newValue);
     string msg = GetRefLogMessage();
     if (msg != null && refLogIncludeResult)
     {
         if (status == RefUpdateResult.Forced)
             msg += ": forced-update";
         else if (status == RefUpdateResult.FastForward)
             msg += ": fast forward";
         else if (status == RefUpdateResult.New)
             msg += ": created";
     }
     RefLogWriter.append(this, msg);
     if ([email protected]())
         return RefUpdateResult.LockFailure;
     db.stored(this._ref.OriginalName, _ref.Name, newValue, @lock.CommitLastModified);
     return status;
 }
Ejemplo n.º 22
0
 public override RefUpdateResult execute(RefUpdateResult status)
 {
     return(_refUpdate.doDelete(status));
 }
Ejemplo n.º 23
0
 protected abstract RefUpdateResult doDelete(RefUpdateResult desiredResult);
Ejemplo n.º 24
0
 public abstract RefUpdateResult execute(RefUpdateResult status);
 public override RefUpdateResult execute(RefUpdateResult status)
 {
     return _refUpdate.doDelete(status);
 }
 /// <summary>
 /// Gracefully update the ref to the new value.
 /// <para/>
 /// Merge test will be performed according to <see cref="IsForceUpdate"/>.
 /// </summary>
 /// <param name="walk">
 /// a RevWalk instance this update command can borrow to perform
 /// the merge test. The walk will be reset to perform the test.
 /// </param>
 /// <returns>
 /// the result status of the update.
 /// </returns>
 public RefUpdateResult update(RevWalk.RevWalk walk)
 {
     requireCanDoUpdate();
     try
     {
         return result = updateImpl(walk, new UpdateStore(this));
     }
     catch (IOException x)
     {
         result = RefUpdateResult.IO_FAILURE;
         throw x;
     }
 }
Ejemplo n.º 27
0
 protected override RefUpdateResult doDelete(RefUpdateResult status)
 {
     if (Ref.getLeaf().getStorage() != Storage.New)
         _database.delete(this);
     return status;
 }
Ejemplo n.º 28
0
 public abstract RefUpdateResult Store(LockFile lockFile, RefUpdateResult status);
        /// <summary>
        /// Replace this reference with a symbolic reference to another reference.
        /// <para/>
        /// This exact reference (not its traversed leaf) is replaced with a symbolic
        /// reference to the requested name.
        /// </summary>
        /// <param name="target">
        /// name of the new target for this reference. The new target name
        /// must be absolute, so it must begin with {@code refs/}.
        /// </param>
        /// <returns><see cref="RefUpdateResult.NEW"/> or <see cref="RefUpdateResult.FORCED"/> on success.</returns>
        public RefUpdateResult link(string target)
        {
            if (!target.StartsWith(Constants.R_REFS))
                throw new ArgumentException("Not " + Constants.R_REFS);
            if (getRefDatabase().isNameConflicting(Name))
                return RefUpdateResult.LOCK_FAILURE;
            try
            {
                if (!tryLock(false))
                    return RefUpdateResult.LOCK_FAILURE;

                Ref old = getRefDatabase().getRef(Name);
                if (old != null && old.isSymbolic())
                {
                    Ref dst = old.getTarget();
                    if (target.Equals(dst.getName()))
                        return result = RefUpdateResult.NO_CHANGE;
                }

                if (old != null && old.getObjectId() != null)
                    OldObjectId = (old.getObjectId());

                Ref dst2 = getRefDatabase().getRef(target);
                if (dst2 != null && dst2.getObjectId() != null)
                    NewObjectId = (dst2.getObjectId());

                return result = doLink(target);
            }
            catch (IOException x)
            {
                result = RefUpdateResult.IO_FAILURE;
                throw;
            }
            finally
            {
                unlock();
            }
        }
Ejemplo n.º 30
0
 public override RefUpdateResult Store(LockFile lockFile, RefUpdateResult status)
 {
     return ref_update.updateStore(lockFile, status);
 }
 public abstract RefUpdateResult execute(RefUpdateResult status);
Ejemplo n.º 32
0
            public override RefUpdateResult Store(LockFile @lock, RefUpdateResult status)
            {
                GitSharp.Ref.Storage storage = ref_update._ref.StorageFormat;
                if (storage == GitSharp.Ref.Storage.New)
                    return status;
                if (storage.IsPacked)
                    ref_update.db.removePackedRef(ref_update._ref.Name);

                int levels = Count(ref_update._ref.Name, '/') - 2;

                // Delete logs _before_ unlocking
                DirectoryInfo gitDir = ref_update.db.Repository.Directory;
                DirectoryInfo logDir = new DirectoryInfo(gitDir+"/"+ Constants.LOGS);
                deleteFileAndEmptyDir(new FileInfo(logDir + "/" + ref_update._ref.Name), levels);

                // We have to unlock before (maybe) deleting the parent directories
                @lock.Unlock();
                if (storage.IsLoose)
                    deleteFileAndEmptyDir(ref_update.looseFile, levels);
                return status;
            }
Ejemplo n.º 33
0
        /// <summary>
        /// Delete the ref.
        /// </summary>
        /// <param name="walk">
        /// A <see cref="RevWalk"/> instance this Delete command can borrow to 
        /// perform the merge test. The walk will be reset to perform the test.
        /// </param>
        /// <returns>The result status of the Delete.</returns>
        public RefUpdateResult Delete(RevWalk.RevWalk walk)
        {
            if (Name.StartsWith(Constants.R_HEADS))
            {
                Ref head = _db.ReadRef(Constants.HEAD);
                if (head != null && Name.Equals(head.Name))
                {
                    return Result = RefUpdateResult.RejectedCurrentBranch;
                }
            }

            try
            {
                return Result = UpdateImpl(walk, new DeleteStore(this));
            }
            catch (IOException)
            {
                Result = RefUpdateResult.IOFailure;
                throw;
            }
        }
Ejemplo n.º 34
0
 private static string toResultString(RefUpdateResult status)
 {
     switch (status)
     {
         case RefUpdateResult.FORCED:
             return "forced-update";
         case RefUpdateResult.FAST_FORWARD:
             return "fast forward";
         case RefUpdateResult.NEW:
             return "created";
         default:
             return null;
     }
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Gracefully update the ref to the new value.
 /// </summary>
 /// <param name="walk">
 /// A <see cref="RevWalk"/> instance this update command can borrow to 
 /// perform the merge test. The walk will be reset to perform the test.
 /// </param>
 /// <returns>The result status of the update.</returns>
 public RefUpdateResult Update(RevWalk.RevWalk walk)
 {
     RequireCanDoUpdate();
     try
     {
         return Result = UpdateImpl(walk, new UpdateStore(this));
     }
     catch (IOException)
     {
         Result = RefUpdateResult.IOFailure;
         throw;
     }
 }
Ejemplo n.º 36
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;
        }
        /// <summary>
        /// Delete the ref.
        /// </summary>
        /// <param name="walk">
        /// a RevWalk instance this delete command can borrow to perform
        /// the merge test. The walk will be reset to perform the test.
        /// </param>
        /// <returns>the result status of the delete.</returns>
        public RefUpdateResult delete(RevWalk.RevWalk walk)
        {
            string myName = Ref.getLeaf().getName();
            if (myName.StartsWith(Constants.R_HEADS))
            {
                Ref head = getRefDatabase().getRef(Constants.HEAD);
                while (head.isSymbolic())
                {
                    head = head.getTarget();
                    if (myName.Equals(head.getName()))
                        return result = RefUpdateResult.REJECTED_CURRENT_BRANCH;
                }
            }

            try
            {
                return result = updateImpl(walk, new DeleteStore(this));
            }
            catch (IOException x)
            {
                result = RefUpdateResult.IO_FAILURE;
                throw;
            }
        }