ReadString() public method

public ReadString ( ) : string
return string
Beispiel #1
0
        private void RecvWants()
        {
            bool isFirst = true;

            for (; ; isFirst = false)
            {
                string line;
                try
                {
                    line = _pckIn.ReadString();
                }
                catch (EndOfStreamException)
                {
                    if (isFirst)
                    {
                        break;
                    }
                    throw;
                }

                if (line == PacketLineIn.END)
                {
                    break;
                }
                if (!line.StartsWith("want ") || line.Length < 45)
                {
                    throw new PackProtocolException("expected want; got " + line);
                }

                if (isFirst && line.Length > 45)
                {
                    string opt = line.Substring(45);
                    if (opt.StartsWith(" "))
                    {
                        opt = opt.Substring(1);
                    }
                    foreach (string c in opt.Split(' '))
                    {
                        _options.Add(c);
                    }
                    line = line.Slice(0, 45);
                }

                ObjectId  id = ObjectId.FromString(line.Substring(5));
                RevObject o;
                try
                {
                    o = _walk.parseAny(id);
                }
                catch (IOException e)
                {
                    throw new PackProtocolException(id.Name + " not valid", e);
                }
                if (!o.has(ADVERTISED))
                {
                    throw new PackProtocolException(id.Name + " not valid");
                }

                Want(o);
            }
        }
Beispiel #2
0
        private void RecvWants()
        {
            bool isFirst = true;

            for (; ; isFirst = false)
            {
                string line;
                try
                {
                    line = _pckIn.ReadString();
                }
                catch (EndOfStreamException)
                {
                    if (isFirst)
                    {
                        break;
                    }
                    throw;
                }

                if (line.Length == 0)
                {
                    break;
                }
                if (!line.StartsWith("want ") || line.Length < 45)
                {
                    throw new PackProtocolException("expected want; got " + line);
                }

                if (isFirst)
                {
                    int sp = line.IndexOf(' ', 45);
                    if (sp >= 0)
                    {
                        foreach (string c in line.Substring(sp + 1).Split(' '))
                        {
                            _options.Add(c);
                        }
                        line = line.Slice(0, sp);
                    }
                }

                string    name = line.Substring(5);
                ObjectId  id   = ObjectId.FromString(name);
                RevObject o;
                try
                {
                    o = _walk.parseAny(id);
                }
                catch (IOException e)
                {
                    throw new PackProtocolException(name + " not valid", e);
                }
                if (!o.has(ADVERTISED))
                {
                    throw new PackProtocolException(name + " not valid");
                }

                Want(o);
            }
        }
Beispiel #3
0
        private void readAdvertisedRefsImpl()
        {
            var avail = new Dictionary <string, Ref>();

            while (true)
            {
                string line;

                try
                {
                    line = pckIn.ReadString();
                }
                catch (EndOfStreamException)
                {
                    if (avail.Count == 0)
                    {
                        throw noRepository();
                    }

                    throw;
                }

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

                if (avail.Count == 0)
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        // The first line (if any) may contain "hidden"
                        // capability values after a NUL byte.
                        foreach (string c in line.Substring(nul + 1).Split(' '))
                        {
                            remoteCapabilies.Add(c);
                        }
                        line = line.Slice(0, nul);
                    }
                }

                string name = line.Slice(41, line.Length);
                if (avail.Count == 0 && name.Equals("capabilities^{}"))
                {
                    // special line from git-receive-pack to show
                    // capabilities when there are no refs to advertise
                    continue;
                }

                ObjectId id = ObjectId.FromString(line.Slice(0, 40));
                if (name.Equals(".have"))
                {
                    additionalHaves.Add(id);
                }
                else if (name.EndsWith("^{}"))
                {
                    name = name.Slice(0, name.Length - 3);
                    Ref prior = avail.get(name);
                    if (prior == null)
                    {
                        throw new PackProtocolException(uri, "advertisement of " + name + "^{} came before " + name);
                    }

                    if (prior.PeeledObjectId != null)
                    {
                        throw duplicateAdvertisement(name + "^{}");
                    }

                    avail.put(name, new PeeledTag(Storage.Network, name, prior.ObjectId, id));
                }
                else
                {
                    Ref prior = avail.put(name, new PeeledNonTag(Storage.Network, name, id));
                    if (prior != null)
                    {
                        throw duplicateAdvertisement(name);
                    }
                }
            }
            available(avail);
        }
Beispiel #4
0
        private void readAdvertisedRefsImpl()
        {
            var avail = new Dictionary <string, Ref>();

            while (true)
            {
                string line;

                try
                {
                    line = pckIn.ReadString();
                }
                catch (EndOfStreamException)
                {
                    if (avail.Count == 0)
                    {
                        throw noRepository();
                    }

                    throw;
                }

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

                if (line.Length == 0)
                {
                    break;
                }

                string name = line.Slice(41, line.Length);
                if (avail.Count == 0 && name.Equals("capabilities^{}"))
                {
                    continue;
                }

                string   idname = line.Slice(0, 40);
                ObjectId id     = ObjectId.FromString(idname);
                if (name.Equals(".have"))
                {
                    additionalHaves.Add(id);
                }
                else if (name.EndsWith("^{}"))
                {
                    name = name.Slice(0, name.Length - 3);
                    Ref prior = avail.ContainsKey(name) ? avail[name] : null;
                    if (prior == null)
                    {
                        throw new PackProtocolException(uri, "advertisement of " + name + "^{} came before " + name);
                    }

                    if (prior.PeeledObjectId != null)
                    {
                        throw duplicateAdvertisement(name + "^{}");
                    }

                    avail[name] = new Ref(Ref.Storage.Network, name, prior.ObjectId, id, true);
                }
                else
                {
                    Ref prior = avail.ContainsKey(name) ? avail[name] : null;
                    if (prior != null)
                    {
                        throw duplicateAdvertisement(name);
                    }
                    avail.Add(name, new Ref(Ref.Storage.Network, name, id));
                }
            }
            available(avail);
        }