コード例 #1
0
ファイル: EditListTest.cs プロジェクト: HackerBaloo/GitSharp
        public void testAddTwo()
        {
            Edit e1 = new Edit(1, 2, 1, 1);
            Edit e2 = new Edit(8, 8, 8, 12);
            EditList l = new EditList();
            l.Add(e1);
            l.Add(e2);
            Assert.AreEqual(2, l.size());
            Assert.AreSame(e1, l.get(0));
            Assert.AreSame(e2, l.get(1));

            IEnumerator i = l.GetEnumerator();
            i.Reset();
            i.MoveNext();
            Assert.AreSame(e1, i.Current);
            i.MoveNext();
            Assert.AreSame(e2, i.Current);

            Assert.IsTrue(l.Equals(l));
            Assert.IsFalse(l.Equals(new EditList()));

            EditList l2 = new EditList();
            l2.Add(e1);
            l2.Add(e2);
            Assert.IsTrue(l.Equals(l2));
            Assert.IsTrue(l2.Equals(l));
            Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
        }
コード例 #2
0
ファイル: EditListTest.cs プロジェクト: stephensong/GitSharp
	    public void testEmpty()
        {
		    EditList l = new EditList();
		    Assert.AreEqual(0, l.size());
		    Assert.IsTrue(l.isEmpty());
		    Assert.AreEqual("EditList[]", l.ToString());

		    Assert.IsTrue(l.Equals(l));
		    Assert.IsTrue(l.Equals(new EditList()));
		    Assert.IsFalse(l.Equals(""));
            Assert.AreEqual(l.GetHashCode(), new EditList().GetHashCode());
	    }
コード例 #3
0
ファイル: EditListTest.cs プロジェクト: stephensong/GitSharp
	    public void testAddOne()
        {
		    Edit e = new Edit(1, 2, 1, 1);
		    EditList l = new EditList();
		    l.Add(e);
		    Assert.AreEqual(1, l.size());
		    Assert.IsFalse(l.isEmpty());
		    Assert.AreSame(e, l.get(0));
            IEnumerator i = l.GetEnumerator();
            i.Reset();
            i.MoveNext();
		    Assert.AreSame(e, i.Current);

		    Assert.IsTrue(l.Equals(l));
		    Assert.IsFalse(l.Equals(new EditList()));

		    EditList l2 = new EditList();
		    l2.Add(e);
		    Assert.IsTrue(l.Equals(l2));
		    Assert.IsTrue(l2.Equals(l));
		    Assert.AreEqual(l.GetHashCode(), l2.GetHashCode());
	    }
コード例 #4
0
ファイル: EditList.cs プロジェクト: stephensong/GitSharp
        private bool isEqual(EditList o)
        {
            if (this.Count != ((EditList)o).Count)
                return false;

            for (int i = 0; i < this.Count; i++)
                if (!this[i].Equals(((EditList)o)[i]))
                    return false;

            return true;
        }
コード例 #5
0
ファイル: FileHeader.cs プロジェクト: gilran/GitSharp
	    /** @return a list describing the content edits performed on this file. */
	    public EditList toEditList()
        {
		    EditList r = new EditList();
		    foreach (HunkHeader hunk in hunks)
			    r.AddRange(hunk.toEditList());
		    return r;
	    }
コード例 #6
0
ファイル: DiffFormatter.cs プロジェクト: HackerBaloo/GitSharp
        private void FormatEdits(Stream @out, RawText a, RawText b, EditList edits)
        {
            for (int curIdx = 0; curIdx < edits.Count; /* */)
            {
                Edit curEdit = edits.get(curIdx);
                int endIdx = FindCombinedEnd(edits, curIdx);
                Edit endEdit = edits.get(endIdx);

                int aCur = Math.Max(0, curEdit.BeginA - _context);
                int bCur = Math.Max(0, curEdit.BeginB - _context);
                int aEnd = Math.Min(a.size(), endEdit.EndA + _context);
                int bEnd = Math.Min(b.size(), endEdit.EndB + _context);

                WriteHunkHeader(@out, aCur, aEnd, bCur, bEnd);

                while (aCur < aEnd || bCur < bEnd)
                {
                    if (aCur < curEdit.BeginA || endIdx + 1 < curIdx)
                    {
                        WriteLine(@out, ' ', a, aCur);
                        aCur++;
                        bCur++;
                    }
                    else if (aCur < curEdit.EndA)
                    {
                        WriteLine(@out, '-', a, aCur++);

                    }
                    else if (bCur < curEdit.EndB)
                    {
                        WriteLine(@out, '+', b, bCur++);
                    }

                    if (End(curEdit, aCur, bCur) && ++curIdx < edits.Count)
                    {
                        curEdit = edits.get(curIdx);
                    }
                }
            }
        }
コード例 #7
0
ファイル: EditListTest.cs プロジェクト: stephensong/GitSharp
	    public void testRemove()
        {
		    Edit e1 = new Edit(1, 2, 1, 1);
		    Edit e2 = new Edit(8, 8, 8, 12);
		    EditList l = new EditList();
		    l.Add(e1);
		    l.Add(e2);
		    l.Remove(e1);
		    Assert.AreEqual(1, l.size());
		    Assert.AreSame(e2, l.get(0));
	    }
コード例 #8
0
ファイル: EditListTest.cs プロジェクト: stephensong/GitSharp
	    public void testSet()
        {
		    Edit e1 = new Edit(1, 2, 1, 1);
		    Edit e2 = new Edit(3, 4, 3, 3);
		    EditList l = new EditList();
		    l.Add(e1);
		    Assert.AreSame(e1, l.get(0));
		    Assert.AreSame(e1, l.set(0, e2));
		    Assert.AreSame(e2, l.get(0));
	    }
コード例 #9
0
ファイル: HunkHeader.cs プロジェクト: HackerBaloo/GitSharp
        /// <summary>
        /// Returns a list describing the content edits performed within the hunk.
        /// </summary>
        /// <returns></returns>
        public EditList ToEditList()
        {
            var r = new EditList();
            byte[] buf = _file.Buffer;
            int c = RawParseUtils.nextLF(buf, _startOffset);
            int oLine = _oldImage.StartLine;
            int nLine = NewStartLine;
            Edit inEdit = null;

            for (; c < EndOffset; c = RawParseUtils.nextLF(buf, c))
            {
                bool breakScan;

                switch (buf[c])
                {
                    case (byte)' ':
                    case (byte)'\n':
                        inEdit = null;
                        oLine++;
                        nLine++;
                        continue;

                    case (byte)'-':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        oLine++;
                        inEdit.ExtendA();
                        continue;

                    case (byte)'+':
                        if (inEdit == null)
                        {
                            inEdit = new Edit(oLine - 1, nLine - 1);
                            r.Add(inEdit);
                        }
                        nLine++;
                        inEdit.ExtendB();
                        continue;

                    case (byte)'\\': // Matches "\ No newline at end of file"
                        continue;

                    default:
                        breakScan = true;
                        break;
                }

                if (breakScan)
                {
                    break;
                }
            }

            return r;
        }
コード例 #10
0
ファイル: HunkHeader.cs プロジェクト: stephensong/GitSharp
	    /** @return a list describing the content edits performed within the hunk. */
	    public EditList toEditList()
        {
		    EditList r = new EditList();
		    byte[] buf = file.buf;
		    int c = RawParseUtils.nextLF(buf, startOffset);
		    int oLine = old.startLine;
		    int nLine = newStartLine;
		    Edit inEdit = null;

            bool break_scan = false;
		    for (; c < endOffset; c = RawParseUtils.nextLF(buf, c)) {
			    switch (buf[c]) {
			    case (byte)' ':
			    case (byte)'\n':
				    inEdit = null;
				    oLine++;
				    nLine++;
				    continue;

			    case (byte)'-':
				    if (inEdit == null) {
					    inEdit = new Edit(oLine - 1, nLine - 1);
					    r.Add(inEdit);
				    }
				    oLine++;
				    inEdit.extendA();
				    continue;

			    case (byte)'+':
				    if (inEdit == null) {
					    inEdit = new Edit(oLine - 1, nLine - 1);
					    r.Add(inEdit);
				    }
				    nLine++;
				    inEdit.extendB();
				    continue;

			    case (byte)'\\': // Matches "\ No newline at end of file"
				    continue;

			    default:
				    break_scan = true;
                    break;
			    }
                if (break_scan)
                    break;
		    }
		    return r;
	    }
コード例 #11
0
ファイル: FileHeader.cs プロジェクト: HackerBaloo/GitSharp
 /// <summary>
 /// Returns a list describing the content edits performed on this file.
 /// </summary>
 /// <returns></returns>
 public EditList ToEditList()
 {
     var r = new EditList();
     _hunks.ForEach(hunk => r.AddRange(hunk.ToEditList()));
     return r;
 }