示例#1
0
        private void Execute(ReceiveCommand cmd)
        {
            try
            {
                RefUpdate ru = db.UpdateRef(cmd.getRefName());
                ru.RefLogIdent = getRefLogIdent();
                switch (cmd.getType())
                {
                case ReceiveCommand.Type.DELETE:
                    if (!ObjectId.ZeroId.Equals(cmd.getOldId()))
                    {
                        ru.ExpectedOldObjectId = cmd.getOldId();
                    }
                    ru.IsForceUpdate = true;
                    Status(cmd, ru.Delete(walk));
                    break;

                case ReceiveCommand.Type.CREATE:
                case ReceiveCommand.Type.UPDATE:
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                    ru.IsForceUpdate       = isAllowNonFastForwards();
                    ru.ExpectedOldObjectId = cmd.getOldId();
                    ru.NewObjectId         = cmd.getNewId();
                    ru.SetRefLogMessage("push", true);
                    Status(cmd, ru.Update(walk));
                    break;
                }
            }
            catch (IOException err)
            {
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, "lock error: " + err.Message);
            }
        }
示例#2
0
        private static void Status(ReceiveCommand cmd, RefUpdate.RefUpdateResult result)
        {
            switch (result)
            {
            case RefUpdate.RefUpdateResult.NotAttempted:
                cmd.setResult(ReceiveCommand.Result.NOT_ATTEMPTED);
                break;

            case RefUpdate.RefUpdateResult.LockFailure:
            case RefUpdate.RefUpdateResult.IOFailure:
                cmd.setResult(ReceiveCommand.Result.LOCK_FAILURE);
                break;

            case RefUpdate.RefUpdateResult.NoChange:
            case RefUpdate.RefUpdateResult.New:
            case RefUpdate.RefUpdateResult.Forced:
            case RefUpdate.RefUpdateResult.FastForward:
                cmd.setResult(ReceiveCommand.Result.OK);
                break;

            case RefUpdate.RefUpdateResult.Rejected:
                cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD);
                break;

            case RefUpdate.RefUpdateResult.RejectedCurrentBranch:
                cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH);
                break;

            default:
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, result.ToString());
                break;
            }
        }
示例#3
0
        private void RecvCommands()
        {
            while (true)
            {
                string line;
                try
                {
                    line = pckIn.ReadStringRaw();
                }
                catch (EndOfStreamException)
                {
                    if (commands.isEmpty())
                    {
                        return;
                    }
                    throw;
                }

                if (line == PacketLineIn.END)
                {
                    break;
                }

                if (commands.isEmpty())
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        foreach (string c in line.Substring(nul + 1).Split(' '))
                        {
                            enabledCapabilities.Add(c);
                        }
                        line = line.Slice(0, nul);
                    }
                }

                if (line.Length < 83)
                {
                    string m = "error: invalid protocol: wanted 'old new ref'";
                    sendError(m);
                    throw new PackProtocolException(m);
                }

                ObjectId oldId = ObjectId.FromString(line.Slice(0, 40));
                ObjectId newId = ObjectId.FromString(line.Slice(41, 81));
                string   name  = line.Substring(82);
                var      cmd   = new ReceiveCommand(oldId, newId, name);

                if (name.Equals(Constants.HEAD))
                {
                    cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH);
                }
                else
                {
                    cmd.setRef(refs.get(cmd.getRefName()));
                }

                commands.Add(cmd);
            }
        }
示例#4
0
        private static void Status(ReceiveCommand cmd, RefUpdate.RefUpdateResult result)
        {
            switch (result)
            {
            case RefUpdate.RefUpdateResult.NOT_ATTEMPTED:
                cmd.setResult(ReceiveCommand.Result.NOT_ATTEMPTED);
                break;

            case RefUpdate.RefUpdateResult.LOCK_FAILURE:
            case RefUpdate.RefUpdateResult.IO_FAILURE:
                cmd.setResult(ReceiveCommand.Result.LOCK_FAILURE);
                break;

            case RefUpdate.RefUpdateResult.NO_CHANGE:
            case RefUpdate.RefUpdateResult.NEW:
            case RefUpdate.RefUpdateResult.FORCED:
            case RefUpdate.RefUpdateResult.FAST_FORWARD:
                cmd.setResult(ReceiveCommand.Result.OK);
                break;

            case RefUpdate.RefUpdateResult.REJECTED:
                cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD);
                break;

            case RefUpdate.RefUpdateResult.REJECTED_CURRENT_BRANCH:
                cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH);
                break;

            default:
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, Enum.GetName(typeof(RefUpdate.RefUpdateResult), result));
                break;
            }
        }
示例#5
0
        private void Execute(ReceiveCommand cmd)
        {
            try
            {
                RefUpdate ru = db.UpdateRef(cmd.getRefName());
                ru.setRefLogIdent(getRefLogIdent());
                switch (cmd.getType())
                {
                case ReceiveCommand.Type.DELETE:
                    if (!ObjectId.ZeroId.Equals(cmd.getOldId()))
                    {
                        // We can only do a CAS style delete if the client
                        // didn't bork its delete request by sending the
                        // wrong zero id rather than the advertised one.
                        //
                        ru.setExpectedOldObjectId(cmd.getOldId());
                    }
                    ru.setForceUpdate(true);
                    Status(cmd, ru.delete(walk));
                    break;

                case ReceiveCommand.Type.CREATE:
                case ReceiveCommand.Type.UPDATE:
                case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                    ru.setForceUpdate(isAllowNonFastForwards());
                    ru.setExpectedOldObjectId(cmd.getOldId());
                    ru.setNewObjectId(cmd.getNewId());
                    ru.setRefLogMessage("push", true);
                    Status(cmd, ru.update(walk));
                    break;
                }
            }
            catch (IOException err)
            {
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, "lock error: " + err.Message);
            }
        }
示例#6
0
        private void RecvCommands()
        {
            while (true)
            {
                string line;
                try
                {
                    line = pckIn.ReadStringRaw();
                }
                catch (EndOfStreamException)
                {
                    if (commands.isEmpty())
                    {
                        return;
                    }
                    throw;
                }

                if (commands.isEmpty())
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        foreach (string c in line.Substring(nul + 1).Split(' '))
                        {
                            enabledCapabilities.Add(c);
                        }
                        line = line.Slice(0, nul);
                    }
                }

                if (line.Length == 0) break;
                if (line.Length < 83)
                {
                    string m = "error: invalid protocol: wanted 'old new ref'";
                    sendError(m);
                    throw new PackProtocolException(m);
                }

                ObjectId oldId = ObjectId.FromString(line.Slice(0, 40));
                ObjectId newId = ObjectId.FromString(line.Slice(41, 81));
                string name = line.Substring(82);
                var cmd = new ReceiveCommand(oldId, newId, name);
                cmd.setRef(refs[cmd.getRefName()]);
                commands.Add(cmd);
            }
        }
示例#7
0
 private List<ReceiveCommand> FilterCommands(ReceiveCommand.Result want)
 {
     var r = new List<ReceiveCommand>(commands.Count);
     foreach (ReceiveCommand cmd in commands)
     {
         if (cmd.getResult() == want)
             r.Add(cmd);
     }
     return r;
 }
示例#8
0
        private void Execute(ReceiveCommand cmd)
        {
            try
            {
                RefUpdate ru = db.UpdateRef(cmd.getRefName());
                ru.RefLogIdent = getRefLogIdent();
                switch (cmd.getType())
                {
                    case ReceiveCommand.Type.DELETE:
                        if (!ObjectId.ZeroId.Equals(cmd.getOldId()))
                        {
                            ru.ExpectedOldObjectId = cmd.getOldId();
                        }
                        ru.IsForceUpdate = true;
                        Status(cmd, ru.Delete(walk));
                        break;

                    case ReceiveCommand.Type.CREATE:
                    case ReceiveCommand.Type.UPDATE:
                    case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                        ru.IsForceUpdate = isAllowNonFastForwards();
                        ru.ExpectedOldObjectId = cmd.getOldId();
                        ru.NewObjectId = cmd.getNewId();
                        ru.SetRefLogMessage("push", true);
                        Status(cmd, ru.Update(walk));
                        break;
                }
            }
            catch (IOException err)
            {
                cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, "lock error: " + err.Message);
            }
        }
示例#9
0
        private static void Status(ReceiveCommand cmd, RefUpdate.RefUpdateResult result)
        {
            switch (result)
            {
                case RefUpdate.RefUpdateResult.NotAttempted:
                    cmd.setResult(ReceiveCommand.Result.NOT_ATTEMPTED);
                    break;

                case RefUpdate.RefUpdateResult.LockFailure:
                case RefUpdate.RefUpdateResult.IOFailure:
                    cmd.setResult(ReceiveCommand.Result.LOCK_FAILURE);
                    break;

                case RefUpdate.RefUpdateResult.NoChange:
                case RefUpdate.RefUpdateResult.New:
                case RefUpdate.RefUpdateResult.Forced:
                case RefUpdate.RefUpdateResult.FastForward:
                    cmd.setResult(ReceiveCommand.Result.OK);
                    break;

                case RefUpdate.RefUpdateResult.Rejected:
                    cmd.setResult(ReceiveCommand.Result.REJECTED_NONFASTFORWARD);
                    break;

                case RefUpdate.RefUpdateResult.RejectedCurrentBranch:
                    cmd.setResult(ReceiveCommand.Result.REJECTED_CURRENT_BRANCH);
                    break;

                default:
                    cmd.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, result.ToString());
                    break;
            }
        }