示例#1
0
        private static RefList <global::GitSharp.Core.Ref> toList(params global::GitSharp.Core.Ref[] refs)
        {
            var b = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>(refs.Length);

            b.addAll(refs, 0, refs.Length);
            return(b.toRefList());
        }
示例#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));
        }
示例#3
0
        public void testCopyConstructorReusesArray()
        {
            var one = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>();

            one.add(REF_A);

            var two = new RefList <global::GitSharp.Core.Ref>(one.toRefList());

            one.set(0, REF_B);
            Assert.AreSame(REF_B, two.get(0));
        }
示例#4
0
        public void testBuilder_AddAll()
        {
            var builder = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>(1);

            global::GitSharp.Core.Ref[] src = { REF_A, REF_B, REF_c, REF_A };
            builder.addAll(src, 1, 2);

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

            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_B, list.get(0));
            Assert.AreSame(REF_c, list.get(1));
        }
示例#5
0
        public override IDictionary <string, Ref> getRefs(string prefix)
        {
            RefList <Ref>      packed   = getPackedRefs();
            RefList <LooseRef> oldLoose = looseRefs.get();

            var scan = new LooseScanner(oldLoose, this);

            scan.scan(prefix);

            RefList <LooseRef> loose;

            if (scan.newLoose != null)
            {
                loose = scan.newLoose.toRefList();
                if (looseRefs.compareAndSet(oldLoose, loose))
                {
                    modCnt.incrementAndGet();
                }
            }
            else
            {
                loose = oldLoose;
            }
            fireRefsChanged();

            RefList <Ref> .Builder <Ref> symbolic = scan.symbolic;
            for (int idx = 0; idx < symbolic.size();)
            {
                Ref @ref = symbolic.get(idx);
                @ref = resolve(@ref, 0, prefix, loose, packed);
                if (@ref != null && @ref.getObjectId() != null)
                {
                    symbolic.set(idx, @ref);
                    idx++;
                }
                else
                {
                    // A broken symbolic reference, we have to drop it from the
                    // collections the client is about to receive. Should be a
                    // rare occurrence so pay a copy penalty.
                    loose = loose.remove(idx);
                    symbolic.remove(idx);
                }
            }

            return(new RefMap(prefix, packed, upcast(loose), symbolic.toRefList()));
        }
示例#6
0
 private RefList<global::GitSharp.Core.Ref> toList(params global::GitSharp.Core.Ref[] refs)
 {
     var b = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>(refs.Length);
     b.addAll(refs, 0, refs.Length);
     return b.toRefList();
 }
示例#7
0
        public void testCopyConstructorReusesArray()
        {
            var one = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>();
            one.add(REF_A);

            var two = new RefList<global::GitSharp.Core.Ref>(one.toRefList());
            one.set(0, REF_B);
            Assert.AreSame(REF_B, two.get(0));
        }
示例#8
0
        public void testBuilder_Set()
        {
            var builder = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>();
            builder.add(REF_A);
            builder.add(REF_A);

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

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

            list = builder.toRefList();
            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_A, list.get(0));
            Assert.AreSame(REF_B, list.get(1));
        }
示例#9
0
        public void testBuilder_AddAll()
        {
            var builder = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>(1);
            global::GitSharp.Core.Ref[] src = { REF_A, REF_B, REF_c, REF_A };
            builder.addAll(src, 1, 2);

            RefList<global::GitSharp.Core.Ref> list = builder.toRefList();
            Assert.AreEqual(2, list.size());
            Assert.AreSame(REF_B, list.get(0));
            Assert.AreSame(REF_c, list.get(1));
        }
示例#10
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());
        }