internal CombinedHunkHeader(CombinedFileHeader fh, int offset) : base(fh, offset, null) { old = new CombinedHunkHeader.CombinedOldImage[fh.GetParentCount()]; for (int i = 0; i < old.Length; i++) { int imagePos = i; old[i] = new _CombinedOldImage_70(fh, imagePos); } }
private int ParseDiffCombined(byte[] hdr, byte[] buf, int start, int end) { CombinedFileHeader fh = new CombinedFileHeader(buf, start); int ptr = fh.ParseGitFileName(start + hdr.Length, end); if (ptr < 0) { return(SkipFile(buf, start)); } ptr = fh.ParseGitHeaders(ptr, end); ptr = ParseHunks(fh, ptr, end); fh.endOffset = ptr; AddFile(fh); return(ptr); }
public virtual void TestParse_OneFileCc() { NGit.Patch.Patch p = ParseTestPatchFile(); NUnit.Framework.Assert.AreEqual(1, p.GetFiles().Count); NUnit.Framework.Assert.IsTrue(p.GetErrors().IsEmpty()); CombinedFileHeader cfh = (CombinedFileHeader)p.GetFiles()[0]; NUnit.Framework.Assert.AreEqual("org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java" , cfh.GetNewPath()); NUnit.Framework.Assert.AreEqual(cfh.GetNewPath(), cfh.GetOldPath()); NUnit.Framework.Assert.AreEqual(98, cfh.startOffset); NUnit.Framework.Assert.AreEqual(2, cfh.GetParentCount()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(0), cfh.GetOldId()); NUnit.Framework.Assert.AreEqual("169356b", cfh.GetOldId(0).Name); NUnit.Framework.Assert.AreEqual("dd8c317", cfh.GetOldId(1).Name); NUnit.Framework.Assert.AreEqual("fd85931", cfh.GetNewId().Name); NUnit.Framework.Assert.AreSame(cfh.GetOldMode(0), cfh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, cfh.GetOldMode(0)); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, cfh.GetOldMode(1)); NUnit.Framework.Assert.AreSame(FileMode.EXECUTABLE_FILE, cfh.GetNewMode()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, cfh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, cfh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, ((IList <HunkHeader>)cfh.GetHunks()).Count ); { CombinedHunkHeader h = (CombinedHunkHeader)(cfh.GetHunks()[0]); NUnit.Framework.Assert.AreSame(cfh, ((CombinedFileHeader)h.GetFileHeader())); NUnit.Framework.Assert.AreEqual(346, h.startOffset); NUnit.Framework.Assert.AreEqual(764, h.endOffset); NUnit.Framework.Assert.AreSame(h.GetOldImage(0), h.GetOldImage()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(0), h.GetOldImage(0).GetId()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(1), h.GetOldImage(1).GetId()); NUnit.Framework.Assert.AreEqual(55, h.GetOldImage(0).GetStartLine()); NUnit.Framework.Assert.AreEqual(12, h.GetOldImage(0).GetLineCount()); NUnit.Framework.Assert.AreEqual(3, h.GetOldImage(0).GetLinesAdded()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(0).GetLinesDeleted()); NUnit.Framework.Assert.AreEqual(163, h.GetOldImage(1).GetStartLine()); NUnit.Framework.Assert.AreEqual(13, h.GetOldImage(1).GetLineCount()); NUnit.Framework.Assert.AreEqual(2, h.GetOldImage(1).GetLinesAdded()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(1).GetLinesDeleted()); NUnit.Framework.Assert.AreEqual(163, h.GetNewStartLine()); NUnit.Framework.Assert.AreEqual(15, h.GetNewLineCount()); NUnit.Framework.Assert.AreEqual(10, h.GetLinesContext()); } }
public virtual void TestParse_CcNewFile() { NGit.Patch.Patch p = ParseTestPatchFile(); NUnit.Framework.Assert.AreEqual(1, p.GetFiles().Count); NUnit.Framework.Assert.IsTrue(p.GetErrors().IsEmpty()); CombinedFileHeader cfh = (CombinedFileHeader)p.GetFiles()[0]; NUnit.Framework.Assert.AreSame(DiffEntry.DEV_NULL, cfh.GetOldPath()); NUnit.Framework.Assert.AreEqual("d", cfh.GetNewPath()); NUnit.Framework.Assert.AreEqual(187, cfh.startOffset); NUnit.Framework.Assert.AreEqual(2, cfh.GetParentCount()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(0), cfh.GetOldId()); NUnit.Framework.Assert.AreEqual("0000000", cfh.GetOldId(0).Name); NUnit.Framework.Assert.AreEqual("0000000", cfh.GetOldId(1).Name); NUnit.Framework.Assert.AreEqual("4bcfe98", cfh.GetNewId().Name); NUnit.Framework.Assert.AreSame(cfh.GetOldMode(0), cfh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.MISSING, cfh.GetOldMode(0)); NUnit.Framework.Assert.AreSame(FileMode.MISSING, cfh.GetOldMode(1)); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, cfh.GetNewMode()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.ADD, cfh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, cfh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, ((IList <HunkHeader>)cfh.GetHunks()).Count ); { CombinedHunkHeader h = (CombinedHunkHeader)(cfh.GetHunks()[0]); NUnit.Framework.Assert.AreSame(cfh, ((CombinedFileHeader)h.GetFileHeader())); NUnit.Framework.Assert.AreEqual(273, h.startOffset); NUnit.Framework.Assert.AreEqual(300, h.endOffset); NUnit.Framework.Assert.AreSame(h.GetOldImage(0), h.GetOldImage()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(0), h.GetOldImage(0).GetId()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(1), h.GetOldImage(1).GetId()); NUnit.Framework.Assert.AreEqual(1, h.GetOldImage(0).GetStartLine()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(0).GetLineCount()); NUnit.Framework.Assert.AreEqual(1, h.GetOldImage(0).GetLinesAdded()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(0).GetLinesDeleted()); NUnit.Framework.Assert.AreEqual(1, h.GetOldImage(1).GetStartLine()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(1).GetLineCount()); NUnit.Framework.Assert.AreEqual(1, h.GetOldImage(1).GetLinesAdded()); NUnit.Framework.Assert.AreEqual(0, h.GetOldImage(1).GetLinesDeleted()); NUnit.Framework.Assert.AreEqual(1, h.GetNewStartLine()); NUnit.Framework.Assert.AreEqual(1, h.GetNewLineCount()); NUnit.Framework.Assert.AreEqual(0, h.GetLinesContext()); } }
public virtual void TestGetText_DiffCc() { Encoding csOld = Sharpen.Extensions.GetEncoding("ISO-8859-1"); Encoding csNew = Sharpen.Extensions.GetEncoding("UTF-8"); NGit.Patch.Patch p = ParseTestPatchFile(); NUnit.Framework.Assert.IsTrue(p.GetErrors().IsEmpty()); NUnit.Framework.Assert.AreEqual(1, p.GetFiles().Count); CombinedFileHeader fh = (CombinedFileHeader)p.GetFiles()[0]; NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count ); // Read the original file as ISO-8859-1 and fix up the one place // where we changed the character encoding. That makes the exp // string match what we really expect to get back. // string exp = ReadTestPatchFile(csOld); exp = exp.Replace("\x12f\xcdngstr\x12f\x10am", "\u00c5ngstr\u00f6m"); NUnit.Framework.Assert.AreEqual(exp, fh.GetScriptText(new Encoding[] { csNew, csOld , csNew })); }
public virtual void TestParse_CcDeleteFile() { NGit.Patch.Patch p = ParseTestPatchFile(); NUnit.Framework.Assert.AreEqual(1, p.GetFiles().Count); NUnit.Framework.Assert.IsTrue(p.GetErrors().IsEmpty()); CombinedFileHeader cfh = (CombinedFileHeader)p.GetFiles()[0]; NUnit.Framework.Assert.AreEqual("a", cfh.GetOldPath()); NUnit.Framework.Assert.AreSame(DiffEntry.DEV_NULL, cfh.GetNewPath()); NUnit.Framework.Assert.AreEqual(187, cfh.startOffset); NUnit.Framework.Assert.AreEqual(2, cfh.GetParentCount()); NUnit.Framework.Assert.AreSame(cfh.GetOldId(0), cfh.GetOldId()); NUnit.Framework.Assert.AreEqual("7898192", cfh.GetOldId(0).Name); NUnit.Framework.Assert.AreEqual("2e65efe", cfh.GetOldId(1).Name); NUnit.Framework.Assert.AreEqual("0000000", cfh.GetNewId().Name); NUnit.Framework.Assert.AreSame(cfh.GetOldMode(0), cfh.GetOldMode()); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, cfh.GetOldMode(0)); NUnit.Framework.Assert.AreSame(FileMode.REGULAR_FILE, cfh.GetOldMode(1)); NUnit.Framework.Assert.AreSame(FileMode.MISSING, cfh.GetNewMode()); NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.DELETE, cfh.GetChangeType()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, cfh.GetPatchType()); NUnit.Framework.Assert.IsTrue((cfh.GetHunks()).IsEmpty ()); }
public _CombinedOldImage_70(CombinedFileHeader fh, int imagePos) { this.fh = fh; this.imagePos = imagePos; }
private int ParseDiffCombined(byte[] hdr, byte[] buf, int start, int end) { CombinedFileHeader fh = new CombinedFileHeader(buf, start); int ptr = fh.ParseGitFileName(start + hdr.Length, end); if (ptr < 0) { return SkipFile(buf, start); } ptr = fh.ParseGitHeaders(ptr, end); ptr = ParseHunks(fh, ptr, end); fh.endOffset = ptr; AddFile(fh); return ptr; }