/// <exception cref="System.IO.IOException"></exception>
        private RefList <Ref> ParsePackedRefs(BufferedReader br)
        {
            RefListBuilder <Ref> all = new RefListBuilder <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      = Sharpen.Runtime.Substring(p, PACKED_REFS_HEADER.Length);
                        peeled = p.Contains(PACKED_REFS_PEELED);
                    }
                    continue;
                }
                if (p[0] == '^')
                {
                    if (last == null)
                    {
                        throw new IOException(JGitText.Get().peeledLineBeforeRef);
                    }
                    ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(p, 1));
                    last = new ObjectIdRef.PeeledTag(RefStorage.PACKED, last.GetName(), last.GetObjectId
                                                         (), id);
                    all.Set(all.Size() - 1, last);
                    continue;
                }
                int         sp   = p.IndexOf(' ');
                ObjectId    id_1 = ObjectId.FromString(Sharpen.Runtime.Substring(p, 0, sp));
                string      name = Copy(p, sp + 1, p.Length);
                ObjectIdRef cur;
                if (peeled)
                {
                    cur = new ObjectIdRef.PeeledNonTag(RefStorage.PACKED, name, id_1);
                }
                else
                {
                    cur = new ObjectIdRef.Unpeeled(RefStorage.PACKED, name, id_1);
                }
                if (last != null && RefComparator.CompareTo(last, cur) > 0)
                {
                    needSort = true;
                }
                all.Add(cur);
                last = cur;
            }
            if (needSort)
            {
                all.Sort();
            }
            return(all.ToRefList());
        }
        /// <exception cref="System.IO.IOException"></exception>
        public override IDictionary <string, Ref> GetRefs(string prefix)
        {
            RefList <Ref> packed = GetPackedRefs();
            RefList <RefDirectory.LooseRef> oldLoose = looseRefs.Get();

            RefDirectory.LooseScanner scan = new RefDirectory.LooseScanner(this, oldLoose);
            scan.Scan(prefix);
            RefList <RefDirectory.LooseRef> loose;

            if (scan.newLoose != null)
            {
                scan.newLoose.Sort();
                loose = scan.newLoose.ToRefList();
                if (looseRefs.CompareAndSet(oldLoose, loose))
                {
                    modCnt.IncrementAndGet();
                }
            }
            else
            {
                loose = oldLoose;
            }
            FireRefsChanged();
            RefListBuilder <Ref> symbolic = scan.symbolic;

            for (int idx = 0; idx < symbolic.Size();)
            {
                Ref symbolicRef = symbolic.Get(idx);
                Ref resolvedRef = Resolve(symbolicRef, 0, prefix, loose, packed);
                if (resolvedRef != null && resolvedRef.GetObjectId() != null)
                {
                    symbolic.Set(idx, resolvedRef);
                    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.
                    symbolic.Remove(idx);
                    int toRemove = loose.Find(symbolicRef.GetName());
                    if (0 <= toRemove)
                    {
                        loose = loose.Remove(toRemove);
                    }
                }
            }
            symbolic.Sort();
            return(new RefMap(prefix, packed, Upcast(loose), symbolic.ToRefList()));
        }
Пример #3
0
		public virtual void TestEmptyBuilder()
		{
			RefList<Ref> list = new RefListBuilder<Ref>().ToRefList();
			NUnit.Framework.Assert.AreEqual(0, list.Size());
			NUnit.Framework.Assert.IsFalse(list.Iterator().HasNext());
			NUnit.Framework.Assert.AreEqual(-1, list.Find("a"));
			NUnit.Framework.Assert.AreEqual(-1, list.Find("z"));
			NUnit.Framework.Assert.IsFalse(list.Contains("a"));
			NUnit.Framework.Assert.IsNull(list.Get("a"));
			NUnit.Framework.Assert.IsTrue(list.AsList().IsEmpty());
			NUnit.Framework.Assert.AreEqual("[]", list.ToString());
			// default array capacity should be 16, with no bounds checking.
			NUnit.Framework.Assert.IsNull(list.Get(16 - 1));
			try
			{
				list.Get(16);
				NUnit.Framework.Assert.Fail("default RefList should have 16 element array");
			}
			catch (IndexOutOfRangeException)
			{
			}
		}
Пример #4
0
		public virtual void TestBuilder_Remove()
		{
			RefListBuilder<Ref> builder = new RefListBuilder<Ref>();
			builder.Add(REF_A);
			builder.Add(REF_B);
			builder.Remove(0);
			NUnit.Framework.Assert.AreEqual(1, builder.Size());
			NUnit.Framework.Assert.AreSame(REF_B, builder.Get(0));
		}
Пример #5
0
		public virtual void TestBuilder_Set()
		{
			RefListBuilder<Ref> builder = new RefListBuilder<Ref>();
			builder.Add(REF_A);
			builder.Add(REF_A);
			NUnit.Framework.Assert.AreEqual(2, builder.Size());
			NUnit.Framework.Assert.AreSame(REF_A, builder.Get(0));
			NUnit.Framework.Assert.AreSame(REF_A, builder.Get(1));
			RefList<Ref> list = builder.ToRefList();
			NUnit.Framework.Assert.AreEqual(2, list.Size());
			NUnit.Framework.Assert.AreSame(REF_A, list.Get(0));
			NUnit.Framework.Assert.AreSame(REF_A, list.Get(1));
			builder.Set(1, REF_B);
			list = builder.ToRefList();
			NUnit.Framework.Assert.AreEqual(2, list.Size());
			NUnit.Framework.Assert.AreSame(REF_A, list.Get(0));
			NUnit.Framework.Assert.AreSame(REF_B, list.Get(1));
		}