Ejemplo n.º 1
0
        public static void DiffFiles(IDiffItem source, IDiffItem target,
                                     DiffOptions diffOpts, string fileNameForHeader,
                                     bool wait)
        {
            DiffItemUtil aItem  = new DiffItemUtil('a', fileNameForHeader, source.GetFile());
            DiffItemUtil bItem  = new DiffItemUtil('b', fileNameForHeader, target.GetFile());
            StreamWriter stream = diffOpts.StreamWriter;

            // short circuit for binary file comparisions
            if (source.GetEncoding() == RepositoryConstants.EncodingBinary && target.GetEncoding() == RepositoryConstants.EncodingBinary)
            {
                stream.WriteLine("Binary files {0} and {1} differ", aItem.Name, bItem.Name);
                return;
            }

            WriteHeader(aItem, bItem, diffOpts);

            // short circuit new files
            if (aItem.Length == 0)
            {
                WriteNewFile(stream, bItem.Lines);
                return;
            }

            Hashtable hashtable        = new Hashtable(aItem.Length + bItem.Length);
            bool      ignoreWhiteSpace = (diffOpts.Flags & DiffOptionFlags.IgnoreWhiteSpace) == DiffOptionFlags.IgnoreWhiteSpace;

            DiffItem[] items = DiffUtil.DiffText(hashtable, aItem.Lines, bItem.Lines,
                                                 ignoreWhiteSpace, ignoreWhiteSpace, false);

            WriteUnified(stream, aItem.Lines, bItem.Lines, items);
        }
Ejemplo n.º 2
0
        public static void DiffFiles(VersionControlServer versionControl,
																	IDiffItem source, IDiffItem target,
																	DiffOptions diffOpts, string fileNameForHeader,
																	bool wait)
        {
            DiffItemUtil aItem = new DiffItemUtil('a', fileNameForHeader, source.GetFile());
            DiffItemUtil bItem = new DiffItemUtil('b', fileNameForHeader, target.GetFile());
            StreamWriter stream = diffOpts.StreamWriter;

            // short circuit for binary file comparisions
            if (source.GetEncoding() == RepositoryConstants.EncodingBinary && target.GetEncoding() == RepositoryConstants.EncodingBinary)
                {
                    stream.WriteLine("Binary files {0} and {1} differ", aItem.Name, bItem.Name);
                    return;
                }

            WriteHeader(aItem, bItem, diffOpts);

            // short circuit new files
            if (aItem.Length == 0)
                {
                    WriteNewFile(stream, bItem.Lines);
                    return;
                }

            Hashtable hashtable = new Hashtable(aItem.Length + bItem.Length);
            bool ignoreWhiteSpace = (diffOpts.Flags & DiffOptionFlags.IgnoreWhiteSpace) ==  DiffOptionFlags.IgnoreWhiteSpace;

            DiffItem[] items = DiffUtil.DiffText(hashtable, aItem.Lines, bItem.Lines,
                                                                                     ignoreWhiteSpace, ignoreWhiteSpace, false);

            WriteUnified(stream, aItem.Lines, bItem.Lines, items);
        }
Ejemplo n.º 3
0
        internal static void WriteHeader(DiffItemUtil aItem, DiffItemUtil bItem,
                                         DiffOptions diffOpts)
        {
            StreamWriter stream = diffOpts.StreamWriter;

            stream.Write("diff --tfs " + aItem.Name + " ");
            if (!String.IsNullOrEmpty(diffOpts.SourceLabel))
            {
                stream.Write(diffOpts.SourceLabel + " ");
            }

            stream.Write(bItem.Name);
            if (!String.IsNullOrEmpty(diffOpts.TargetLabel))
            {
                stream.Write("@" + diffOpts.TargetLabel);
            }

            stream.WriteLine();

            // the trailing tabs below help diffutils grok filenames with spaces
            stream.WriteLine("--- " + aItem.Name + "\t");
            stream.WriteLine("+++ " + bItem.Name + "\t");
        }
        internal static void WriteHeader(DiffItemUtil aItem, DiffItemUtil bItem,
                                         DiffOptions diffOpts)
        {
            StreamWriter stream = diffOpts.StreamWriter;
            stream.Write("diff --tfs " + aItem.Name + " ");
            if (!String.IsNullOrEmpty(diffOpts.SourceLabel))
                stream.Write(diffOpts.SourceLabel + " ");

            stream.Write(bItem.Name);
            if (!String.IsNullOrEmpty(diffOpts.TargetLabel))
                stream.Write("@" + diffOpts.TargetLabel);

            stream.WriteLine();
			
            // the trailing tabs below help diffutils grok filenames with spaces
            stream.WriteLine("--- " + aItem.Name + "\t");
            stream.WriteLine("+++ " + bItem.Name + "\t");
        }