protected override void EndProcessing() { // Use default logger XmlConfigurator.Configure((XmlElement) ConfigurationManager.GetSection("log4net")); PerformInstallAction( () => { var diff = new DiffInfo( CommandList, string.IsNullOrEmpty(Name) ? "Sitecore PowerShell Extensions Generated Update Package" : Name, Readme ?? string.Empty, Tag ?? string.Empty); var fileName = Path; if (string.IsNullOrEmpty(fileName)) { fileName = string.Format("{0}.update", Name); } if (!System.IO.Path.IsPathRooted(fileName)) { fileName = FullPackageProjectPath(fileName); } if (ShouldProcess(fileName, "Export update package")) { PackageGenerator.GeneratePackage(diff, LicenseFileName, fileName); } }); }
protected virtual DiffInfo LoadFromPackage(string path) { IProcessingContext context = new SimpleProcessingContext(); CommandInstallerContext.Setup(context, Path.GetFileNameWithoutExtension(path), UpgradeAction.Preview, Sitecore.Update.Utils.InstallMode.Install, null, new List <ContingencyEntry>()); ISource <PackageEntry> source = new PackageReader(path); ISink <PackageEntry> installer = DoCreateInstallerSink(context); var sorter = new PackageDumper(source); sorter.Initialize(context); sorter.Populate(installer); installer.Flush(); var commands = new List <ICommand>(sorter.Commands); var engine = new DataEngine { FilterCommands = false, OptimizeCommands = false }; engine.ProcessCommands(ref commands); var info = new DiffInfo(commands, string.Empty, string.Empty, "Generated by ConvertFromPackage command."); MetadataView view = UpdateHelper.LoadMetadata(path); if (view != null) { info.Readme = view.Readme; info.InstallMode = view.Comment; info.Title = view.PackageName; } ; return(info); }
void IAssetMenuOperations.ShowDiff() { string selectedPath = AssetsSelection.GetSelectedPath( mAssetSelection.GetSelectedAssets()); DiffInfo diffInfo = null; IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); waiter.Execute( /*threadOperationDelegate*/ delegate { string symbolicName = GetSymbolicName(selectedPath); string extension = Path.GetExtension(selectedPath); diffInfo = Plastic.API.BuildDiffInfoForDiffWithPrevious( selectedPath, symbolicName, selectedPath, extension, mWkInfo); }, /*afterOperationDelegate*/ delegate { if (waiter.Exception != null) { ExceptionsHandler.DisplayException(waiter.Exception); return; } DiffOperation.DiffWithPrevious( diffInfo, null, null); }); }
/// <summary> /// Get the diff of the file between its original and modified version. /// </summary> /// <param name="fileInfo">The file info for the file to get a diff for.</param> /// <returns>The file's diff info.</returns> public DiffInfo UncommittedDiff(ITargetFileInfo fileInfo) { if (!IsWritablePath(fileInfo.DerivedFileName)) { throw new FileNotFoundException($"Cannot access file '{fileInfo.OriginalFileName}'"); } var diff = new DiffInfo(); //Original File var historyCommits = repo.Commits.QueryBy(fileInfo.DerivedFileName); var latestCommit = historyCommits.FirstOrDefault(); if (latestCommit != null) { var blob = latestCommit.Commit[fileInfo.DerivedFileName].Target as Blob; if (blob != null) { diff.Original = blob.GetContentText(); } } else { diff.Original = $"Could not read original file {fileInfo.DerivedFileName}."; } var repoPath = Path.Combine(repo.Info.WorkingDirectory, fileInfo.DerivedFileName); using (var stream = new StreamReader(fileFinder.ReadFile(fileFinder.GetProjectRelativePath(repoPath)))) { diff.Changed = stream.ReadToEnd().Replace("\r", ""); } return(diff); }
/// <summary> /// Mains the specified args. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { Console.WriteLine("Source: {0}", options.Source); Console.WriteLine("Target: {0}", options.Target); Console.WriteLine("Output: {0}", options.Output); Console.WriteLine("Collision behavior: {0}", options.CollisionBehavior); Console.WriteLine("Configuration: {0}", options.Configuration); Console.WriteLine("Path to project file: {0}", options.ScProjFilePath); if (ExclusionHandler.HasValidExclusions(options.Configuration, options.ScProjFilePath)) { var exclusions = ExclusionHandler.GetExcludedItems(options.ScProjFilePath, options.Configuration); ExclusionHandler.RemoveExcludedItems(options.Source, exclusions); ExclusionHandler.RemoveExcludedItems(options.Target, exclusions); } var diff = new DiffInfo( DiffGenerator.GetDiffCommands(options.Source, options.Target, options.CollisionBehavior), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", options.Source, options.Target)); PackageGenerator.GeneratePackage(diff, string.Empty, options.Output); } else { Console.WriteLine(options.GetUsage()); } }
protected override void EndProcessing() { // Use default logger XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net")); PerformInstallAction( () => { var diff = new DiffInfo( CommandList, string.IsNullOrEmpty(Name) ? "Sitecore PowerShell Extensions Generated Update Package" : Name, Readme ?? string.Empty, Tag ?? string.Empty); var fileName = Path; if (string.IsNullOrEmpty(fileName)) { fileName = string.Format("{0}.update", Name); } if (!System.IO.Path.IsPathRooted(fileName)) { fileName = FullPackageProjectPath(fileName); } if (ShouldProcess(fileName, "Export update package")) { PackageGenerator.GeneratePackage(diff, LicenseFileName, fileName); } }); }
protected virtual IList <CommandViewItem> GetDifference(DiffInfo source, DiffInfo target) { Dictionary <string, ICommand> sourceCommands = this.ExtractCommands(source); Dictionary <string, ICommand> targetCommands = this.ExtractCommands(target); List <CommandViewItem> result = new List <CommandViewItem>(); foreach (string key in sourceCommands.Keys.ToArray()) { if (!targetCommands.ContainsKey(key)) { result.Add(this.GetAddedCommand(sourceCommands[key])); sourceCommands.Remove(key); } else { result.Add(this.GetChangedCommand(sourceCommands[key], targetCommands[key])); sourceCommands.Remove(key); targetCommands.Remove(key); } } Assert.IsTrue(sourceCommands.Keys.Count == 0, "problem in algorithm that compares packages. source"); foreach (var key in targetCommands.Keys.ToArray()) { result.Add(this.GetDeletedCommand(targetCommands[key])); targetCommands.Remove(key); } Assert.IsTrue(targetCommands.Keys.Count == 0, "problem in algorithm that compares packages. target"); return(result); }
private void loadPackageToolStripMenuItem_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.FolderBrowserDialog.SelectedPath)) { if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["defaultDiffLocation"])) { this.openFileDialog1.InitialDirectory = ConfigurationManager.AppSettings["defaultDiffLocation"]; } } DialogResult result = this.openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { try { string packagePath = this.openFileDialog1.FileName; this.diff = new DiffLoader().Load(packagePath); this.InitializeForm(); this.editReadMeToolStripMenuItem.Enabled = false; this.compareToToolStripMenuItem.Enabled = true; this.Text += " package: " + packagePath; } catch (Exception ex) { MessageBox.Show(string.Format("Cannot load Diff: {0}", ex.ToString())); } } }
public Codegram GenerateCodegramFromDiffContent(DiffInfo diffInfo, int maxSize) { var codegram = new Codegram(); codegram.Filegrams = new List <Filegram>(); codegram.Author = diffInfo.Author; codegram.Date = diffInfo.Date; codegram.Message = diffInfo.Message; CrossSimiliarity(diffInfo.Files); foreach (var file in diffInfo.Files) { var filegram = new Filegram(); filegram.FileName = file.Hunks.First().FileName; foreach (var chunk in file.Hunks) { var lines = SalientLines(maxSize, chunk); filegram.Linegrams = lines.ToList(); } codegram.Filegrams.Add(filegram); } // Temp placement: Apply patterns Pattern pattern = new RemovedFilePattern(); pattern.Rewrite(codegram); return(codegram); }
//public IEnumerable<HunkRangeInfo> Parse(string text) //{ // return from hunkLine in GetUnifiedFormatHunkLines(text) // where !string.IsNullOrEmpty(hunkLine.Item1) // select new HunkRangeInfo(new HunkRange(GetHunkOriginalFile(hunkLine.Item1)), new HunkRange(GetHunkNewFile(hunkLine.Item1)), hunkLine.Item2, hunkLine.Item3); //} public DiffInfo Parse(string text) { var diffInfo = new DiffInfo(); diffInfo.Author = GetAuthorFromDiff(text); diffInfo.Message = GetMessageFromDiff(text); diffInfo.Date = GetDateFromDiff(text); foreach (var chunk in SplitFileHunks(text)) { var split = chunk.Split('\n').AsEnumerable(); var hunks = GetUnifiedFormatHunkLines(split) .Where(line => !string.IsNullOrEmpty(line.Item1)) .Select(line => new HunkRangeInfo( new HunkRange(GetHunkOriginalFile(line.Item1)), new HunkRange(GetHunkNewFile(line.Item1)), line.Item2, GetFileName(split) ) ).ToList(); diffInfo.Files.Add(new FileDiff { Hunks = hunks }); } foreach (var file in diffInfo.Files) { if (file.Hunks.Any()) { file.FileName = file.Hunks.First().FileName; } } return(diffInfo); }
protected override void BeginProcessing() { try { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", Path.Combine(currentDirectory, "Sitecore.Courier.dll.config")); ResetConfigMechanism(); string version = Guid.NewGuid().ToString(); Console.WriteLine("Source: {0}", Source); Console.WriteLine("Target: {0}", Target); Console.WriteLine("Output: {0}", Output); Console.WriteLine("SerializationProvider: {0}", SerializationProvider); Console.WriteLine("CollisionBehavior: {0}", CollisionBehavior); Console.WriteLine("IncludeFiles: {0}", IncludeFiles); Console.WriteLine("DacPac: {0}", DacPac); RainbowSerializationProvider.Enabled = SerializationProvider == SerializationProvider.Rainbow; RainbowSerializationProvider.IncludeFiles = IncludeFiles; RainbowSerializationProvider.EnsureRevision = EnsureRevision; var diff = new DiffInfo( DiffGenerator.GetDiffCommands(Source, Target, IncludeSecurity, version, CollisionBehavior), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", Source, Target)); if (IncludeSecurity) { diff.Commands.Add(new PostStepFileSystemDataItem(currentDirectory, string.Empty, PostDeployDll) .GenerateAddCommand().FirstOrDefault()); diff.PostStep = PostStep; diff.Version = version; } if (DacPac) { SqlConverter c = new SqlConverter(); c.ConvertPackage(diff, Output); var builder = new DacPacBuilder(); DirectoryInfo d = new DirectoryInfo(Output); foreach (var file in d.GetFiles("*.sql")) { builder.ConvertToDacPac(file.FullName, Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}.dacpac")); } } else { PackageGenerator.GeneratePackage(diff, string.Empty, Output); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }
public void ConvertPackage(DiffInfo diff, string outputPath) { using (Converter converter = new Converter(diff, new SqlWriter(new FileSystemProvider(), new SqlGenerator(), outputPath))) { this.ConvertItems(converter); } }
protected virtual Dictionary <string, ICommand> ExtractCommands(DiffInfo diff) { var result = new Dictionary <string, ICommand>(); foreach (var command in diff.Commands) { result.Add(this.GetCommandKey(command), command); } return(result); }
public void TestPushDiff() { var repo2 = (GitRepository)Repo; AddFile("file", "meh", true, true); PostCommit(repo2); AddFile("file1", "text", true, true); AddFile("file2", "text2", true, true); DiffInfo[] diff = repo2.GetPushDiff("origin", "master"); Assert.AreEqual(2, diff.Length); DiffInfo item = diff [0]; Assert.IsNotNull(item); Assert.AreEqual("file1", item.FileName.FileName); string text = @"diff --git a/file1 b/file1 new file mode 100644 index 0000000..f3a3485 --- /dev/null +++ b/file1 @@ -0,0 +1 @@ +text \ No newline at end of file "; if (Platform.IsWindows) { text = text.Replace("\r\n", "\n"); } Assert.AreEqual(text, item.Content); item = diff [1]; Assert.IsNotNull(item); Assert.AreEqual("file2", item.FileName.FileName); text = @"diff --git a/file2 b/file2 new file mode 100644 index 0000000..009b64b --- /dev/null +++ b/file2 @@ -0,0 +1 @@ +text2 \ No newline at end of file "; if (Platform.IsWindows) { text = text.Replace("\r\n", "\n"); } Assert.AreEqual(text, item.Content); }
private ICollection <DiffInfo> GetDiffInfoCollection(BigInteger leftBits, BigInteger rightBits, int maxBinaryLength) { ICollection <DiffInfo> diffInfoCollection = new List <DiffInfo>(); BigInteger diffBits = leftBits ^ rightBits; while (!diffBits.IsZero) { DiffInfo diffInfo = GetSingleDiffInfo(diffBits, maxBinaryLength); diffInfoCollection.Add(diffInfo); diffBits >>= maxBinaryLength - diffInfo.Offset; maxBinaryLength = diffInfo.Offset; } return(diffInfoCollection); }
public ArtifactDetails CreateArtifacts(string sourcePath, string targetPath) { var commands = _sitecoreSerializationDiffGenerator.GetDiffCommands(sourcePath, targetPath); var diff = new DiffInfo(commands, "Sitecore Courier Package", string.Empty, string.Format("Diff between folders '{0}' and '{1}'", sourcePath, targetPath)); Update.Engine.PackageGenerator.GeneratePackage(diff, string.Empty, PACKAGE_NAME); CreateItemsToPublishFile(commands); var artifactDetails = new ArtifactDetails { ContentPackageFilePath = PACKAGE_NAME, ItemsToPublishFilePath = ITEM_TO_PUBLISH_FILE }; return artifactDetails; }
/// <summary> /// 静态方法,将Diff保存到文本文件 /// </summary> /// <param name="diffFile">调用DiffFiles方法生成的diffFile</param> /// <param name="fullName">用户输入的diff文件的完整路径</param> public static void SaveDiffToText(DiffInfo diffFile, string fullName) { StreamWriter writer = new StreamWriter(fullName); foreach (Object item in diffFile) { if (item is string) { writer.WriteLine(item); } else { writer.WriteLine("/****Conflict Lines****/!"); } } writer.Close(); }
public DiffData(Repository vc, FilePath root, VersionInfo info, bool remote) { VersionInfo = info; Diff = new Lazy <DiffInfo> (() => { try { DiffInfo result = null; if (!remote) { result = vc.GenerateDiff(root, info); } return(result ?? vc.PathDiff(root, new [] { info.LocalPath }, remote).FirstOrDefault()); } catch (Exception ex) { Exception = ex; return(null); } }); }
public ArtifactDetails CreateArtifacts(string sourcePath, string targetPath) { var commands = _sitecoreSerializationDiffGenerator.GetDiffCommands(sourcePath, targetPath); var diff = new DiffInfo(commands, "Sitecore Courier Package", string.Empty, string.Format("Diff between folders '{0}' and '{1}'", sourcePath, targetPath)); Update.Engine.PackageGenerator.GeneratePackage(diff, string.Empty, PACKAGE_NAME); CreateItemsToPublishFile(commands); var artifactDetails = new ArtifactDetails { ContentPackageFilePath = PACKAGE_NAME, ItemsToPublishFilePath = ITEM_TO_PUBLISH_FILE }; return(artifactDetails); }
/// <summary> /// Mains the specified args. /// </summary> /// <param name="args">The arguments.</param> private static void Main(string[] args) { for (int i = 0; i < args.Length; i++) { string s = args[i]; Console.WriteLine("\t" + s); } string sourcePath = GetArgument("source", args); string targetPath = GetArgument("target", args); string outputPath = GetArgument("output", args); var diff = new DiffInfo( DiffGenerator.GetDiffCommands(sourcePath, targetPath), "Sitecore Courier Package", string.Empty, string.Format("Diff between folders '{0}' and '{1}'", sourcePath, targetPath)); PackageGenerator.GeneratePackage(diff, string.Empty, outputPath); }
/// <summary> /// 静态计算文件相似度方法,根据diffFile信息。因为diffFile中不提供两个文件的长度,因此用参数提供 /// </summary> /// <param name="diffFile"></param> /// <param name="lengthA"></param> /// <param name="lengthB"></param> /// <param name="ignoreEmptyLine"></param> /// <returns></returns> public static float FileSimilarity(DiffInfo diffFile, int lengthA, int lengthB, bool ignoreEmptyLine) { int uniLineCountA = 0; int uniLineCountB = 0; int emptyLineCount = 0; foreach (Object cItem in diffFile) { if (cItem is ConfictItem) { if (((ConfictItem)cItem).contentA != null) { foreach (string line in ((ConfictItem)cItem).contentA) { uniLineCountA++; //统计FileA中冲突项的行数 if (line.Trim() == "") { emptyLineCount++; } //统计空行的数量 } } if (((ConfictItem)cItem).contentB != null) { foreach (string line in ((ConfictItem)cItem).contentB) { uniLineCountB++; //统计FileB中冲突项的行数 if (line.Trim() == "") { emptyLineCount++; } } } } } if (ignoreEmptyLine) { return((float)1 - ((float)(uniLineCountA + uniLineCountB - emptyLineCount) / (float)(lengthA + lengthB - emptyLineCount))); } else { return((float)1 - ((float)(uniLineCountA + uniLineCountB) / (float)(lengthA + lengthB))); } }
/// <summary> /// Handles the Generate_ click event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Generate_Click(object sender, EventArgs e) { var sourcePath = this.SourcePath.Text; var targetPath = this.TargetPath.Text; var result = DiffGenerator.GetDiffCommands(sourcePath, targetPath); var fileName = "SitecoreCourier_{0}.update".FormatWith(Guid.NewGuid()); var filePath = string.Format("{0}/{1}", this.Server.MapPath("/temp"), fileName); result = FilterCommands(result); var diff = new DiffInfo(result, "Sitecore Courier Package", string.Empty, string.Format("Diff has been generated between '{0}' and '{1}'", this.SourcePath.Text, this.TargetPath.Text)); PackageGenerator.GeneratePackage(diff, string.Empty, filePath); this.DownloadLink.NavigateUrl = string.Format("/temp/{0}", fileName); this.DownloadLink.Visible = true; this.AnalyzeResults.Visible = false; }
void IAssetMenuOperations.ShowDiff() { if (LaunchTool.ShowDownloadPlasticExeWindow( mWkInfo, mIsGluonMode, TrackFeatureUseEvent.Features.InstallPlasticCloudFromShowDiff, TrackFeatureUseEvent.Features.InstallPlasticEnterpriseFromFromShowDiff, TrackFeatureUseEvent.Features.CancelPlasticInstallationFromFromShowDiff)) { return; } string selectedPath = AssetsSelection.GetSelectedPath( mAssetSelection.GetSelectedAssets()); DiffInfo diffInfo = null; IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); waiter.Execute( /*threadOperationDelegate*/ delegate { string symbolicName = GetSymbolicName(selectedPath); string extension = Path.GetExtension(selectedPath); diffInfo = PlasticGui.Plastic.API.BuildDiffInfoForDiffWithPrevious( selectedPath, symbolicName, selectedPath, extension, mWkInfo); }, /*afterOperationDelegate*/ delegate { if (waiter.Exception != null) { ExceptionsHandler.DisplayException(waiter.Exception); return; } DiffOperation.DiffWithPrevious( diffInfo, null, null); }); }
/// <summary> /// Mains the specified args. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { Console.WriteLine("Source: {0}", options.Source); Console.WriteLine("Target: {0}", options.Target); Console.WriteLine("Output: {0}", options.Output); var diff = new DiffInfo( DiffGenerator.GetDiffCommands(options.Source, options.Target), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", options.Source, options.Target)); PackageGenerator.GeneratePackage(diff, string.Empty, options.Output); } else { Console.WriteLine(options.GetUsage()); } }
private DiffInfo GetSingleDiffInfo(BigInteger diffBits, int length) { // Trimming trailing zeroes. while ((diffBits & 1) == 0) { length--; diffBits >>= 1; } DiffInfo info = new DiffInfo(); while ((diffBits & 1) == 1) { info.Length++; length--; diffBits >>= 1; } info.Offset = length; return(info); }
protected override void BeginProcessing() { AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Sitecore.Courier.dll.config")); ResetConfigMechanism(); Console.WriteLine("Source: {0}", Source); Console.WriteLine("Target: {0}", Target); Console.WriteLine("Output: {0}", Output); Console.WriteLine("SerializationProvider: {0}", SerializationProvider); Console.WriteLine("CollisionBehavior: {0}", CollisionBehavior); Console.WriteLine("IncludeFiles: {0}", IncludeFiles); RainbowSerializationProvider.Enabled = SerializationProvider == SerializationProvider.Rainbow; RainbowSerializationProvider.IncludeFiles = IncludeFiles; var diff = new DiffInfo( DiffGenerator.GetDiffCommands(Source, Target, CollisionBehavior), "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", Source, Target)); PackageGenerator.GeneratePackage(diff, string.Empty, Output); }
public void TestPushDiff() { var repo2 = (GitRepository)Repo; AddFile("file", "meh", true, true); PostCommit(repo2); AddFile("file1", "text", true, true); AddFile("file2", "text2", true, true); DiffInfo[] diff = repo2.GetPushDiff("origin", "master"); Assert.AreEqual(2, diff.Length); DiffInfo item = diff [0]; Assert.IsNotNull(item); Assert.AreEqual("file1", item.FileName.FileName); //Assert.AreEqual ("text", item.Content); item = diff [1]; Assert.IsNotNull(item); Assert.AreEqual("file2", item.FileName.FileName); //Assert.AreEqual ("text2", item.Content); }
void IPlasticAPI.LaunchDifferences(DiffInfo diffInfo, IToolLauncher xDiffLauncher) { throw new NotImplementedException(); }
/// <summary> /// Mains the specified args. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { var options = new Options(); if (CommandLine.Parser.Default.ParseArguments(args, options)) { Console.WriteLine("Source: {0}", options.Source); Console.WriteLine("Target: {0}", options.Target); Console.WriteLine("Output: {0}", options.Output); Console.WriteLine("Collision behavior: {0}", options.CollisionBehavior); Console.WriteLine("Use Rainbow: {0}", options.UseRainbow); Console.WriteLine("Include Security: {0}", options.IncludeSecurity); Console.WriteLine("Include Files: {0}", options.IncludeFiles); Console.WriteLine("Configuration: {0}", options.Configuration); Console.WriteLine("Ensure Revision: {0}", options.EnsureRevision); Console.WriteLine("Path to project file: {0}", options.ScProjFilePath); Console.WriteLine("DacPac Output: {0}", options.DacPac); string version = Guid.NewGuid().ToString(); SanitizeOptions(options); if (ExclusionHandler.HasValidExclusions(options.Configuration, options.ScProjFilePath)) { var exclusions = ExclusionHandler.GetExcludedItems(options.ScProjFilePath, options.Configuration); ExclusionHandler.RemoveExcludedItems(options.Source, exclusions); ExclusionHandler.RemoveExcludedItems(options.Target, exclusions); } RainbowSerializationProvider.Enabled = options.UseRainbow; RainbowSerializationProvider.IncludeFiles = options.IncludeFiles; RainbowSerializationProvider.EnsureRevision = options.EnsureRevision; var commands = DiffGenerator.GetDiffCommands(options.Source, options.Target, options.IncludeSecurity, version, options.CollisionBehavior); var diff = new DiffInfo( commands, "Sitecore Courier Package", string.Empty, string.Format("Diff between serialization folders '{0}' and '{1}'.", options.Source, options.Target)); if (options.IncludeSecurity) { var currentDirectory = Directory.GetCurrentDirectory(); commands.Add(new PostStepFileSystemDataItem(currentDirectory, string.Empty, PostDeployDll) .GenerateAddCommand().FirstOrDefault()); diff.PostStep = PostStep; diff.Version = version; } if (options.DacPac) { SqlConverter c = new SqlConverter(); c.ConvertPackage(diff, options.Output); var builder = new DacPacBuilder(); DirectoryInfo d = new DirectoryInfo(options.Output); foreach (var file in d.GetFiles("*.sql")) { builder.ConvertToDacPac(file.FullName, Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}.dacpac")); } } else { PackageGenerator.GeneratePackage(diff, string.Empty, options.Output); } } else { Console.WriteLine(options.GetUsage()); } }
public DiffInfo[] GetPushDiff (string remote, string branch) { ObjectId cid1 = RootRepository.Resolve (remote + "/" + branch); ObjectId cid2 = RootRepository.Resolve (RootRepository.GetBranch ()); RevWalk rw = new RevWalk (RootRepository); RevCommit c1 = rw.ParseCommit (cid1); RevCommit c2 = rw.ParseCommit (cid2); List<DiffInfo> diffs = new List<DiffInfo> (); foreach (var change in GitUtil.CompareCommits (RootRepository, c1, c2)) { string diff; switch (change.GetChangeType ()) { case DiffEntry.ChangeType.DELETE: diff = GenerateDiff (EmptyContent, GetCommitContent (c2, change.GetOldPath ())); break; case DiffEntry.ChangeType.ADD: diff = GenerateDiff (GetCommitContent (c1, change.GetNewPath ()), EmptyContent); break; default: diff = GenerateDiff (GetCommitContent (c1, change.GetNewPath ()), GetCommitContent (c2, change.GetNewPath ())); break; } DiffInfo di = new DiffInfo (RootPath, RootRepository.FromGitPath (change.GetNewPath ()), diff); diffs.Add (di); } return diffs.ToArray (); }
/// <summary> /// 在Diff窗口中显示Diff信息 /// </summary> /// <param name="diffInfo">DiffInfo对象</param> public static void ShowDiffInWindow(DiffInfo diffInfo) { }
public DiffInfo[] GetPushDiff (string remote, string branch) { ObjectId cid1 = repo.Resolve (remote + "/" + branch); ObjectId cid2 = repo.Resolve (repo.GetBranch ()); RevWalk rw = new RevWalk (repo); RevCommit c1 = rw.ParseCommit (cid1); RevCommit c2 = rw.ParseCommit (cid2); List<DiffInfo> diffs = new List<DiffInfo> (); foreach (Change change in GitUtil.CompareCommits (repo, c1, c2)) { string diff; switch (change.ChangeType) { case ChangeType.Deleted: diff = GenerateDiff (EmptyContent, GetCommitContent (c2, change.Path)); break; case ChangeType.Added: diff = GenerateDiff (GetCommitContent (c1, change.Path), EmptyContent); break; default: diff = GenerateDiff (GetCommitContent (c1, change.Path), GetCommitContent (c2, change.Path)); break; } DiffInfo di = new DiffInfo (path, FromGitPath (change.Path), diff); diffs.Add (di); } return diffs.ToArray (); }
public Converter(DiffInfo diff, ISqlWriter writer) { this.Diff = diff; this.Writer = writer; }
public class DiffInfo : ArrayList { } //定义DiffInfo类型 //非静态diff方法 //public void StartDiff() //{ //} /// <summary> /// 静态diff方法 /// </summary> /// <param name="fileA"></param> /// <param name="fileB"></param> /// <returns></returns> public static DiffInfo DiffFiles(List <string> fileA, List <string> fileB) { DiffInfo diffFile = new DiffInfo(); ListStringLCS lcsObject = new ListStringLCS(fileA, fileB); //创建一个LCS类的对象 lcsObject.GetLCS(); int lineNoA, lineNoB, prevLineNoA, prevLineNoB; prevLineNoA = 0; prevLineNoB = 0; lineNoA = 0; lineNoB = 0; //将LCS中的项及冲突项依次加入diffFile中 foreach (LCSItem lcsItem in lcsObject.lcs) { int lcsIndex = lcsObject.lcs.IndexOf(lcsItem); lineNoA = lcsItem.lineOfFileA; lineNoB = lcsItem.lintOfFileB; if (lineNoA - prevLineNoA == 1 && lineNoB - prevLineNoB == 1) { } else if (lineNoA - prevLineNoA == 1 && lineNoB - prevLineNoB > 1)//增加的情况 { ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.ADD; cItem.contentA = null; cItem.contentB = new List <string>(); for (int i = prevLineNoB; i < lineNoB - 1; i++) //将fileB中增加的行加入此项 { cItem.contentB.Add(fileB[i]); } diffFile.Add(cItem); //prevLineNoA = lineNoA; //prev指针下移 //prevLineNoB = lineNoB; } else if (lineNoA - prevLineNoA > 1 && lineNoB - prevLineNoB == 1) //删除的情况 { ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.DELETE; cItem.contentA = new List <string>(); cItem.contentB = null; for (int i = prevLineNoA; i < lineNoA - 1; i++) //将fileA中删除的行加入此项 { cItem.contentA.Add(fileA[i]); } diffFile.Add(cItem); //prevLineNoA = lineNoA; //prev指针下移 //prevLineNoB = lineNoB; } //lineNoA - prevLineNoA > 1 && lineNoB - prevLineNoB > 1,同时有增加和删除 else { #region 先后顺序将两边的冲突项加入diffFile //下面分支的作用是将行号靠前的一边构造的冲突项先加入diffFile if (prevLineNoA >= prevLineNoB) { //先加入左边删除项 ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.DELETE; cItem.contentA = new List <string>(); cItem.contentB = null; for (int i = prevLineNoA; i < lineNoA - 1; i++) //将fileA中删除的行加入contentA { cItem.contentA.Add(fileA[i]); } diffFile.Add(cItem); //后加入右边增加项 cItem = new ConfictItem(); cItem.type = ConfictType.ADD; cItem.contentA = null; cItem.contentB = new List <string>(); for (int i = prevLineNoB; i < lineNoB - 1; i++) { cItem.contentB.Add(fileB[i]); } //将fileB中增加的行加入contentB diffFile.Add(cItem); } else { //先加入右边增加项 ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.ADD; cItem.contentA = null; cItem.contentB = new List <string>(); for (int i = prevLineNoB; i < lineNoB - 1; i++) { cItem.contentB.Add(fileB[i]); } diffFile.Add(cItem); //先加入左边删除项 cItem = new ConfictItem(); cItem.type = ConfictType.DELETE; cItem.contentB = null; cItem.contentA = new List <string>(); for (int i = prevLineNoA; i < lineNoA - 1; i++) { cItem.contentA.Add(fileA[i]); } diffFile.Add(cItem); } #endregion //prevLineNoA = lineNoA; //prev指针下移 //prevLineNoB = lineNoB; } #region 将LCS中的项加入diffFile if (lcsItem.isExactSame) //完全相同的项直接加入diffFile { diffFile.Add(lcsItem.lineContent.ToString()); prevLineNoA = lineNoA; //prev指针下移 prevLineNoB = lineNoB; } else//有修改的项作为冲突项加入diffFile { ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.MODIFIED; cItem.contentA = new List <string>(); cItem.contentB = new List <string>(); do//使用循环将连续的有修改的项合并到一个冲突项 { //分隔符前面的内容加入contentA,后面的内容加入contentB int indexDiv = lcsItem.lineContent.ToString().IndexOf("$DIVIDER$"); cItem.contentA.Add(lcsItem.lineContent.ToString().Substring(0, indexDiv)); cItem.contentB.Add(lcsItem.lineContent.ToString().Substring(indexDiv + 9)); diffFile.Add(cItem); //将冲突项加入diffFile prevLineNoA = lineNoA; //prev指针下移 prevLineNoB = lineNoB; } while (lineNoA - prevLineNoA == 1 && lineNoB - prevLineNoB == 1 && !lcsItem.isExactSame); } #endregion } #region 处理剩余项 if (lineNoA < fileA.Count) //如果还有删除项 { ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.DELETE; cItem.contentA = new List <string>(); cItem.contentB = null; for (int i = lineNoA; i < fileA.Count; i++) { cItem.contentA.Add(fileA[i]); } diffFile.Add(cItem); } if (lineNoB < fileB.Count) //如果还有增加项 { ConfictItem cItem = new ConfictItem(); cItem.type = ConfictType.ADD; cItem.contentA = null; cItem.contentB = new List <string>(); for (int i = lineNoB; i < fileB.Count; i++) { cItem.contentB.Add(fileB[i]); } } #endregion return(diffFile); }
public ReadMeEditor(DiffInfo info) { InitializeComponent(); this.diff = info; this.readmeEditArea.Text = this.diff.Readme; }