Example #1
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;
            }
        }
 private static Ref recreate(Ref old, ObjectIdRef leaf)
 {
     if (old.isSymbolic())
     {
         Ref dst = recreate(old.getTarget(), leaf);
         return(new SymbolicRef(old.getName(), dst));
     }
     return(leaf);
 }
Example #3
0
        /// <returns>
        /// true if the {@code Constants#HEAD} reference needs to be linked
        /// to the new destination name.
        /// </returns>
        protected bool needToUpdateHEAD()
        {
            Ref head = source.getRefDatabase().getRef(Constants.HEAD);

            if (head.isSymbolic())
            {
                head = head.getTarget();
                return(head.getName().Equals(source.getName()));
            }
            return(false);
        }
Example #4
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();
            }
        }
        private Ref resolve(Ref @ref, int depth, string prefix,
                            RefList <LooseRef> loose, RefList <Ref> packed)
        {
            if (@ref.isSymbolic())
            {
                Ref dst = @ref.getTarget();

                if (MAX_SYMBOLIC_REF_DEPTH <= depth)
                {
                    return(null); // claim it doesn't exist
                }
                // If the cached value can be assumed to be current due to a
                // recent scan of the loose directory, use it.
                if (loose != null && dst.getName().StartsWith(prefix))
                {
                    int idx;
                    if (0 <= (idx = loose.find(dst.getName())))
                    {
                        dst = loose.get(idx);
                    }
                    else if (0 <= (idx = packed.find(dst.getName())))
                    {
                        dst = packed.get(idx);
                    }
                    else
                    {
                        return(@ref);
                    }
                }
                else
                {
                    dst = readRef(dst.getName(), packed);
                    if (dst == null)
                    {
                        return(@ref);
                    }
                }

                dst = resolve(dst, depth + 1, prefix, loose, packed);
                if (dst == null)
                {
                    return(null);
                }
                return(new SymbolicRef(@ref.getName(), dst));
            }
            return(@ref);
        }
Example #6
0
        public override string ToString()
        {
            var r = new StringBuilder();

            r.Append("SymbolicRef[");
            Ref cur = this;

            while (cur.isSymbolic())
            {
                r.Append(cur.getName());
                r.Append(" -> ");
                cur = cur.getTarget();
            }
            r.Append(cur.getName());
            r.Append('=');
            r.Append(ObjectId.ToString(cur.getObjectId()));
            r.Append("]");
            return(r.ToString());
        }