Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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()));
        }
Ejemplo n.º 3
0
        public void testSet()
        {
            RefList <global::GitSharp.Core.Ref> one = toList(REF_A, REF_A);
            RefList <global::GitSharp.Core.Ref> two = one.set(1, REF_B);

            Assert.AreNotSame(one, two);

            // one is not modified
            Assert.AreEqual(2, one.size());
            Assert.AreSame(REF_A, one.get(0));
            Assert.AreSame(REF_A, one.get(1));

            // but two is
            Assert.AreEqual(2, two.size());
            Assert.AreSame(REF_A, one.get(0));
            Assert.AreSame(REF_B, two.get(1));
        }
Ejemplo n.º 4
0
        public override Ref peel(Ref @ref)
        {
            Ref leaf = @ref.getLeaf();

            if (leaf.isPeeled() || leaf.getObjectId() == null)
            {
                return(@ref);
            }

            RevWalk.RevWalk rw  = new RevWalk.RevWalk(getRepository());
            RevObject       obj = rw.parseAny(leaf.getObjectId());
            ObjectIdRef     newLeaf;

            if (obj is RevTag)
            {
                do
                {
                    obj = rw.parseAny(((RevTag)obj).getObject());
                } while (obj is RevTag);

                newLeaf = new PeeledTag(leaf.getStorage(), leaf
                                        .getName(), leaf.getObjectId(), obj.Copy());
            }
            else
            {
                newLeaf = new PeeledNonTag(leaf.getStorage(), leaf
                                           .getName(), leaf.getObjectId());
            }

            // Try to remember this peeling in the cache, so we don't have to do
            // it again in the future, but only if the reference is unchanged.
            if (leaf.getStorage().IsLoose)
            {
                RefList <LooseRef> curList = looseRefs.get();
                int idx = curList.find(leaf.getName());
                if (0 <= idx && curList.get(idx) == leaf)
                {
                    LooseRef           asPeeled = ((LooseRef)leaf).peel(newLeaf);
                    RefList <LooseRef> newList  = curList.set(idx, asPeeled);
                    looseRefs.compareAndSet(curList, newList);
                }
            }

            return(recreate(@ref, newLeaf));
        }
Ejemplo n.º 5
0
        private Ref readRef(string name, RefList <Ref> packed)
        {
            RefList <LooseRef> curList = looseRefs.get();
            int idx = curList.find(name);

            if (0 <= idx)
            {
                LooseRef o = curList.get(idx);
                LooseRef n = scanRef(o, name);
                if (n == null)
                {
                    if (looseRefs.compareAndSet(curList, curList.remove(idx)))
                    {
                        modCnt.incrementAndGet();
                    }
                    return(packed.get(name));
                }

                if (o == n)
                {
                    return(n);
                }
                if (looseRefs.compareAndSet(curList, curList.set(idx, n)))
                {
                    modCnt.incrementAndGet();
                }
                return(n);
            }

            LooseRef n2 = scanRef(null, name);

            if (n2 == null)
            {
                return(packed.get(name));
            }
            if (looseRefs.compareAndSet(curList, curList.add(idx, n2)))
            {
                modCnt.incrementAndGet();
            }
            return(n2);
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 9
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());
        }