Exemplo n.º 1
0
        public void Run()
        {
            IEnumerable<IConversionStep> steps = new IConversionStep[]
                                                     {
                                                         new RemoveLeadingFilePathStep(),
                                                         new InsertTortoiseSegmentationLineStep(),
                                                         new CorrectNullReferencesStep()
                                                     };

            foreach (FileInfo patchFile in FindPatches(_options.InputPaths))
            {
                System.Console.Write(patchFile.Name);
                System.Console.Write(" ..");
                string contents;
                using (StreamReader t = patchFile.OpenText())
                    contents = t.ReadToEnd();

                foreach (IConversionStep step in steps)
                {
                    System.Console.Write(".");
                    contents = step.Convert(contents);
                }

                string svnDir = _options.OutputDir ?? patchFile.DirectoryName;
                if (!Path.IsPathRooted(svnDir))
                    svnDir = Path.Combine(_baseDir, svnDir);

                var svnPatch = new FileInfo(Path.Combine(svnDir, "svn-" + patchFile.Name));
                if (svnPatch.Exists)
                    svnPatch.Delete();

                using (StreamWriter t = svnPatch.CreateText())
                    t.Write(contents);

                System.Console.WriteLine(".  Done.");
            }
        }
        private string createPatch(string path, out UrlAnalyzeResult analyzeResult)
        {
            string originUrl = "http://github.com/" + path;
            analyzeResult = urlAnalyzer().Analyze(new Uri(originUrl));

            string originDiffUrl = analyzeResult.CompareUrl + ".diff";

            string patchContents;
            patchContents = new WebClient().DownloadString(originDiffUrl);

            var lines = new[]
                            {
                                "Online: " + analyzeResult.PermaLink,
                                "Download: " + analyzeResult.DownloadUrl,
                                "View: " + analyzeResult.ViewUrl,
                                "Based on r" + analyzeResult.SvnRevision + " in " + analyzeResult.SvnUrl,
                                "",
                                "Included commits:"
                            };

            var changes =
                analyzeResult.Changes.Select(
                    c => string.Format(" - {0} (by {1} on {2})", c.message, c.author.name + "<" + c.author.email + ">", c.authored_date))
                    .SelectMany(m => m.Replace("\n", "\n   ").Replace("\r", "").Split('\n'));

            lines = lines
                .Union(changes)
                .ToArray();

            var prependInfoHeader = new PrependInfoHeader(lines);
            IEnumerable<IConversionStep> steps = new IConversionStep[]
                                                     {
                                                         prependInfoHeader,
                                                         new RemoveLeadingFilePathStep(),
                                                         new InsertTortoiseSegmentationLineStep(),
                                                         new CorrectNullReferencesStep()
                                                     };

            patchContents = steps.Aggregate(patchContents,
                                            (current, conversionStep) => conversionStep.Convert(current));
            return patchContents;
        }
Exemplo n.º 3
0
 public void AddStep(IConversionStep step)
 {
     _steps.Add(step);
 }