コード例 #1
0
        public virtual void TestBreakModify_RejoinIfUnpaired()
        {
            ObjectId  aId = Blob("foo");
            ObjectId  bId = Blob("bar");
            DiffEntry m   = DiffEntry.Modify(PATH_A);

            m.oldId = AbbreviatedObjectId.FromObjectId(aId);
            m.newId = AbbreviatedObjectId.FromObjectId(bId);
            rd.Add(m);
            rd.SetBreakScore(101);
            // Ensure m is broken apart
            IList <DiffEntry> entries = rd.Compute();

            NUnit.Framework.Assert.AreEqual(1, entries.Count);
            DiffEntry modify = entries[0];

            NUnit.Framework.Assert.AreEqual(m.oldPath, modify.oldPath);
            NUnit.Framework.Assert.AreEqual(m.oldId, modify.oldId);
            NUnit.Framework.Assert.AreEqual(m.oldMode, modify.oldMode);
            NUnit.Framework.Assert.AreEqual(m.newPath, modify.newPath);
            NUnit.Framework.Assert.AreEqual(m.newId, modify.newId);
            NUnit.Framework.Assert.AreEqual(m.newMode, modify.newMode);
            NUnit.Framework.Assert.AreEqual(m.changeType, modify.changeType);
            NUnit.Framework.Assert.AreEqual(0, modify.score);
        }
コード例 #2
0
 internal static NGit.Diff.DiffEntry Delete(string path, AnyObjectId id)
 {
     NGit.Diff.DiffEntry e = new NGit.Diff.DiffEntry();
     e.oldId      = AbbreviatedObjectId.FromObjectId(id);
     e.oldMode    = FileMode.REGULAR_FILE;
     e.oldPath    = path;
     e.newId      = A_ZERO;
     e.newMode    = FileMode.MISSING;
     e.newPath    = DEV_NULL;
     e.changeType = DiffEntry.ChangeType.DELETE;
     return(e);
 }
コード例 #3
0
 private static void AssertAdd(string newName, ObjectId newId, FileMode newMode, DiffEntry
                               add)
 {
     NUnit.Framework.Assert.AreEqual(DiffEntry.DEV_NULL, add.oldPath);
     NUnit.Framework.Assert.AreEqual(DiffEntry.A_ZERO, add.oldId);
     NUnit.Framework.Assert.AreEqual(FileMode.MISSING, add.oldMode);
     NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.ADD, add.changeType);
     NUnit.Framework.Assert.AreEqual(newName, add.newPath);
     NUnit.Framework.Assert.AreEqual(AbbreviatedObjectId.FromObjectId(newId), add.newId
                                     );
     NUnit.Framework.Assert.AreEqual(newMode, add.newMode);
 }
コード例 #4
0
ファイル: DiffEntry.cs プロジェクト: shoff/ngit
        // reduce the visibility of the default constructor
        /// <summary>Convert the TreeWalk into DiffEntry headers.</summary>
        /// <remarks>Convert the TreeWalk into DiffEntry headers.</remarks>
        /// <param name="walk">the TreeWalk to walk through. Must have exactly two trees.</param>
        /// <returns>headers describing the changed files.</returns>
        /// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
        public static IList <NGit.Diff.DiffEntry> Scan(TreeWalk walk)
        {
            IList <NGit.Diff.DiffEntry> r     = new AList <NGit.Diff.DiffEntry>();
            MutableObjectId             idBuf = new MutableObjectId();

            while (walk.Next())
            {
                NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
                walk.GetObjectId(idBuf, 0);
                entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
                walk.GetObjectId(idBuf, 1);
                entry.newId   = AbbreviatedObjectId.FromObjectId(idBuf);
                entry.oldMode = walk.GetFileMode(0);
                entry.newMode = walk.GetFileMode(1);
                entry.newPath = entry.oldPath = walk.PathString;
                if (entry.oldMode == FileMode.MISSING)
                {
                    entry.oldPath    = NGit.Diff.DiffEntry.DEV_NULL;
                    entry.changeType = DiffEntry.ChangeType.ADD;
                    r.AddItem(entry);
                }
                else
                {
                    if (entry.newMode == FileMode.MISSING)
                    {
                        entry.newPath    = NGit.Diff.DiffEntry.DEV_NULL;
                        entry.changeType = DiffEntry.ChangeType.DELETE;
                        r.AddItem(entry);
                    }
                    else
                    {
                        entry.changeType = DiffEntry.ChangeType.MODIFY;
                        if (RenameDetector.SameType(entry.oldMode, entry.newMode))
                        {
                            r.AddItem(entry);
                        }
                        else
                        {
                            Sharpen.Collections.AddAll(r, BreakModify(entry));
                        }
                    }
                }
            }
            return(r);
        }
コード例 #5
0
        public virtual void TestExactRename_OneRenameOneModify()
        {
            ObjectId  foo = Blob("foo");
            ObjectId  bar = Blob("bar");
            DiffEntry a   = DiffEntry.Add(PATH_A, foo);
            DiffEntry b   = DiffEntry.Delete(PATH_Q, foo);
            DiffEntry c   = DiffEntry.Modify(PATH_H);

            c.newId = c.oldId = AbbreviatedObjectId.FromObjectId(bar);
            rd.Add(a);
            rd.Add(b);
            rd.Add(c);
            IList <DiffEntry> entries = rd.Compute();

            NUnit.Framework.Assert.AreEqual(2, entries.Count);
            AssertRename(b, a, 100, entries[0]);
            NUnit.Framework.Assert.AreSame(c, entries[1]);
        }
コード例 #6
0
        public virtual void TestBreakModify_BreakNone()
        {
            ObjectId  aId = Blob("foo");
            ObjectId  bId = Blob("bar");
            DiffEntry m   = DiffEntry.Modify(PATH_A);

            m.oldId = AbbreviatedObjectId.FromObjectId(aId);
            m.newId = AbbreviatedObjectId.FromObjectId(bId);
            DiffEntry a = DiffEntry.Add(PATH_B, aId);

            rd.Add(a);
            rd.Add(m);
            rd.SetBreakScore(-1);
            IList <DiffEntry> entries = rd.Compute();

            NUnit.Framework.Assert.AreEqual(2, entries.Count);
            NUnit.Framework.Assert.AreSame(m, entries[0]);
            NUnit.Framework.Assert.AreSame(a, entries[1]);
        }
コード例 #7
0
        public virtual void TestBreakModify_BreakAll()
        {
            ObjectId  aId = Blob("foo");
            ObjectId  bId = Blob("bar");
            DiffEntry m   = DiffEntry.Modify(PATH_A);

            m.oldId = AbbreviatedObjectId.FromObjectId(aId);
            m.newId = AbbreviatedObjectId.FromObjectId(bId);
            DiffEntry a = DiffEntry.Add(PATH_B, aId);

            rd.Add(a);
            rd.Add(m);
            rd.SetBreakScore(101);
            IList <DiffEntry> entries = rd.Compute();

            NUnit.Framework.Assert.AreEqual(2, entries.Count);
            AssertAdd(PATH_A, bId, FileMode.REGULAR_FILE, entries[0]);
            AssertRename(DiffEntry.BreakModify(m)[0], a, 100, entries[1]);
        }
コード例 #8
0
        public virtual void TestBreakModify_DontBreakAboveScore()
        {
            ObjectId  aId = Blob("blah\nblah\nfoo");
            ObjectId  bId = Blob("blah\nblah\nbar");
            DiffEntry m   = DiffEntry.Modify(PATH_A);

            m.oldId = AbbreviatedObjectId.FromObjectId(aId);
            m.newId = AbbreviatedObjectId.FromObjectId(bId);
            DiffEntry a = DiffEntry.Add(PATH_B, aId);

            rd.Add(a);
            rd.Add(m);
            rd.SetBreakScore(20);
            // Should not break the modify
            IList <DiffEntry> entries = rd.Compute();

            NUnit.Framework.Assert.AreEqual(2, entries.Count);
            NUnit.Framework.Assert.AreSame(m, entries[0]);
            NUnit.Framework.Assert.AreSame(a, entries[1]);
        }
コード例 #9
0
ファイル: AbbreviationTest.cs プロジェクト: shoff/ngit
        public virtual void TestAbbreviateOnEmptyRepository()
        {
            ObjectId id = Id("9d5b926ed164e8ee88d3b8b1e525d699adda01ba");

            NUnit.Framework.Assert.AreEqual(id.Abbreviate(2), reader.Abbreviate(id, 2));
            NUnit.Framework.Assert.AreEqual(id.Abbreviate(7), reader.Abbreviate(id, 7));
            NUnit.Framework.Assert.AreEqual(id.Abbreviate(8), reader.Abbreviate(id, 8));
            NUnit.Framework.Assert.AreEqual(id.Abbreviate(10), reader.Abbreviate(id, 10));
            NUnit.Framework.Assert.AreEqual(id.Abbreviate(16), reader.Abbreviate(id, 16));
            NUnit.Framework.Assert.AreEqual(AbbreviatedObjectId.FromObjectId(id), reader.Abbreviate
                                                (id, Constants.OBJECT_ID_STRING_LENGTH));
            //
            ICollection <ObjectId> matches;

            matches = reader.Resolve(reader.Abbreviate(id, 8));
            NUnit.Framework.Assert.IsNotNull(matches);
            NUnit.Framework.Assert.AreEqual(0, matches.Count);
            matches = reader.Resolve(AbbreviatedObjectId.FromObjectId(id));
            NUnit.Framework.Assert.IsNotNull(matches);
            NUnit.Framework.Assert.AreEqual(1, matches.Count);
            NUnit.Framework.Assert.AreEqual(id, matches.Iterator().Next());
        }
コード例 #10
0
        /// <summary>
        /// Convert the TreeWalk into DiffEntry headers, depending on
        /// <code>includeTrees</code>
        /// it will add tree objects into result or not.
        /// </summary>
        /// <param name="walk">
        /// the TreeWalk to walk through. Must have exactly two trees and
        /// when
        /// <code>includeTrees</code>
        /// parameter is
        /// <code>true</code>
        /// it can't
        /// be recursive.
        /// </param>
        /// <param name="includeTrees">include tree object's.</param>
        /// <returns>headers describing the changed files.</returns>
        /// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
        /// <exception cref="System.ArgumentException">
        /// when
        /// <code>includeTrees</code>
        /// is true and given TreeWalk is
        /// recursive. Or when given TreeWalk doesn't have exactly two
        /// trees
        /// </exception>
        public static IList <NGit.Diff.DiffEntry> Scan(TreeWalk walk, bool includeTrees)
        {
            if (walk.TreeCount != 2)
            {
                throw new ArgumentException(JGitText.Get().treeWalkMustHaveExactlyTwoTrees);
            }
            if (includeTrees && walk.Recursive)
            {
                throw new ArgumentException(JGitText.Get().cannotBeRecursiveWhenTreesAreIncluded);
            }
            IList <NGit.Diff.DiffEntry> r     = new AList <NGit.Diff.DiffEntry>();
            MutableObjectId             idBuf = new MutableObjectId();

            while (walk.Next())
            {
                NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
                walk.GetObjectId(idBuf, 0);
                entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
                walk.GetObjectId(idBuf, 1);
                entry.newId   = AbbreviatedObjectId.FromObjectId(idBuf);
                entry.oldMode = walk.GetFileMode(0);
                entry.newMode = walk.GetFileMode(1);
                entry.newPath = entry.oldPath = walk.PathString;
                if (entry.oldMode == FileMode.MISSING)
                {
                    entry.oldPath    = NGit.Diff.DiffEntry.DEV_NULL;
                    entry.changeType = DiffEntry.ChangeType.ADD;
                    r.AddItem(entry);
                }
                else
                {
                    if (entry.newMode == FileMode.MISSING)
                    {
                        entry.newPath    = NGit.Diff.DiffEntry.DEV_NULL;
                        entry.changeType = DiffEntry.ChangeType.DELETE;
                        r.AddItem(entry);
                    }
                    else
                    {
                        if (!entry.oldId.Equals(entry.newId))
                        {
                            entry.changeType = DiffEntry.ChangeType.MODIFY;
                            if (RenameDetector.SameType(entry.oldMode, entry.newMode))
                            {
                                r.AddItem(entry);
                            }
                            else
                            {
                                Sharpen.Collections.AddAll(r, BreakModify(entry));
                            }
                        }
                        else
                        {
                            if (entry.oldMode != entry.newMode)
                            {
                                entry.changeType = DiffEntry.ChangeType.MODIFY;
                                r.AddItem(entry);
                            }
                        }
                    }
                }
                if (includeTrees && walk.IsSubtree)
                {
                    walk.EnterSubtree();
                }
            }
            return(r);
        }
コード例 #11
0
        /// <exception cref="System.IO.IOException"></exception>
        private byte[] Open(DiffEntry.Side side, DiffEntry entry)
        {
            if (entry.GetMode(side) == FileMode.MISSING)
            {
                return(EMPTY);
            }
            if (entry.GetMode(side).GetObjectType() != Constants.OBJ_BLOB)
            {
                return(EMPTY);
            }
            if (IsBinary())
            {
                return(BINARY);
            }
            AbbreviatedObjectId id = entry.GetId(side);

            if (!id.IsComplete)
            {
                ICollection <ObjectId> ids = reader.Resolve(id);
                if (ids.Count == 1)
                {
                    id = AbbreviatedObjectId.FromObjectId(ids.Iterator().Next());
                    switch (side)
                    {
                    case DiffEntry.Side.OLD:
                    {
                        entry.oldId = id;
                        break;
                    }

                    case DiffEntry.Side.NEW:
                    {
                        entry.newId = id;
                        break;
                    }
                    }
                }
                else
                {
                    if (ids.Count == 0)
                    {
                        throw new MissingObjectException(id, Constants.OBJ_BLOB);
                    }
                    else
                    {
                        throw new AmbiguousObjectException(id, ids);
                    }
                }
            }
            try
            {
                ObjectLoader ldr = source.Open(side, entry);
                return(ldr.GetBytes(binaryFileThreshold));
            }
            catch (LargeObjectException.ExceedsLimit)
            {
                return(BINARY);
            }
            catch (LargeObjectException.ExceedsByteArrayLimit)
            {
                return(BINARY);
            }
            catch (LargeObjectException.OutOfMemory)
            {
                return(BINARY);
            }
            catch (LargeObjectException tooBig)
            {
                tooBig.SetObjectId(id.ToObjectId());
                throw;
            }
        }