public override void OnExecute(CommandEventArgs e) { List <string> toAdd = new List <string>(); List <SvnItem> items = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (item.IsVersioned) { items.Add(item); } else if (item.IsFile && item.IsVersionable && item.InSolution && !item.IsIgnored && !item.IsSccExcluded) { toAdd.Add(item.FullPath); // Add new files ### Alternative: Show them as added items.Add(item); } } if (items.Count == 0) { return; } SvnRevision start = SvnRevision.Base; SvnRevision end = SvnRevision.Working; // should we show the path selector? if (e.ShouldPrompt(true)) { using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.UnifiedDiffTitle; dlg.Items = items; dlg.RevisionStart = start; dlg.RevisionEnd = end; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } items.Clear(); items.AddRange(dlg.GetCheckedItems()); start = dlg.RevisionStart; end = dlg.RevisionEnd; } } if (items.Count == 0) { return; } SvnRevisionRange revRange = new SvnRevisionRange(start, end); IAnkhTempFileManager tempfiles = e.GetService <IAnkhTempFileManager>(); string tempFile = tempfiles.GetTempFile(".patch"); IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); string slndir = ss.ProjectRoot; using (MemoryStream stream = new MemoryStream()) { e.Context.GetService <IProgressRunner>().RunModal(CommandStrings.RunningDiff, delegate(object sender, ProgressWorkerArgs ee) { SvnAddArgs aa = new SvnAddArgs(); aa.ThrowOnError = false; aa.AddParents = false; foreach (string item in toAdd) { ee.Client.Add(item, aa); } SvnDiffArgs diffArgs = new SvnDiffArgs(); diffArgs.IgnoreAncestry = true; diffArgs.NoDeleted = false; diffArgs.ThrowOnError = false; foreach (SvnItem item in items) { SvnWorkingCopy wc; if (!string.IsNullOrEmpty(slndir) && item.IsBelowPath(slndir)) { diffArgs.RelativeToPath = slndir; } else if ((wc = item.WorkingCopy) != null) { diffArgs.RelativeToPath = wc.FullPath; } else { diffArgs.RelativeToPath = null; } if (!ee.Client.Diff(item.FullPath, revRange, diffArgs, stream)) { if (diffArgs.LastException != null) { StreamWriter sw = new StreamWriter(stream); sw.WriteLine(); sw.WriteLine(string.Format("# {0}: {1}", item.FullPath, diffArgs.LastException.Message)); sw.Flush(); // Don't dispose the writer as that might close the stream } if (diffArgs.IsLastInvocationCanceled) { break; } } } stream.Flush(); }); stream.Position = 0; using (StreamReader sr = new StreamReader(stream)) { File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8); VsShellUtilities.OpenDocument(e.Context, tempFile); } } }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> selectedFiles = new List <SvnItem>(); if (e.Command == AnkhCommand.DocumentShowChanges) { SvnItem item = e.Selection.ActiveDocumentSvnItem; if (item == null) { return; } selectedFiles.Add(item); } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (!item.IsVersioned || (item.Status.LocalNodeStatus == SvnStatus.Added && !item.Status.IsCopied)) { continue; } if (e.Command == AnkhCommand.ItemCompareBase || e.Command == AnkhCommand.ItemShowChanges) { if (!(item.IsModified || item.IsDocumentDirty) || !item.IsLocalDiffAvailable // exclude if local diff is not available ) { continue; } } if (e.Command == AnkhCommand.DiffLocalItem && !NotDeletedFilter(item)) { continue; } selectedFiles.Add(item); } } SvnRevisionRange revRange = null; switch (e.Command) { case AnkhCommand.DiffLocalItem: break; // revRange null -> show selector case AnkhCommand.ItemCompareBase: case AnkhCommand.ItemShowChanges: case AnkhCommand.DocumentShowChanges: revRange = new SvnRevisionRange(SvnRevision.Base, SvnRevision.Working); break; case AnkhCommand.ItemCompareCommitted: revRange = new SvnRevisionRange(SvnRevision.Committed, SvnRevision.Working); break; case AnkhCommand.ItemCompareLatest: revRange = new SvnRevisionRange(SvnRevision.Head, SvnRevision.Working); break; case AnkhCommand.ItemComparePrevious: revRange = new SvnRevisionRange(SvnRevision.Previous, SvnRevision.Working); break; } if (e.PromptUser || selectedFiles.Count > 1 || revRange == null) { SvnRevision start = revRange == null ? SvnRevision.Base : revRange.StartRevision; SvnRevision end = revRange == null ? SvnRevision.Working : revRange.EndRevision; // should we show the path selector? if (e.PromptUser || !Shift) { using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.CompareFilesTitle; dlg.Items = selectedFiles; dlg.RevisionStart = start; dlg.RevisionEnd = end; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } selectedFiles.Clear(); selectedFiles.AddRange(dlg.GetCheckedItems()); start = dlg.RevisionStart; end = dlg.RevisionEnd; } } revRange = new SvnRevisionRange(start, end); } if (revRange.EndRevision.RevisionType == SvnRevisionType.Working || revRange.StartRevision.RevisionType == SvnRevisionType.Working) { // Save only the files needed IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); if (tracker != null) { tracker.SaveDocuments(SvnItem.GetPaths(selectedFiles)); } } IAnkhDiffHandler diff = e.GetService <IAnkhDiffHandler>(); foreach (SvnItem item in selectedFiles) { AnkhDiffArgs da = new AnkhDiffArgs(); if ((item.Status.IsCopied || item.IsReplaced) && (!revRange.StartRevision.RequiresWorkingCopy || !revRange.EndRevision.RequiresWorkingCopy)) { // The file is copied, use its origins history instead of that of the new file SvnUriTarget copiedFrom = diff.GetCopyOrigin(item); // TODO: Maybe handle Previous/Committed as history if (copiedFrom != null && !revRange.StartRevision.RequiresWorkingCopy) { if (null == (da.BaseFile = diff.GetTempFile(copiedFrom, revRange.StartRevision, true))) { return; // Canceled } da.BaseTitle = diff.GetTitle(copiedFrom, revRange.StartRevision); } if (copiedFrom != null && !revRange.EndRevision.RequiresWorkingCopy) { if (null == (da.MineFile = diff.GetTempFile(copiedFrom, revRange.EndRevision, true))) { return; // Canceled } da.MineTitle = diff.GetTitle(copiedFrom, revRange.EndRevision); } } if (da.BaseFile == null) { if (null == (da.BaseFile = (revRange.StartRevision == SvnRevision.Working) ? item.FullPath : diff.GetTempFile(item, revRange.StartRevision, true))) { return; // Canceled } da.BaseTitle = diff.GetTitle(item, revRange.StartRevision); } if (da.MineFile == null) { if (null == (da.MineFile = (revRange.EndRevision == SvnRevision.Working) ? item.FullPath : diff.GetTempFile(item, revRange.EndRevision, true))) { return; // Canceled } da.MineTitle = diff.GetTitle(item, revRange.EndRevision); } if (!String.Equals(da.MineFile, item.FullPath, StringComparison.OrdinalIgnoreCase)) { da.ReadOnly = true; } diff.RunDiff(da); } }
public override void OnExecute(CommandEventArgs e) { SvnRevision updateTo; List <string> files = new List <string>(); if (e.Command == AnkhCommand.UpdateItemSpecific || e.Command == AnkhCommand.UpdateProjectFileSpecific) { updateTo = SvnRevision.Head; List <SvnItem> items = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (item.IsFile && item.IsVersioned) { items.Add(item); } } using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.UpdateFilesTitle; dlg.Items = items; dlg.RevisionStart = updateTo; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } files.AddRange(SvnItem.GetPaths(dlg.GetCheckedItems())); updateTo = dlg.RevisionStart; } } else { updateTo = SvnRevision.Head; List <SvnItem> dirs = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsVersioned) { continue; } bool found = false; foreach (SvnItem p in dirs) { if (item.IsBelowPath(p) && p.WorkingCopy == item.WorkingCopy) { found = true; break; } } if (found) { continue; } files.Add(item.FullPath); if (item.IsDirectory) { dirs.Add(item); } } } IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); tracker.SaveDocuments(e.Selection.GetSelectedFiles(true)); using (DocumentLock lck = tracker.LockDocuments(files, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { SvnUpdateResult ur; ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; e.GetService <IProgressRunner>().RunModal(CommandStrings.UpdatingTitle, pa, delegate(object sender, ProgressWorkerArgs ee) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Depth = SvnDepth.Infinity; ua.Revision = updateTo; e.GetService <IConflictHandler>(). RegisterConflictHandler(ua, ee.Synchronizer); ee.Client.Update(files, ua, out ur); }); } }