Esempio n. 1
0
        protected override void ParseIndexLine(int ptr, int eol)
        {
            // "index $asha1,$bsha1..$csha1"
            //
            var ids = new List <AbbreviatedObjectId>();

            while (ptr < eol)
            {
                int comma = RawParseUtils.nextLF(Buffer, ptr, (byte)',');
                if (eol <= comma)
                {
                    break;
                }
                ids.Add(AbbreviatedObjectId.FromString(Buffer, ptr, comma - 1));
                ptr = comma;
            }

            _oldIds = new AbbreviatedObjectId[ids.Count + 1];
            ids.CopyTo(_oldIds);
            int dot2 = RawParseUtils.nextLF(Buffer, ptr, (byte)'.');

            _oldIds[_oldIds.Length - 1] = AbbreviatedObjectId.FromString(Buffer, ptr, dot2 - 1);
            NewId     = AbbreviatedObjectId.FromString(Buffer, dot2 + 1, eol - 1);
            _oldModes = new FileMode[_oldIds.Length];
        }
Esempio n. 2
0
        /// <exception cref="System.IO.IOException"></exception>
        private NonNoteEntry MergeNonNotes(NonNoteEntry baseList, NonNoteEntry oursList,
                                           NonNoteEntry theirsList)
        {
            if (baseList == null && oursList == null && theirsList == null)
            {
                return(null);
            }
            ObjectId baseId   = Write(baseList);
            ObjectId oursId   = Write(oursList);
            ObjectId theirsId = Write(theirsList);

            inserter.Flush();
            Merger m = nonNotesMergeStrategy.NewMerger(db, true);

            if (m is ThreeWayMerger)
            {
                ((ThreeWayMerger)m).SetBase(baseId);
            }
            if (!m.Merge(oursId, theirsId))
            {
                throw new NotesMergeConflictException(baseList, oursList, theirsList);
            }
            ObjectId            resultTreeId = m.GetResultTreeId();
            AbbreviatedObjectId none         = AbbreviatedObjectId.FromString(string.Empty);

            return(NoteParser.Parse(none, resultTreeId, reader).nonNotes);
        }
        public void testEmpty_FromString()
        {
            AbbreviatedObjectId i = AbbreviatedObjectId.FromString(string.Empty);

            Assert.IsNotNull(i);
            Assert.AreEqual(0, i.Length);
            Assert.IsFalse(i.isComplete());
            Assert.AreEqual(string.Empty, i.name());
        }
        public void testNotEquals_DiffLength()
        {
            const string        sa = "7b6e8067abcd";
            const string        sb = "7b6e8067";
            AbbreviatedObjectId a  = AbbreviatedObjectId.FromString(sa);
            AbbreviatedObjectId b  = AbbreviatedObjectId.FromString(sb);

            Assert.IsFalse(a.Equals(b));
            Assert.IsFalse(b.Equals(a));
        }
        public void testEquals_Full()
        {
            const string        s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
            AbbreviatedObjectId a = AbbreviatedObjectId.FromString(s);
            AbbreviatedObjectId b = AbbreviatedObjectId.FromString(s);

            Assert.AreNotSame(a, b);
            Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            Assert.IsTrue(a.Equals(b));
            Assert.IsTrue(b.Equals(a));
        }
        public void testEquals_Short()
        {
            const string        s = "7b6e8067";
            AbbreviatedObjectId a = AbbreviatedObjectId.FromString(s);
            AbbreviatedObjectId b = AbbreviatedObjectId.FromString(s);

            Assert.AreNotSame(a, b);
            Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
            Assert.IsTrue(a.Equals(b));
            Assert.IsTrue(b.Equals(a));
        }
        public void test17_FromString()
        {
            const string        s = "7b6e8067ec96acef9";
            AbbreviatedObjectId i = AbbreviatedObjectId.FromString(s);

            Assert.IsNotNull(i);
            Assert.AreEqual(s.Length, i.Length);
            Assert.IsFalse(i.isComplete());
            Assert.AreEqual(s, i.name());
            Assert.IsNull(i.ToObjectId());
        }
Esempio n. 8
0
        internal virtual void ParseIndexLine(int ptr, int end)
        {
            // "index $asha1..$bsha1[ $mode]" where $asha1 and $bsha1
            // can be unique abbreviations
            //
            int dot2 = RawParseUtils.NextLF(buf, ptr, '.');
            int mode = RawParseUtils.NextLF(buf, dot2, ' ');

            oldId = AbbreviatedObjectId.FromString(buf, ptr, IsWindowsLineEnding(dot2) ? dot2 - 2 : dot2 - 1);
            newId = AbbreviatedObjectId.FromString(buf, dot2 + 1, IsWindowsLineEnding(mode) ? mode - 2 : mode - 1);
            if (mode < end)
            {
                newMode = oldMode = ParseFileMode(mode, end);
            }
        }
        public void testFull_FromString()
        {
            const string        s = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
            AbbreviatedObjectId i = AbbreviatedObjectId.FromString(s);

            Assert.IsNotNull(i);
            Assert.AreEqual(s.Length, i.Length);
            Assert.IsTrue(i.isComplete());
            Assert.AreEqual(s, i.name());

            ObjectId f = i.ToObjectId();

            Assert.IsNotNull(f);
            Assert.AreEqual(ObjectId.FromString(s), f);
            Assert.AreEqual(f.GetHashCode(), i.GetHashCode());
        }
Esempio n. 10
0
        protected virtual void ParseIndexLine(int ptr, int end)
        {
            // "index $asha1..$bsha1[ $mode]" where $asha1 and $bsha1
            // can be unique abbreviations
            //
            int dot2 = RawParseUtils.nextLF(Buffer, ptr, (byte)'.');
            int mode = RawParseUtils.nextLF(Buffer, dot2, (byte)' ');

            oldId = AbbreviatedObjectId.FromString(Buffer, ptr, dot2 - 1);
            NewId = AbbreviatedObjectId.FromString(Buffer, dot2 + 1, mode - 1);

            if (mode < end)
            {
                _newMode = _oldMode = ParseFileMode(mode, end);
            }
        }
Esempio n. 11
0
        public void testPrefixCompare_Full()
        {
            const string        s1 = "7b6e8067ec96acef9a4184b43210d583b6d2f99a";
            AbbreviatedObjectId a  = AbbreviatedObjectId.FromString(s1);
            ObjectId            i1 = ObjectId.FromString(s1);

            Assert.AreEqual(0, a.prefixCompare(i1));
            Assert.IsTrue(i1.startsWith(a));

            const string s2 = "7b6e8067ec96acef9a4184b43210d583b6d2f99b";
            ObjectId     i2 = ObjectId.FromString(s2);

            Assert.IsTrue(a.prefixCompare(i2) < 0);
            Assert.IsFalse(i2.startsWith(a));

            const string s3 = "7b6e8067ec96acef9a4184b43210d583b6d2f999";
            ObjectId     i3 = ObjectId.FromString(s3);

            Assert.IsTrue(a.prefixCompare(i3) > 0);
            Assert.IsFalse(i3.startsWith(a));
        }
Esempio n. 12
0
        internal override void ParseIndexLine(int ptr, int eol)
        {
            // "index $asha1,$bsha1..$csha1"
            //
            IList <AbbreviatedObjectId> ids = new AList <AbbreviatedObjectId>();

            while (ptr < eol)
            {
                int comma = RawParseUtils.NextLF(buf, ptr, ',');
                if (eol <= comma)
                {
                    break;
                }
                ids.AddItem(AbbreviatedObjectId.FromString(buf, ptr, comma - 1));
                ptr = comma;
            }
            oldIds = new AbbreviatedObjectId[ids.Count + 1];
            Sharpen.Collections.ToArray(ids, oldIds);
            int dot2 = RawParseUtils.NextLF(buf, ptr, '.');

            oldIds[ids.Count] = AbbreviatedObjectId.FromString(buf, ptr, dot2 - 1);
            newId             = AbbreviatedObjectId.FromString(buf, dot2 + 1, eol - 1);
            oldModes          = new FileMode[oldIds.Length];
        }
Esempio n. 13
0
        /// <exception cref="System.IO.IOException"></exception>
        private IList <RebaseCommand.Step> LoadSteps()
        {
            byte[] buf                   = IOUtil.ReadFully(new FilePath(rebaseDir, GIT_REBASE_TODO));
            int    ptr                   = 0;
            int    tokenBegin            = 0;
            AList <RebaseCommand.Step> r = new AList <RebaseCommand.Step>();

            while (ptr < buf.Length)
            {
                tokenBegin = ptr;
                ptr        = RawParseUtils.NextLF(buf, ptr);
                int nextSpace              = 0;
                int tokenCount             = 0;
                RebaseCommand.Step current = null;
                while (tokenCount < 3 && nextSpace < ptr)
                {
                    switch (tokenCount)
                    {
                    case 0:
                    {
                        nextSpace = RawParseUtils.Next(buf, tokenBegin, ' ');
                        string actionToken = Sharpen.Runtime.GetStringForBytes(buf, tokenBegin, nextSpace
                                                                               - tokenBegin - 1);
                        tokenBegin = nextSpace;
                        if (actionToken[0] == '#')
                        {
                            tokenCount = 3;
                            break;
                        }
                        RebaseCommand.Action action = RebaseCommand.Action.Parse(actionToken);
                        if (action != null)
                        {
                            current = new RebaseCommand.Step(RebaseCommand.Action.Parse(actionToken));
                        }
                        break;
                    }

                    case 1:
                    {
                        if (current == null)
                        {
                            break;
                        }
                        nextSpace = RawParseUtils.Next(buf, tokenBegin, ' ');
                        string commitToken = Sharpen.Runtime.GetStringForBytes(buf, tokenBegin, nextSpace
                                                                               - tokenBegin - 1);
                        tokenBegin     = nextSpace;
                        current.commit = AbbreviatedObjectId.FromString(commitToken);
                        break;
                    }

                    case 2:
                    {
                        if (current == null)
                        {
                            break;
                        }
                        nextSpace = ptr;
                        int length = ptr - tokenBegin;
                        current.shortMessage = new byte[length];
                        System.Array.Copy(buf, tokenBegin, current.shortMessage, 0, length);
                        r.AddItem(current);
                        break;
                    }
                    }
                    tokenCount++;
                }
            }
            return(r);
        }
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void Load(ObjectId rootTree)
        {
            AbbreviatedObjectId none = AbbreviatedObjectId.FromString(string.Empty);

            root = NoteParser.Parse(none, rootTree, reader);
        }