Exemplo n.º 1
0
        private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store)
        {
            if (isNameConflicting())
            {
                return(RefUpdateResult.LockFailure);
            }

            var @lock = new LockFile(_looseFile);

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

            try
            {
                OldObjectId = _db.IdOf(Name);
                if (_expValue != null)
                {
                    ObjectId o = OldObjectId ?? ObjectId.ZeroId;
                    if (!AnyObjectId.equals(_expValue, o))
                    {
                        return(RefUpdateResult.LockFailure);
                    }
                }

                if (OldObjectId == null)
                {
                    return(store.Store(@lock, RefUpdateResult.New));
                }

                RevObject newObj = SafeParse(walk, _newValue);
                RevObject oldObj = SafeParse(walk, OldObjectId);
                if (newObj == oldObj)
                {
                    return(store.Store(@lock, RefUpdateResult.NoChange));
                }

                RevCommit newCom = (newObj as RevCommit);
                RevCommit oldCom = (oldObj as RevCommit);
                if (newCom != null && oldCom != null)
                {
                    if (walk.isMergedInto(oldCom, newCom))
                    {
                        return(store.Store(@lock, RefUpdateResult.FastForward));
                    }
                }

                if (IsForceUpdate)
                {
                    return(store.Store(@lock, RefUpdateResult.Forced));
                }

                return(RefUpdateResult.Rejected);
            }
            finally
            {
                @lock.Unlock();
            }
        }
Exemplo n.º 2
0
        private RefUpdateResult updateImpl(RevWalk.RevWalk walk, Store store)
        {
            RevObject newObj;
            RevObject oldObj;

            if (getRefDatabase().isNameConflicting(Name))
            {
                return(RefUpdateResult.LOCK_FAILURE);
            }
            try
            {
                if (!tryLock(true))
                {
                    return(RefUpdateResult.LOCK_FAILURE);
                }
                if (expValue != null)
                {
                    ObjectId o;
                    o = oldValue != null ? oldValue : ObjectId.ZeroId;
                    if (!AnyObjectId.equals(expValue, o))
                    {
                        return(RefUpdateResult.LOCK_FAILURE);
                    }
                }
                if (oldValue == null)
                {
                    return(store.execute(RefUpdateResult.NEW));
                }

                newObj = safeParse(walk, newValue);
                oldObj = safeParse(walk, oldValue);
                if (newObj == oldObj)
                {
                    return(store.execute(RefUpdateResult.NO_CHANGE));
                }

                if (newObj is RevCommit && oldObj is RevCommit)
                {
                    if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj))
                    {
                        return(store.execute(RefUpdateResult.FAST_FORWARD));
                    }
                }

                if (IsForceUpdate)
                {
                    return(store.execute(RefUpdateResult.FORCED));
                }
                return(RefUpdateResult.REJECTED);
            }
            finally
            {
                unlock();
            }
        }
Exemplo n.º 3
0
        private IDictionary <string, RemoteRefUpdate> PrepareRemoteUpdates()
        {
            IDictionary <string, RemoteRefUpdate> result = new Dictionary <string, RemoteRefUpdate>();

            foreach (RemoteRefUpdate rru in _toPush.Values)
            {
                Ref      advertisedRef = _connection.GetRef(rru.RemoteName);
                ObjectId advertisedOld = (advertisedRef == null ? ObjectId.ZeroId : advertisedRef.ObjectId);

                if (rru.NewObjectId.Equals(advertisedOld))
                {
                    if (rru.IsDelete)
                    {
                        // ref does exist neither locally nor remotely
                        rru.Status = RemoteRefUpdate.UpdateStatus.NON_EXISTING;
                    }
                    else
                    {
                        // same object - nothing to do
                        rru.Status = RemoteRefUpdate.UpdateStatus.UP_TO_DATE;
                    }
                    continue;
                }

                // caller has explicitly specified expected old object id, while it
                // has been changed in the mean time - reject
                if (rru.IsExpectingOldObjectId && !rru.ExpectedOldObjectId.Equals(advertisedOld))
                {
                    rru.Status = RemoteRefUpdate.UpdateStatus.REJECTED_REMOTE_CHANGED;
                    continue;
                }

                // Create ref (hasn't existed on remote side) and delete ref
                // are always fast-forward commands, feasible at this level
                if (advertisedOld.Equals(ObjectId.ZeroId) || rru.IsDelete)
                {
                    rru.FastForward = true;
                    result.put(rru.RemoteName, rru);
                    continue;
                }

                // check for fast-forward:
                // - both old and new ref must point to commits, AND
                // - both of them must be known for us, exist in repository, AND
                // - old commit must be ancestor of new commit
                bool fastForward = true;
                try
                {
                    RevCommit oldRev = (_walker.parseAny(advertisedOld) as RevCommit);
                    RevCommit newRev = (_walker.parseAny(rru.NewObjectId) as RevCommit);
                    if (oldRev == null || newRev == null || !_walker.isMergedInto(oldRev, newRev))
                    {
                        fastForward = false;
                    }
                }
                catch (MissingObjectException)
                {
                    fastForward = false;
                }
                catch (Exception x)
                {
                    throw new TransportException(_transport.Uri, "reading objects from local repository failed: " + x.Message, x);
                }
                rru.FastForward = fastForward;
                if (!fastForward && !rru.ForceUpdate)
                {
                    rru.Status = RemoteRefUpdate.UpdateStatus.REJECTED_NONFASTFORWARD;
                }
                else
                {
                    result.put(rru.RemoteName, rru);
                }
            }
            return(result);
        }