Exemple #1
0
        public void testBuilder_Remove()
        {
            var builder = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>();

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

            Assert.AreEqual(1, builder.size());
            Assert.AreSame(REF_B, builder.get(0));
        }
Exemple #2
0
        public void testBuilder_ToString()
        {
            var exp = new StringBuilder();

            exp.Append("[");
            exp.Append(REF_A);
            exp.Append(", ");
            exp.Append(REF_B);
            exp.Append("]");

            var list = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>();

            list.add(REF_A);
            list.add(REF_B);
            Assert.AreEqual(exp.ToString(), list.ToString());
        }
            public void scan(string prefix)
            {
                if (ALL.Equals(prefix))
                {
                    scanOne(Constants.HEAD);
                    scanTree(Constants.R_REFS, _refDirectory.refsDir);

                    // If any entries remain, they are deleted, drop them.
                    if (newLoose == null && curIdx < curLoose.size())
                    {
                        newLoose = curLoose.copy(curIdx);
                    }
                }
                else if (prefix.StartsWith(Constants.R_REFS) && prefix.EndsWith("/"))
                {
                    curIdx = -(curLoose.find(prefix) + 1);
                    DirectoryInfo dir = PathUtil.CombineDirectoryPath(_refDirectory.refsDir, prefix.Substring(Constants.R_REFS.Length));
                    scanTree(prefix, dir);

                    // Skip over entries still within the prefix; these have
                    // been removed from the directory.
                    while (curIdx < curLoose.size())
                    {
                        if (!curLoose.get(curIdx).getName().StartsWith(prefix))
                        {
                            break;
                        }
                        if (newLoose == null)
                        {
                            newLoose = curLoose.copy(curIdx);
                        }
                        curIdx++;
                    }

                    // Keep any entries outside of the prefix space, we
                    // do not know anything about their status.
                    if (newLoose != null)
                    {
                        while (curIdx < curLoose.size())
                        {
                            newLoose.add(curLoose.get(curIdx++));
                        }
                    }
                }
            }
Exemple #4
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));
        }
Exemple #5
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));
        }
Exemple #6
0
        public void testAddToEmptyList()
        {
            RefList <global::GitSharp.Core.Ref> one = toList();
            RefList <global::GitSharp.Core.Ref> two = one.add(0, REF_B);

            Assert.AreNotSame(one, two);

            // one is not modified, but two is
            Assert.AreEqual(0, one.size());
            Assert.AreEqual(1, two.size());
            Assert.IsFalse(two.isEmpty());
            Assert.AreSame(REF_B, two.get(0));
        }
Exemple #7
0
        public void testAddToEndOfList()
        {
            RefList <global::GitSharp.Core.Ref> one = toList(REF_A);
            RefList <global::GitSharp.Core.Ref> two = one.add(1, REF_B);

            Assert.AreNotSame(one, two);

            // one is not modified, but two is
            Assert.AreEqual(1, one.size());
            Assert.AreSame(REF_A, one.get(0));
            Assert.AreEqual(2, two.size());
            Assert.AreSame(REF_A, two.get(0));
            Assert.AreSame(REF_B, two.get(1));
        }
Exemple #8
0
        public void testAddToMiddleOfListByInsertionPosition()
        {
            RefList <global::GitSharp.Core.Ref> one = toList(REF_A, REF_c);

            Assert.AreEqual(-2, one.find(REF_B.Name));

            RefList <global::GitSharp.Core.Ref> two = one.add(one.find(REF_B.Name), REF_B);

            Assert.AreNotSame(one, two);

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

            Assert.AreEqual(3, two.size());
            Assert.AreSame(REF_A, two.get(0));
            Assert.AreSame(REF_B, two.get(1));
            Assert.AreSame(REF_c, two.get(2));
        }
        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);
        }
Exemple #10
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));
        }
Exemple #11
0
        public void testBuilder_ToString()
        {
            var exp = new StringBuilder();
            exp.Append("[");
            exp.Append(REF_A);
            exp.Append(", ");
            exp.Append(REF_B);
            exp.Append("]");

            var list = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>();
            list.add(REF_A);
            list.add(REF_B);
            Assert.AreEqual(exp.ToString(), list.ToString());
        }
Exemple #12
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));
        }
Exemple #13
0
        public void testBuilder_Remove()
        {
            var builder = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>();
            builder.add(REF_A);
            builder.add(REF_B);
            builder.remove(0);

            Assert.AreEqual(1, builder.size());
            Assert.AreSame(REF_B, builder.get(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());
        }
            private void scanOne(string name)
            {
                LooseRef cur;

                if (curIdx < curLoose.size())
                {
                    do
                    {
                        cur = curLoose.get(curIdx);
                        int cmp = RefComparator.compareTo(cur, name);
                        if (cmp < 0)
                        {
                            // Reference is not loose anymore, its been deleted.
                            // Skip the name in the new result list.
                            if (newLoose == null)
                            {
                                newLoose = curLoose.copy(curIdx);
                            }
                            curIdx++;
                            cur = null;
                            continue;
                        }

                        if (cmp > 0) // Newly discovered loose reference.
                        {
                            cur = null;
                        }
                        break;
                    } while (curIdx < curLoose.size());
                }
                else
                {
                    cur = null; // Newly discovered loose reference.
                }
                LooseRef n;

                try
                {
                    n = _refDirectory.scanRef(cur, name);
                }
                catch (IOException)
                {
                    n = null;
                }

                if (n != null)
                {
                    if (cur != n && newLoose == null)
                    {
                        newLoose = curLoose.copy(curIdx);
                    }
                    if (newLoose != null)
                    {
                        newLoose.add(n);
                    }
                    if (n.isSymbolic())
                    {
                        symbolic.add(n);
                    }
                }
                else if (cur != null)
                {
                    // Tragically, this file is no longer a loose reference.
                    // Kill our cached entry of it.
                    if (newLoose == null)
                    {
                        newLoose = curLoose.copy(curIdx);
                    }
                }

                if (cur != null)
                {
                    curIdx++;
                }
            }