public override void OnExecute(CommandEventArgs e) { IPendingChangesManager pcm = e.GetService <IPendingChangesManager>(); PendingChange.RefreshContext rc = new PendingChange.RefreshContext(e.Context); Dictionary <string, PendingChange> selectedChanges = new Dictionary <string, PendingChange>(StringComparer.OrdinalIgnoreCase); List <SvnItem> resources = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { PendingChange pc; if (PendingChange.CreateIfPending(rc, item, out pc)) { if (!pc.IsNoChangeForPatching()) { selectedChanges.Add(pc.FullPath, pc); resources.Add(pc.SvnItem); } } } if (resources.Count == 0) { return; } using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.CreatePatchTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(resources); DialogResult dr = pcs.ShowDialog(e.Context); if (dr != DialogResult.OK) { return; } string fileName = GetFileName(e.Context.DialogOwner); if (string.IsNullOrEmpty(fileName)) { return; } PendingChangeCreatePatchArgs pca = new PendingChangeCreatePatchArgs(); pca.FileName = fileName; IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); pca.RelativeToPath = ss.ProjectRoot; pca.AddUnversionedFiles = true; List <PendingChange> patchChanges = new List <PendingChange>(pcs.GetSelection()); e.GetService <IPendingChangeHandler>().CreatePatch(patchChanges, pca); } }
public void DoCreatePatch(string fileName) { if (string.IsNullOrEmpty(fileName)) { return; } PendingChangeCreatePatchArgs a = new PendingChangeCreatePatchArgs(); a.FileName = fileName; IAnkhSolutionSettings ss = Context.GetService <IAnkhSolutionSettings>(); a.RelativeToPath = ss.ProjectRoot; a.AddUnversionedFiles = true; List <PendingChange> changes = new List <PendingChange>(UI.CheckedItems); if (Context.GetService <IPendingChangeHandler>().CreatePatch(changes, a)) { } }
public bool CreatePatch(IEnumerable <PendingChange> changes, PendingChangeCreatePatchArgs args) { using (PendingCommitState state = new PendingCommitState(Context, changes)) { if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'first' { return(false); } if (!PreCommit_SaveDirty(state)) { return(false); } if (args.AddUnversionedFiles) { if (!PreCommit_AddNewFiles(state)) { return(false); } if (!PreCommit_HandleMissingFiles(state)) { return(false); } } state.FlushState(); if (!PreCommit_AddNeededParents(state)) { return(false); } if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'again' { return(false); } } string relativeToPath = args.RelativeToPath; string relativeToPathP = relativeToPath.EndsWith("\\") ? relativeToPath : (relativeToPath + "\\"); string fileName = args.FileName; SvnRevisionRange revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working); SvnDiffArgs a = new SvnDiffArgs(); a.IgnoreAncestry = true; a.NoDeleted = false; a.Depth = SvnDepth.Empty; using (MemoryStream stream = new MemoryStream()) { GetService <IProgressRunner>().RunModal(PccStrings.DiffTitle, delegate(object sender, ProgressWorkerArgs e) { foreach (PendingChange pc in changes) { SvnItem item = pc.SvnItem; SvnWorkingCopy wc; if (!string.IsNullOrEmpty(relativeToPath) && item.FullPath.StartsWith(relativeToPathP, StringComparison.OrdinalIgnoreCase)) { a.RelativeToPath = relativeToPath; } else if ((wc = item.WorkingCopy) != null) { a.RelativeToPath = wc.FullPath; } else { a.RelativeToPath = null; } e.Client.Diff(item.FullPath, revRange, a, stream); } stream.Flush(); stream.Position = 0; }); using (StreamReader sr = new StreamReader(stream)) { string line; // Parse to lines to resolve EOL issues using (StreamWriter sw = File.CreateText(fileName)) { while (null != (line = sr.ReadLine())) { sw.WriteLine(line); } } } } return(true); }