private static void AssertCopy(DiffEntry o, DiffEntry n, int score, DiffEntry copy ) { NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.COPY, copy.GetChangeType()); NUnit.Framework.Assert.AreEqual(o.GetOldPath(), copy.GetOldPath()); NUnit.Framework.Assert.AreEqual(n.GetNewPath(), copy.GetNewPath()); NUnit.Framework.Assert.AreEqual(o.GetOldMode(), copy.GetOldMode()); NUnit.Framework.Assert.AreEqual(n.GetNewMode(), copy.GetNewMode()); NUnit.Framework.Assert.AreEqual(o.GetOldId(), copy.GetOldId()); NUnit.Framework.Assert.AreEqual(n.GetNewId(), copy.GetNewId()); NUnit.Framework.Assert.AreEqual(score, copy.GetScore()); }
private static void AssertRename(DiffEntry o, DiffEntry n, int score, DiffEntry rename ) { NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.RENAME, rename.GetChangeType ()); NUnit.Framework.Assert.AreEqual(o.GetOldPath(), rename.GetOldPath()); NUnit.Framework.Assert.AreEqual(n.GetNewPath(), rename.GetNewPath()); NUnit.Framework.Assert.AreEqual(o.GetOldMode(), rename.GetOldMode()); NUnit.Framework.Assert.AreEqual(n.GetNewMode(), rename.GetNewMode()); NUnit.Framework.Assert.AreEqual(o.GetOldId(), rename.GetOldId()); NUnit.Framework.Assert.AreEqual(n.GetNewId(), rename.GetNewId()); NUnit.Framework.Assert.AreEqual(score, rename.GetScore()); }
/// <exception cref="System.IO.IOException"></exception> private void FormatHeader(ByteArrayOutputStream o, DiffEntry ent) { DiffEntry.ChangeType type = ent.GetChangeType(); string oldp = ent.GetOldPath(); string newp = ent.GetNewPath(); FileMode oldMode = ent.GetOldMode(); FileMode newMode = ent.GetNewMode(); o.Write(Constants.EncodeASCII("diff --git ")); o.Write(Constants.Encode(QuotePath(oldPrefix + (type == DiffEntry.ChangeType.ADD ? newp : oldp)))); o.Write(' '); o.Write(Constants.Encode(QuotePath(newPrefix + (type == DiffEntry.ChangeType.DELETE ? oldp : newp)))); o.Write('\n'); switch (type) { case DiffEntry.ChangeType.ADD: { o.Write(Constants.EncodeASCII("new file mode ")); newMode.CopyTo(o); o.Write('\n'); break; } case DiffEntry.ChangeType.DELETE: { o.Write(Constants.EncodeASCII("deleted file mode ")); oldMode.CopyTo(o); o.Write('\n'); break; } case DiffEntry.ChangeType.RENAME: { o.Write(Constants.EncodeASCII("similarity index " + ent.GetScore() + "%")); o.Write('\n'); o.Write(Constants.Encode("rename from " + QuotePath(oldp))); o.Write('\n'); o.Write(Constants.Encode("rename to " + QuotePath(newp))); o.Write('\n'); break; } case DiffEntry.ChangeType.COPY: { o.Write(Constants.EncodeASCII("similarity index " + ent.GetScore() + "%")); o.Write('\n'); o.Write(Constants.Encode("copy from " + QuotePath(oldp))); o.Write('\n'); o.Write(Constants.Encode("copy to " + QuotePath(newp))); o.Write('\n'); if (!oldMode.Equals(newMode)) { o.Write(Constants.EncodeASCII("new file mode ")); newMode.CopyTo(o); o.Write('\n'); } break; } case DiffEntry.ChangeType.MODIFY: { if (0 < ent.GetScore()) { o.Write(Constants.EncodeASCII("dissimilarity index " + (100 - ent.GetScore()) + "%" )); o.Write('\n'); } break; } } if ((type == DiffEntry.ChangeType.MODIFY || type == DiffEntry.ChangeType.RENAME) && !oldMode.Equals(newMode)) { o.Write(Constants.EncodeASCII("old mode ")); oldMode.CopyTo(o); o.Write('\n'); o.Write(Constants.EncodeASCII("new mode ")); newMode.CopyTo(o); o.Write('\n'); } if (!ent.GetOldId().Equals(ent.GetNewId())) { FormatIndexLine(o, ent); } }