Beispiel #1
0
        public void testConstructor_PeeledStatusNotKnown()
        {
            ObjectIdRef r;

            r = new Unpeeled(Storage.Loose, name, ID_A);
            Assert.AreSame(Storage.Loose, r.getStorage());
            Assert.AreSame(name, r.getName());
            Assert.AreSame(ID_A, r.getObjectId());
            Assert.IsFalse(r.isPeeled(), "not peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");
            Assert.AreSame(r, r.getLeaf(), "leaf is this");
            Assert.AreSame(r, r.getTarget(), "target is this");
            Assert.IsFalse(r.isSymbolic(), "not symbolic");

            r = new Unpeeled(Storage.Packed, name, ID_A);
            Assert.AreSame(Storage.Packed, r.getStorage());

            r = new Unpeeled(Storage.LoosePacked, name, ID_A);
            Assert.AreSame(Storage.LoosePacked, r.getStorage());

            r = new Unpeeled(Storage.New, name, null);
            Assert.AreSame(Storage.New, r.getStorage());
            Assert.AreSame(name, r.getName());
            Assert.IsNull(r.getObjectId(), "no id on new ref");
            Assert.IsFalse(r.isPeeled(), "not peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");
            Assert.AreSame(r, r.getLeaf(), "leaf is this");
            Assert.AreSame(r, r.getTarget(), "target is this");
            Assert.IsFalse(r.isSymbolic(), "not symbolic");
        }
Beispiel #2
0
            private Ref ReadRef(IDictionary <string, Ref> avail, string path, string name)
            {
                string line;

                try
                {
                    using (StreamReader br = openReader(path))
                    {
                        line = br.ReadLine();
                    }
                }
                catch (FileNotFoundException)
                {
                    return(null);
                }
                catch (IOException err)
                {
                    throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err);
                }

                if (line == null)
                {
                    throw new TransportException("Empty ref: " + name);
                }

                if (line.StartsWith("ref: "))
                {
                    string target = line.Substring("ref: ".Length);
                    Ref    r      = avail.GetValue(target);
                    if (r == null)
                    {
                        r = ReadRef(avail, ROOT_DIR + target, target);
                    }
                    if (r == null)
                    {
                        r = new Unpeeled(Storage.New, target, null);
                    }
                    r = new SymbolicRef(name, r);
                    avail.put(r.getName(), r);
                    return(r);
                }

                if (ObjectId.IsId(line))
                {
                    Ref r = new Unpeeled(Loose(avail.GetValue(name)),
                                         name, ObjectId.FromString(line));
                    avail.put(r.getName(), r);
                    return(r);
                }

                throw new TransportException("Bad ref: " + name + ": " + line);
            }
Beispiel #3
0
        public void testConstructor_Peeled()
        {
            ObjectIdRef r;

            r = new Unpeeled(Storage.Loose, name, ID_A);
            Assert.AreSame(Storage.Loose, r.getStorage());
            Assert.AreSame(name, r.getName());
            Assert.AreSame(ID_A, r.getObjectId());
            Assert.IsFalse(r.isPeeled(), "not peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");
            Assert.AreSame(r, r.getLeaf(), "leaf is this");
            Assert.AreSame(r, r.getTarget(), "target is this");
            Assert.IsFalse(r.isSymbolic(), "not symbolic");

            r = new PeeledNonTag(Storage.Loose, name, ID_A);
            Assert.IsTrue(r.isPeeled(), "is peeled");
            Assert.IsNull(r.getPeeledObjectId(), "no peel id");

            r = new PeeledTag(Storage.Loose, name, ID_A, ID_B);
            Assert.IsTrue(r.isPeeled(), "is peeled");
            Assert.AreSame(ID_B, r.getPeeledObjectId());
        }
Beispiel #4
0
            private Ref ReadRef(IDictionary<string, Ref> avail, string path, string name)
            {
                string line;
                try
                {
                    using (StreamReader br = openReader(path))
                    {
                        line = br.ReadLine();
                    }
                }
                catch (FileNotFoundException)
                {
                    return null;
                }
                catch (IOException err)
                {
                    throw new TransportException("Cannot Read " + _objectsPath + "/" + path + ": " + err.Message, err);
                }

                if (line == null)
                    throw new TransportException("Empty ref: " + name);

                if (line.StartsWith("ref: "))
                {
                    string target = line.Substring("ref: ".Length);
                    Ref r = avail.GetValue(target);
                    if (r == null)
                        r = ReadRef(avail, ROOT_DIR + target, target);
                    if (r == null)
                        r = new Unpeeled(Storage.New, target, null);
                    r = new SymbolicRef(name, r);
                    avail.put(r.getName(), r);
                    return r;
                }

                if (ObjectId.IsId(line))
                {
                    Ref r = new Unpeeled(Loose(avail.GetValue(name)),
                            name, ObjectId.FromString(line));
                    avail.put(r.getName(), r);
                    return r;
                }

                throw new TransportException("Bad ref: " + name + ": " + line);
            }