public static bool UpdateDir(SvnClient client, string name, SvnDepth depth, out SvnUpdateResult result, string revision = null) { return(client.Update(name, new SvnUpdateArgs { Revision = SubversionHelper.MakeRevision(revision), Depth = depth, IgnoreExternals = true, KeepDepth = true }, out result)); }
public override string Update(IPackageTree packageTree, FileSystemInfo destination) { SvnUpdateResult result = null; using (var client = new SvnClient()) { try { client.Update(destination.FullName, out result); } catch (SvnRepositoryIOException sre) { HandleExceptions(sre); } catch (SvnObstructedUpdateException sue) { HandleExceptions(sue); } } return(result.Revision.ToString()); }
internal bool CheckOut(SvnUriTarget target, string path, SvnCheckOutArgs args, out SvnUpdateResult result) { bool checkoutResult; using (SharpSvn.SvnClient client = new SharpSvn.SvnClient()) { client.Authentication.ForceCredentials("selin", "123456"); checkoutResult = client.CheckOut(new Uri("https://DESKTOP-CK68HBF/svn/test"), path, out result); } return(checkoutResult); }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List <string> filesAdd = new List <string>(); List <string> filesDelete = new List <string>(); List <string> filesModify = new List <string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (!changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (!File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
private static void PerformUpdate(CommandEventArgs e, ProgressWorkerArgs wa, SvnRevision rev, bool allowUnversionedObstructions, bool updateExternals, bool setDepthInfinity, IEnumerable <UpdateGroup> groups, out SvnUpdateResult updateResult) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = rev; ua.AllowObstructions = allowUnversionedObstructions; ua.IgnoreExternals = !updateExternals; ua.KeepDepth = setDepthInfinity; updateResult = null; HybridCollection <string> handledExternals = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object ss, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.UpdateExternal) { if (!handledExternals.Contains(ee.FullPath)) { handledExternals.Add(ee.FullPath); } } }; e.Context.GetService <IConflictHandler>().RegisterConflictHandler(ua, wa.Synchronizer); foreach (UpdateGroup group in groups) { if (handledExternals.Contains(group.WorkingCopyRoot)) { continue; } group.Nodes.Sort(StringComparer.OrdinalIgnoreCase); // Currently Subversion runs update per item passed and in // Subversion 1.6 passing each item separately is actually // a tiny bit faster than passing them all at once. // (sleep_for_timestamp fails its fast route) foreach (string path in group.Nodes) { if (handledExternals.Contains(path)) { continue; } SvnUpdateResult result; wa.Client.Update(path, ua, out result); if (updateResult == null) { updateResult = result; // Return the primary update as version for output } } } }
public override void OnExecute(CommandEventArgs e) { IAnkhServiceEvents ci = e.GetService <IAnkhServiceEvents>(); if (ci != null) { ci.OnLastChanged(new LastChangedEventArgs(null, null)); } SvnRevision rev; bool allowUnversionedObstructions = false; bool updateExternals = true; bool setDepthInfinity = true; IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>(); ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); Uri reposRoot = null; if (IsHeadCommand(e.Command) || e.DontPrompt) { rev = SvnRevision.Head; } else if (IsSolutionCommand(e.Command)) { SvnItem projectItem = settings.ProjectRootSvnItem; Debug.Assert(projectItem != null, "Has item"); using (UpdateDialog ud = new UpdateDialog()) { ud.ItemToUpdate = projectItem; ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } else if (IsFolderCommand(e.Command)) { SvnItem dirItem = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false)); Debug.Assert(dirItem != null && dirItem.IsDirectory && dirItem.IsVersioned); using (UpdateDialog ud = new UpdateDialog()) { ud.Text = CommandStrings.UpdateFolder; ud.FolderLabelText = CommandStrings.UpdateFolderLabel; ud.ItemToUpdate = dirItem; ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } else { // We checked there was only a single repository to select a revision // from in OnUpdate, so we can suffice with only calculate the path SvnItem si = null; SvnOrigin origin = null; foreach (SccProject p in GetSelectedProjects(e)) { ISccProjectInfo pi = mapper.GetProjectInfo(p); if (pi == null || pi.ProjectDirectory == null) { continue; } SvnItem item = cache[pi.ProjectDirectory]; if (!item.IsVersioned) { continue; } if (si == null && origin == null) { si = item; origin = new SvnOrigin(item); reposRoot = item.WorkingCopy.RepositoryRoot; } else { si = null; string urlPath1 = origin.Uri.AbsolutePath; string urlPath2 = item.Uri.AbsolutePath; int i = 0; while (i < urlPath1.Length && i < urlPath2.Length && urlPath1[i] == urlPath2[i]) { i++; } while (i > 0 && urlPath1[i - 1] != '/') { i--; } origin = new SvnOrigin(new Uri(origin.Uri, urlPath1.Substring(0, i)), origin.RepositoryRoot); } } Debug.Assert(origin != null); using (UpdateDialog ud = new UpdateDialog()) { ud.Text = CommandStrings.UpdateProject; if (si != null) { ud.ItemToUpdate = si; } else { ud.SvnOrigin = origin; ud.SetMultiple(true); } ud.Revision = SvnRevision.Head; if (ud.ShowDialog(e.Context) != DialogResult.OK) { return; } rev = ud.Revision; allowUnversionedObstructions = ud.AllowUnversionedObstructions; updateExternals = ud.UpdateExternals; setDepthInfinity = ud.SetDepthInfinty; } } Dictionary <string, SvnItem> itemsToUpdate = new Dictionary <string, SvnItem>(StringComparer.OrdinalIgnoreCase); SortedList <string, UpdateGroup> groups = new SortedList <string, UpdateGroup>(StringComparer.OrdinalIgnoreCase); // Get a list of all documents below the specified paths that are open in editors inside VS HybridCollection <string> lockPaths = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); foreach (SvnItem item in GetAllUpdateRoots(e)) { // GetAllUpdateRoots can (and probably will) return duplicates! if (itemsToUpdate.ContainsKey(item.FullPath) || !item.IsVersioned) { continue; } SvnWorkingCopy wc = item.WorkingCopy; if (!IsHeadCommand(e.Command) && reposRoot != null) { // Specific revisions are only valid on a single repository! if (wc != null && wc.RepositoryRoot != reposRoot) { continue; } } UpdateGroup group; if (!groups.TryGetValue(wc.FullPath, out group)) { group = new UpdateGroup(wc.FullPath); groups.Add(wc.FullPath, group); } group.Nodes.Add(item.FullPath); itemsToUpdate.Add(item.FullPath, item); foreach (string file in documentTracker.GetDocumentsBelow(item.FullPath)) { if (!lockPaths.Contains(file)) { lockPaths.Add(file); } } } documentTracker.SaveDocuments(lockPaths); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(lockPaths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { SvnUpdateResult updateResult = null; ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; string title; if (IsSolutionCommand(e.Command)) { title = CommandStrings.UpdatingSolution; } else if (IsFolderCommand(e.Command)) { title = CommandStrings.UpdatingFolder; } else { title = CommandStrings.UpdatingProject; } e.GetService <IProgressRunner>().RunModal(title, pa, delegate(object sender, ProgressWorkerArgs a) { PerformUpdate(e, a, rev, allowUnversionedObstructions, updateExternals, setDepthInfinity, groups.Values, out updateResult); }); if (ci != null && updateResult != null && IsSolutionCommand(e.Command)) { ci.OnLastChanged(new LastChangedEventArgs(CommandStrings.UpdatedToTitle, updateResult.Revision.ToString())); } } }
private static void PerformUpdate(CommandEventArgs e, ProgressWorkerArgs wa, SvnRevision rev, bool allowUnversionedObstructions, bool updateExternals, bool setDepthInfinity, IEnumerable<List<string>> groups, out SvnUpdateResult updateResult) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = rev; ua.AllowObstructions = allowUnversionedObstructions; ua.IgnoreExternals = !updateExternals; ua.KeepDepth = setDepthInfinity; updateResult = null; HybridCollection<string> handledExternals = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object ss, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.UpdateExternal) { if (!handledExternals.Contains(ee.FullPath)) handledExternals.Add(ee.FullPath); } }; e.Context.GetService<IConflictHandler>().RegisterConflictHandler(ua, wa.Synchronizer); foreach (List<string> group in groups) { // Currently Subversion runs update per item passed and in // Subversion 1.6 passing each item separately is actually // a tiny bit faster than passing them all at once. // (sleep_for_timestamp fails its fast route) foreach (string path in group) { if (handledExternals.Contains(path)) continue; SvnUpdateResult result; wa.Client.Update(path, ua, out result); if (updateResult == null) updateResult = result; // Return the primary update as version for output } } }
private void ReadResults(SvnUpdateResult result) { IDictionary<string, SvnUpdateResult> results = result.ResultMap; foreach (string key in results.Keys) { SvnUpdateResult updateResult = results[key]; Log.LogMessage(MessageImportance.Normal, "[{0} - {1}]", key, updateResult.Revision); } }
public void Copy() { Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = true; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.simulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } foreach (SvnChangeItem changeItem in changeItems.Values) { string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine("{0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: { Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } break; case SvnChangeAction.Delete: { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; _client.Delete(targetPath, svnDeleteArgs); } break; } } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Commiting {0}", _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } _client.Commit(_args.Destination, commitArgs); } }