protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (DesignMode) { return; } string directory = File.Exists(PathToAdd) ? Path.GetDirectoryName(PathToAdd) : PathToAdd; string root = Path.GetPathRoot(directory); projectNameBox.Text = Path.GetFileNameWithoutExtension(PathToAdd); localFolder.Items.Add(directory); while (!root.Equals(directory, StringComparison.OrdinalIgnoreCase)) { directory = SvnTools.GetNormalizedDirectoryName(directory); localFolder.Items.Add(directory); } if (localFolder.Items.Count > 0) { localFolder.SelectedIndex = 0; } }
/// <summary> /// Stores the item in the caching dictionary/ies /// </summary> /// <param name="item"></param> public void StoreItem(SvnItem item) { if (item == null) { throw new ArgumentNullException("item"); } Map[item.FullPath] = item; SvnDirectory dir; if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { if (item.IsDirectory) { ((ISvnDirectoryUpdate)dir).Store(item); } else { ScheduleForCleanup(dir); } } var parentDir = SvnTools.GetNormalizedDirectoryName(item.FullPath); if (string.IsNullOrEmpty(parentDir) || parentDir == item.FullPath) { return; // Skip root directory } if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { ((ISvnDirectoryUpdate)dir)?.Store(item); } }
private bool MaybeProcessAncestorRename(string oldName, string newName) { // If the name of the node itself doesn't change in a rename, it's most likely // a parent rename. if (!string.Equals(Path.GetFileName(oldName), Path.GetFileName(newName))) { return(false); } string oldNode = SvnTools.GetNormalizedDirectoryName(oldName); string newNode = SvnTools.GetNormalizedDirectoryName(newName); if (oldNode == null || newNode == null || String.Equals(oldNode, newNode)) { return(false); } if (_alreadyProcessed.Contains(newNode)) { return(true); } if (MaybeProcessAncestorRename(oldNode, newNode)) { return(true); } if (!_fileOrigins.ContainsKey(newNode)) { return(false); } return(ProcessRename(oldNode, newNode)); }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) { continue; } string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return(true); }
internal void AddParents(string newParent) { SvnAddArgs aa = new SvnAddArgs(); aa.AddParents = true; aa.ThrowOnError = false; aa.Depth = SvnDepth.Empty; Client.Add(SvnTools.GetNormalizedDirectoryName(newParent), aa); }
/// <summary> /// Refreshes this instance. /// </summary> public void Refresh() { ISccProjectInfo projectInfo; if (_project.IsSolution) { SvnItem rootItem = SolutionSettings.ProjectRootSvnItem; SetValues( Scc.IsSolutionManaged, "Solution: " + Path.GetFileNameWithoutExtension(SolutionSettings.SolutionFilename), SafeRepositoryRoot(rootItem), SafeRepositoryPath(rootItem), GetStatus(rootItem, null, SolutionSettings.SolutionFilename), (rootItem != null) ? EmptyToDot(SvnItem.MakeRelative(rootItem.FullPath, SvnTools.GetNormalizedDirectoryName(SolutionSettings.SolutionFilename))) : "", (rootItem != null) ? rootItem.FullPath : "" ); } else if (null != (projectInfo = ProjectMap.GetProjectInfo(_project)) && null != (projectInfo.ProjectDirectory) && null != (projectInfo.SccBaseDirectory)) { SvnItem dirItem = Cache[projectInfo.SccBaseDirectory]; SetValues( Scc.IsProjectManaged(_project), projectInfo.UniqueProjectName, SafeRepositoryRoot(dirItem), SafeRepositoryPath(dirItem), GetStatus(dirItem, projectInfo, projectInfo.ProjectFile), EmptyToDot(SvnItem.MakeRelative(projectInfo.SccBaseDirectory, projectInfo.ProjectDirectory)), projectInfo.SccBaseDirectory ); } else { // Should have been filtered before; probably a buggy project that changed while the dialog was open SetValues( false, "-?-", "-?-", "-?-", "-?-", "-?-", "-?-" ); } }
private void okButton_Click(object sender, EventArgs e) { IAnkhSolutionSettings settings = Context.GetService <IAnkhSolutionSettings>(); UriMap map = slnBindPath.SelectedItem as UriMap; if (map == null) { return; } if (settings.ProjectRootUri != null && map.Uri != settings.ProjectRootUri) { string dir = SvnTools.GetNormalizedDirectoryName(settings.SolutionFilename); settings.ProjectRoot = SvnTools.GetNormalizedFullPath(Path.Combine(dir, map.Value)); } }
public void RemoveItem(SvnItem item) { if (item == null) { throw new ArgumentNullException("item"); } var deleted = false; SvnDirectory dir; if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { // The item is a directory itself.. remove it's map if (dir.Directory == item) { DirectoryMap.Remove(item.FullPath); deleted = true; } } SvnItem other; if (Map.TryGetValue(item.FullPath, out other)) { if (item == other) { Map.Remove(item.FullPath); } } if (!deleted) { return; } var parentDir = SvnTools.GetNormalizedDirectoryName(item.FullPath); if (string.IsNullOrEmpty(parentDir) || parentDir == item.FullPath) { return; // Skip root directory } if (DirectoryMap.TryGetValue(item.FullPath, out dir)) { dir.Remove(item.FullPath); } }
void SetProjectRootValue(string value) { if (SolutionFilename == null) { return; } string sd = SvnTools.PathToRelativeUri(SvnTools.GetNormalizedDirectoryName(SolutionFilename).TrimEnd('\\') + '\\').ToString(); string v = SvnTools.PathToRelativeUri(SvnTools.GetNormalizedFullPath(value)).ToString(); if (!v.EndsWith("/")) { v += "/"; } if (!sd.StartsWith(v, StringComparison.OrdinalIgnoreCase)) { return; } Uri solUri; Uri resUri; if (!Uri.TryCreate("file:///" + sd.Replace('\\', '/'), UriKind.Absolute, out solUri) || !Uri.TryCreate("file:///" + v.Replace('\\', '/'), UriKind.Absolute, out resUri)) { return; } using (SvnClient client = GetService <ISvnClientPool>().GetNoUIClient()) { SvnSetPropertyArgs ps = new SvnSetPropertyArgs(); ps.ThrowOnError = false; client.SetProperty(SolutionFilename, AnkhSccPropertyNames.ProjectRoot, solUri.MakeRelativeUri(resUri).ToString(), ps); GetService <ISvnStatusCache>().MarkDirty(SolutionFilename); // The getter will reload the settings for us } _cache = null; }
private void OnOpenFolder(object sender, CommandEventArgs e) { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.Exists) { System.Diagnostics.Process.Start(item.IsDirectory ? item.FullPath : SvnTools.GetNormalizedDirectoryName(item.FullPath)); } } }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } var walkPath = path; var walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } var args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { ISvnDirectoryUpdate updateDir; SvnItem walkItem = null; // We get more information for free, lets use that to update other items DirectoryMap.TryGetValue(walkPath, out var directory); if (null != directory) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one directory = new SvnDirectory(walkPath); updateDir = directory = GetDirectory(walkPath); DirectoryMap[walkPath] = directory; } bool ok; var statSelf = false; var noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf && null != walkItem) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { var truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!Map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
public void Path_NormalizePathSharp() { Assert.That(SvnTools.GetNormalizedFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\\"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), "Shortcut route via IsNormalized"); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf\\sad sad sad f\\"), Is.EqualTo("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf")); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); string drive = Environment.CurrentDirectory.Substring(0, 2).ToLowerInvariant(); Assert.That(SvnTools.GetNormalizedDirectoryName(drive), Is.EqualTo(drive.ToUpperInvariant() + Path.GetDirectoryName(Environment.CurrentDirectory).Substring(2))); // CWD on current drive Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("c:\\a"), Is.EqualTo("C:\\")); Assert.That(Path.GetDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\Server\Share")); Assert.That(Path.GetDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub\"), Is.EqualTo(@"C:\Dir\Sub")); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub"), Is.EqualTo(@"C:\Dir")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\server\Share")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$\\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\server\c$"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\seRver\c$\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\seRver\c$\\"), Is.Null); string share = @"\\" + Environment.MachineName.ToLowerInvariant() + @"\C$"; string shaUC = @"\\" + Environment.MachineName.ToUpperInvariant() + @"\C$"; Assert.That(SvnTools.IsNormalizedFullPath(share)); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC)); Assert.That(!SvnTools.IsNormalizedFullPath(share + "\\")); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC + "\\")); Assert.That(SvnTools.GetTruePath(share + "\\A\\B", true), Is.EqualTo(share + "\\A\\B")); Assert.That(SvnTools.GetTruePath(share + "\\A", true), Is.EqualTo(share + "\\A")); Assert.That(SvnTools.GetTruePath(share, true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath(share + "\\", true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath("C:\\A", true), Is.EqualTo("C:\\A")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } string walkPath = path; bool walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } SvnStatusArgs args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { SvnDirectory directory; ISvnDirectoryUpdate updateDir; SvnItem walkItem; // We get more information for free, lets use that to update other items if (_dirMap.TryGetValue(walkPath, out directory)) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one updateDir = directory = new SvnDirectory(Context, walkPath); _dirMap[walkPath] = directory; } walkItem = directory.Directory; bool ok; bool statSelf = false; bool noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (!ok) { if (args.LastException != null) { switch (args.LastException.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT: if (CommandService != null) { CommandService.PostExecCommand(AnkhCommand.NotifyWcToNew, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED: _enableUpgrade = true; if (updateDir != null) { updateDir.SetNeedsUpgrade(); } if (!_sendUpgrade && CommandService != null) { _sendUpgrade = true; CommandService.PostExecCommand(AnkhCommand.NotifyUpgradeRequired, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY: // Status only reports this error if there is no ancestor working copy // We should avoid statting all parent directories again for .IsVersionable noWcAtAll = true; break; case SvnErrorCode.SVN_ERR_WC_CLEANUP_REQUIRED: if (updateDir != null) { updateDir.SetNeedsCleanup(); } break; } } statSelf = true; } else if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { string truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!_map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
public override void OnExecute(CommandEventArgs e) { HybridCollection <string> dirs = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true)) { SvnDirectory dir = i.ParentDirectory; if (dir != null && dir.NeedsWorkingCopyUpgrade && !dirs.Contains(dir.FullPath)) { dirs.Add(dir.FullPath); } else if (i.IsDirectory && i.AsDirectory().NeedsWorkingCopyUpgrade&& !dirs.Contains(i.FullPath)) { dirs.Add(i.FullPath); } } e.GetService <IProgressRunner>().RunModal(CommandStrings.UpgradingWorkingCopy, delegate(object sender, ProgressWorkerArgs a) { HybridCollection <string> done = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (string dir in dirs) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (done.Contains(dir)) { continue; } if (a.Client.Info(dir, ia, null) || ia.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED) { continue; } SvnUpgradeArgs ua = new SvnUpgradeArgs(); ua.ThrowOnError = false; /* Capture the already upgraded directories to avoid a lot of work */ ua.Notify += delegate(object sender2, SvnNotifyEventArgs n) { if (n.Action == SvnNotifyAction.UpgradedDirectory) { if (!done.Contains(n.FullPath)) { done.Add(n.FullPath); } } }; string tryDir = dir; while (true) { if (a.Client.Upgrade(tryDir, ua) || ua.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_INVALID_OP_ON_CWD) { break; } string pd = SvnTools.GetNormalizedDirectoryName(tryDir); if (pd == tryDir || string.IsNullOrEmpty(pd)) { break; } tryDir = pd; } } }); if (dirs.Count > 0) { StatusCache.ResetUpgradeWarning(); } }
public void Path_NormalizePathSharp() { Assert.That(SvnTools.GetNormalizedFullPath("c:\\a\\..\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\\"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), Is.EqualTo("C:\\123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" + "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"), "Shortcut route via IsNormalized"); if (File.Exists("C:\\Progra~1")) { Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\Progra~1"), Is.EqualTo("C:\\Program Files")); } Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf\\sad sad sad f\\"), Is.EqualTo("C:\\asdasdashdadhjadjahjdhasjhajhfasdjsdf\\sdsdfsdfsdfgsdjhfsda hjsdsdf sdaf")); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); string drive = Environment.CurrentDirectory.Substring(0, 2).ToLowerInvariant(); var curDir = Environment.CurrentDirectory; if (curDir.Contains("~")) { // This case triggers on the GitHub bot curDir = SvnTools.GetNormalizedFullPath(curDir); } Assert.That(SvnTools.GetNormalizedDirectoryName(drive), Is.EqualTo(drive.ToUpperInvariant() + Path.GetDirectoryName(curDir).Substring(2))); // CWD on current drive Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("C:\\\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName("c:\\a"), Is.EqualTo("C:\\")); Assert.That(Path.GetDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\Server\Share")); Assert.That(Path.GetDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub\"), Is.EqualTo(@"C:\Dir\Sub")); Assert.That(Path.GetDirectoryName(@"C:\Dir\Sub"), Is.EqualTo(@"C:\Dir")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share\Path"), Is.EqualTo(@"\\server\Share")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\Server\Share"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$"), Is.Null); Assert.That(Path.GetDirectoryName(@"\\server\c$\\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\server\c$"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedFullPath(@"\\seRver\c$\"), Is.EqualTo(@"\\server\c$")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\server\c$\\"), Is.Null); Assert.That(SvnTools.GetNormalizedDirectoryName(@"\\seRver\c$\\"), Is.Null); string share = @"\\" + Environment.MachineName.ToLowerInvariant() + @"\C$"; string shaUC = @"\\" + Environment.MachineName.ToUpperInvariant() + @"\C$"; Assert.That(SvnTools.IsNormalizedFullPath(share)); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC)); Assert.That(!SvnTools.IsNormalizedFullPath(share + "\\")); Assert.That(!SvnTools.IsNormalizedFullPath(shaUC + "\\")); Assert.That(SvnTools.GetTruePath(share + "\\A\\B", true), Is.EqualTo(share + "\\A\\B")); Assert.That(SvnTools.GetTruePath(share + "\\A", true), Is.EqualTo(share + "\\A")); Assert.That(SvnTools.GetTruePath(share, true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath(share + "\\", true), Is.EqualTo(share)); Assert.That(SvnTools.GetTruePath("C:\\A", true), Is.EqualTo("C:\\A")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\dir\\"), Is.EqualTo(@"C:\")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"C:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(@"c:\sub\dir\\"), Is.EqualTo(@"C:\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\dir\\"), Is.EqualTo(share)); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(share + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedDirectoryName(shaUC + @"\sub\dir\\"), Is.EqualTo(share + @"\sub")); Assert.That(SvnTools.GetNormalizedFullPath("c:\\"), Is.EqualTo("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("C:\\"), Is.EqualTo("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("C:"), Does.StartWith("C:\\")); Assert.That(SvnTools.GetNormalizedFullPath("c:"), Does.StartWith("C:\\")); }