コード例 #1
0
        public virtual void TestDiff()
        {
            Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
            FilePath folder = new FilePath(db.Directory.GetParent(), "folder");

            folder.Mkdir();
            Write(new FilePath(folder, "folder.txt"), "folder");
            Git git = new Git(db);

            git.Add().AddFilepattern(".").Call();
            git.Commit().SetMessage("Initial commit").Call();
            Write(new FilePath(folder, "folder.txt"), "folder change");
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            DiffFormatter         df = new DiffFormatter(new SafeBufferedOutputStream(os));

            df.SetRepository(db);
            df.SetPathFilter(PathFilter.Create("folder"));
            DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
            FileTreeIterator newTree = new FileTreeIterator(db);

            df.Format(oldTree, newTree);
            df.Flush();
            string actual   = System.Text.Encoding.UTF8.GetString(os.ToByteArray());
            string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
                              + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
                              "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";

            NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
        }
コード例 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private void AssertFormatted(string name)
        {
            fmt.Format(file, a, b);
            string exp = RawParseUtils.Decode(ReadFile(name));

            NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(@out.ToByteArray()));
        }
コード例 #3
0
ファイル: GitRepository.cs プロジェクト: kthguru/monodevelop
		string GenerateDiff (byte[] data1, byte[] data2)
		{
			if (RawText.IsBinary (data1) || RawText.IsBinary (data2)) {
				if (data1.Length != data2.Length)
					return GettextCatalog.GetString (" Binary files differ");
				if (data1.Length == data2.Length) {
					for (int n=0; n<data1.Length; n++) {
						if (data1[n] != data2[n])
							return GettextCatalog.GetString (" Binary files differ");
					}
				}
				return string.Empty;
			}
			var text1 = new RawText (data1);
			var text2 = new RawText (data2);
			var edits = MyersDiff<RawText>.INSTANCE.Diff(RawTextComparator.DEFAULT, text1, text2);
			MemoryStream s = new MemoryStream ();
			var formatter = new NGit.Diff.DiffFormatter (s);
			formatter.Format (edits, text1, text2);
			return Encoding.UTF8.GetString (s.ToArray ());
		}
コード例 #4
0
		string GenerateDiff (string s1, string s2)
		{
			var text1 = new NGit.Diff.RawText (Encoding.UTF8.GetBytes (s1));
			var text2 = new NGit.Diff.RawText (Encoding.UTF8.GetBytes (s2));
			var edits = MyersDiff<RawText>.INSTANCE.Diff(RawTextComparator.DEFAULT, text1, text2);
			MemoryStream s = new MemoryStream ();
			var formatter = new NGit.Diff.DiffFormatter (s);
			formatter.Format (edits, text1, text2);
			return Encoding.UTF8.GetString (s.ToArray ());
		}