Esempio n. 1
0
        public void testBuilder_AddThenSort()
        {
            var builder = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>(1);

            builder.add(REF_B);
            builder.add(REF_A);

            RefList <global::GitSharp.Core.Ref> list = builder.toRefList();

            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_B, list.get(0));
            Assert.AreSame(REF_A, list.get(1));

            builder.sort();
            list = builder.toRefList();
            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_A, list.get(0));
            Assert.AreSame(REF_B, list.get(1));
        }
Esempio n. 2
0
        public void testBuilder_AddThenSort()
        {
            var builder = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>(1);
            builder.add(REF_B);
            builder.add(REF_A);

            RefList<global::GitSharp.Core.Ref> list = builder.toRefList();
            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_B, list.get(0));
            Assert.AreSame(REF_A, list.get(1));

            builder.sort();
            list = builder.toRefList();
            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_A, list.get(0));
            Assert.AreSame(REF_B, list.get(1));
        }
Esempio n. 3
0
        private static RefList <Ref> parsePackedRefs(TextReader br)
        {
            var all = new RefList <Ref> .Builder <Ref>();

            Ref  last     = null;
            bool peeled   = false;
            bool needSort = false;

            string p;

            while ((p = br.ReadLine()) != null)
            {
                if (p[0] == '#')
                {
                    if (p.StartsWith(PACKED_REFS_HEADER))
                    {
                        p      = p.Substring(PACKED_REFS_HEADER.Length);
                        peeled = p.Contains(PACKED_REFS_PEELED);
                    }
                    continue;
                }

                if (p[0] == '^')
                {
                    if (last == null)
                    {
                        throw new IOException("Peeled line before ref.");
                    }

                    ObjectId id = ObjectId.FromString(p.Substring(1));
                    last = new PeeledTag(Storage.Packed, last.getName(), last
                                         .getObjectId(), id);
                    all.set(all.size() - 1, last);
                    continue;
                }

                int         sp   = p.IndexOf(' ');
                ObjectId    id2  = ObjectId.FromString(p.Slice(0, sp));
                string      name = copy(p, sp + 1, p.Length);
                ObjectIdRef cur;
                if (peeled)
                {
                    cur = new PeeledNonTag(Storage.Packed, name, id2);
                }
                else
                {
                    cur = new Unpeeled(Storage.Packed, name, id2);
                }
                if (last != null && RefComparator.compareTo(last, cur) > 0)
                {
                    needSort = true;
                }
                all.add(cur);
                last = cur;
            }

            if (needSort)
            {
                all.sort();
            }
            return(all.toRefList());
        }