public override void OnExecute(CommandEventArgs e) { ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>()); if (item == null) { return; } string newName = item.Origin.Target.FileName; if (e.Argument != null) { string[] items = e.Argument as string[]; if (items != null) { if (items.Length == 1) { newName = items[0]; } else if (items.Length > 1) { newName = items[1]; } } } string logMessage; using (RenameDialog dlg = new RenameDialog()) { dlg.Context = e.Context; dlg.OldName = item.Origin.Target.FileName; dlg.NewName = newName; if (DialogResult.OK != dlg.ShowDialog(e.Context)) { return; } newName = dlg.NewName; logMessage = dlg.LogMessage; } try { Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri); e.GetService <IProgressRunner>().RunModal(CommandStrings.RenamingNodes, delegate(object sender, ProgressWorkerArgs we) { SvnMoveArgs ma = new SvnMoveArgs(); ma.LogMessage = logMessage; we.Client.RemoteMove(itemUri, new Uri(itemUri, newName), ma); }); } finally { item.RefreshItem(true); } }
static void Test10() { var homeUri = new Uri("http://192.168.1.105/svn/BIST/release"); var tgtUri = SvnTools.GetNormalizedUri(new Uri("http://192.168.1.105/svn/BIST/../modelsBinaries/missiontrModels/trunk")); var client = new SvnClient(); SvnInfoEventArgs homeInfo; if (!client.GetInfo(homeUri, out homeInfo)) { return; } string homeRepoUrl = homeInfo.RepositoryRoot.AbsoluteUri; SvnInfoEventArgs tgtInfo; if (!client.GetInfo(tgtUri, out tgtInfo)) { return; } string tgtRepoUrl = tgtInfo.RepositoryRoot.AbsoluteUri; string relativizedUrl; Exter.TryMakeRelativeReference(client, tgtUri.AbsoluteUri, homeRepoUrl, out relativizedUrl); }
public void RefreshItem(bool refreshParent) { if (TreeNode != null) { Uri uri = null; if (refreshParent && null != TreeNode.Parent && null != TreeNode.Origin) { uri = ((RepositoryTreeNode)this.TreeNode.Parent).NormalizedUri; } else { uri = TreeNode.NormalizedUri; } if (uri != null && this.TreeNode.TreeView is RepositoryTreeView) { RepositoryTreeView rtv = (RepositoryTreeView)this.TreeNode.TreeView; rtv.Reload(uri); } } else if (ListViewItem != null) { RepositoryExplorerControl rec = GetRepositoryExplorerControl(); if (rec != null) { // This always reloads the parent and its children (not only when requested) Uri uri = new Uri(SvnTools.GetNormalizedUri(this.Uri), "./"); // parent uri rec.Reload(uri); } } }
public void SetUris(IEnumerable <SvnOrigin> uris) { deleteList.ClearSelected(); SortedDictionary <Uri, SvnOrigin> d = new SortedDictionary <Uri, SvnOrigin>(UriComparer.Default); foreach (SvnOrigin o in uris) { SvnUriTarget ut = o.Target as SvnUriTarget; if (ut != null) { d[ut.Uri] = o; } else { d[o.Uri] = o; } } _uris = new Uri[d.Count]; List <Uri> newUris = new List <Uri>(); foreach (SvnOrigin o in d.Values) { deleteList.Items.Add(o.Uri); newUris.Add(SvnTools.GetNormalizedUri(o.Uri)); } _uris = newUris.ToArray(); }
private RepositoryTreeNode EnsureNodeUri(Uri uri, Uri repositoryUri, SvnNodeKind kind) { Uri nUri = SvnTools.GetNormalizedUri(uri); RepositoryTreeNode tn; if (!_nodeMap.TryGetValue(nUri, out tn)) { Uri parentUri = new Uri(uri, kind == SvnNodeKind.Directory ? "../" : "./"); if (parentUri == uri) { return(null); } RepositoryTreeNode parent = EnsureNodeUri(parentUri, repositoryUri, SvnNodeKind.Directory); if (parent != null) { tn = new RepositoryTreeNode(new SvnOrigin(uri, repositoryUri)); string name = uri.ToString(); tn.Text = tn.Origin.Target.FileName; if (IconMapper != null) { if (kind == SvnNodeKind.Directory) { tn.IconIndex = IconMapper.DirectoryIcon; } else { tn.IconIndex = IconMapper.GetIconForExtension(Path.GetExtension(name)); } } _nodeMap.Add(nUri, tn); tn.Preload(kind); SortedAddNode(parent.Nodes, tn); if (!parent.IsExpanded && IsLoading(nUri)) { parent.LoadExpand(); tn.EnsureVisible(); } else if (IsLoading(nUri)) { tn.EnsureVisible(); } } } return(tn); }
/// <summary> /// The ensure the repository root /// </summary> /// <param name="uri">Always the repository root</param> /// <returns></returns> private RepositoryTreeNode EnsureRoot(Uri uri) { EnsureServerOf(uri); Uri serverUri; Uri nUri = SvnTools.GetNormalizedUri(uri); RepositoryTreeNode serverNode = FindServer(uri, out serverUri); if (serverNode == null) { return(null); } if (!serverNode.IsExpanded && IsLoading(nUri)) { serverNode.LoadExpand(); } foreach (RepositoryTreeNode reposRoot in serverNode.Nodes) { if (reposRoot.NormalizedUri == nUri) { return(reposRoot); } } // uri is always the repos root here RepositoryTreeNode rtn = new RepositoryTreeNode(new SvnOrigin(uri, uri)); rtn.Text = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped); if (IconMapper != null) { rtn.IconIndex = IconMapper.GetSpecialIcon(SpecialIcon.Db); } serverNode.Nodes.Add(rtn); if (!_nodeMap.ContainsKey(rtn.NormalizedUri)) { _nodeMap.Add(rtn.NormalizedUri, rtn); } if (!serverNode.IsExpanded || IsLoading(nUri)) { serverNode.LoadExpand(); } return(rtn); }
public void Path_SshUsernameTests() { Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("http://[email protected]/"), "/trunk")).AbsoluteUri, Is.EqualTo("http://[email protected]/trunk")); SvnUriTarget target = new SvnUriTarget(new Uri("http://[email protected]/home/user/repos/"), 1234); Assert.That(target.Revision.RevisionType, Is.EqualTo(SvnRevisionType.Number)); Assert.That(target.Uri.AbsoluteUri, Is.EqualTo("http://[email protected]/home/user/repos")); SvnUriTarget target2 = new SvnUriTarget(new Uri("http://[email protected]:123/home/user/repos/"), SvnRevisionType.Head); Assert.That(target2.Revision, Is.EqualTo(SvnRevision.Head)); Assert.That(target2.Uri.AbsoluteUri, Is.EqualTo("http://[email protected]:123/home/user/repos")); }
private void AddItem(ISvnRepositoryListItem item, Uri repositoryRoot) { if (item == null) { throw new ArgumentNullException("item"); } Uri uri = item.Uri; Uri folderUri; if (item.Entry.NodeKind == SvnNodeKind.File && !ShowFiles) { folderUri = new Uri(uri, "./"); } else { folderUri = uri; } RepositoryTreeNode s = EnsureNodeUri(folderUri, repositoryRoot, ShowFiles ? item.Entry.NodeKind : SvnNodeKind.Directory); if (s != null) { s.AddItem(item); if (s.ExpandAfterLoad) { s.LoadExpand(); Uri nUri = SvnTools.GetNormalizedUri(folderUri); if (IsLoading(nUri)) { TreeNode tn = SelectedNode; while (tn != null && tn != s) { tn = tn.Parent; } if (tn != s) { SelectedNode = s; s.EnsureVisible(); } } } } }
public void BrowseRoot(RepositoryTreeNode parent, Uri uri) { uri = SvnTools.GetNormalizedUri(uri); RepositoryTreeNode itemNode; if (_nodeMap.TryGetValue(uri, out itemNode)) { SelectedNode = itemNode; itemNode.EnsureVisible(); return; } BrowseTo(uri); }
public void BrowseTo(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } Uri nUri; try { nUri = SvnTools.GetNormalizedUri(uri); } catch (UriFormatException) { return; } RepositoryTreeNode tn; if (_nodeMap.TryGetValue(nUri, out tn)) { TreeNode parent = tn; while (parent != null) { if (!parent.IsExpanded) { parent.Expand(); } parent = parent.Parent; } SelectedNode = tn; tn.EnsureVisible(); return; } if (uri.IsAbsoluteUri) { _expandTo = SvnTools.GetNormalizedUri(uri).AbsoluteUri; } else { _expandTo = null; } BrowseItem(uri); }
public void Path_TestNormalizeUri() { Assert.That(SvnTools.GetNormalizedUri(new Uri("https://svn.apache.org/repos/asf/incubator/lucene.net/trunk/C%23/")).AbsoluteUri, Is.EqualTo("https://svn.apache.org/repos/asf/incubator/lucene.net/trunk/C%23")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://localhost/test")).AbsoluteUri, Is.EqualTo("http://localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://localhost/test/")).AbsoluteUri, Is.EqualTo("http://localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://localhost/test//")).AbsoluteUri, Is.EqualTo("http://localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("file:///c:/"), "a b")).AbsoluteUri, Is.EqualTo("file:///C:/a%20b")); Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("file:///c:/"), "a b/")).AbsoluteUri, Is.EqualTo("file:///C:/a%20b")); Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("file:///c:/"), "a%20b")).AbsoluteUri, Is.EqualTo("file:///C:/a%20b")); Assert.That(SvnTools.GetNormalizedUri(new Uri(new Uri("file:///c:/"), "a%20b/")).AbsoluteUri, Is.EqualTo("file:///C:/a%20b")); Assert.That(SvnTools.GetNormalizedUri(new Uri("file:///e:/")).AbsoluteUri, Is.EqualTo("file:///E:/")); Assert.That(SvnTools.GetNormalizedUri(new Uri("file://*****:*****@"\\server\share")).AbsoluteUri, Is.EqualTo("file://server/share")); Assert.That(SvnTools.GetNormalizedUri(new Uri(@"\\server\share\")).AbsoluteUri, Is.EqualTo("file://server/share")); Assert.That(SvnTools.GetNormalizedUri(new Uri(@"\\server\share\a")).AbsoluteUri, Is.EqualTo("file://server/share/a")); Assert.That(SvnTools.GetNormalizedUri(new Uri(@"\\server\share\a\")).AbsoluteUri, Is.EqualTo("file://server/share/a")); Assert.That(SvnTools.GetNormalizedUri(new Uri("HTTP://localhost/test")).AbsoluteUri, Is.EqualTo("http://localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri("hTTp://uSeR@localhost/test/")).AbsoluteUri, Is.EqualTo("http://uSeR@localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri("httP://localhost/test//")).AbsoluteUri, Is.EqualTo("http://localhost/test")); Assert.That(SvnTools.GetNormalizedUri(new Uri(@"\\SERVER\share\a\")).AbsoluteUri, Is.EqualTo("file://server/share/a")); Assert.That(SvnTools.GetNormalizedUri(new Uri(@"\\SERVER\Share\a\")).AbsoluteUri, Is.EqualTo("file://server/Share/a")); Assert.That(SvnTools.GetNormalizedUri(new Uri("file://localhost/C:/Repositories/testrepo/TraceStart")).AbsoluteUri, Is.EqualTo("file://localhost/C:/Repositories/testrepo/TraceStart")); Assert.That(SvnUriTarget.FromUri(new Uri("file://localhost/C:/Repositories/testrepo/TraceStart")).Uri.AbsoluteUri, Is.EqualTo("file://localhost/C:/Repositories/testrepo/TraceStart")); }
private void MaybeExpand(Uri uri) { uri = SvnTools.GetNormalizedUri(uri); RepositoryTreeNode tn; if (_nodeMap.TryGetValue(uri, out tn)) { if (tn.ExpandAfterLoad || IsLoading(uri)) { tn.LoadExpand(); } if (SelectedNode == tn) { OnSelectedNodeRefresh(EventArgs.Empty); } } }
public void Path_TestUriNormalization() { Assert.That(SvnTools.GetNormalizedUri(new Uri("\\\\server\\repos")).AbsoluteUri, Is.EqualTo("file://server/repos")); Assert.That(SvnTools.GetNormalizedUri(new Uri("\\\\server\\repos\\file")).AbsoluteUri, Is.EqualTo("file://server/repos/file")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://host/")).AbsoluteUri, Is.EqualTo("http://host/")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://host/svn/")).AbsoluteUri, Is.EqualTo("http://host/svn")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://user@host/")).AbsoluteUri, Is.EqualTo("http://user@host/")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://user@host/svn/")).AbsoluteUri, Is.EqualTo("http://user@host/svn")); Assert.That(SvnTools.GetNormalizedUri(new Uri("file://server//repos//qqq")).AbsoluteUri, Is.EqualTo("file://server/repos/qqq")); Assert.That(SvnTools.GetNormalizedUri(new Uri("http://sErVeR/")).AbsoluteUri, Is.EqualTo("http://server/")); Assert.That((new Uri("http://sErVeR/")).AbsoluteUri, Is.EqualTo("http://server/")); Assert.That((new Uri("http://sErVeR/")).ToString(), Is.EqualTo("http://server/")); // TODO: Maybe ensure //Assert.That(SvnTools.GetNormalizedUri(new Uri("f:\\repos")).AbsoluteUri, Is.EqualTo("file:///F:/repos")); }
public void Reload(Uri uri) { if (uri == null) { // This might be useful when repository roots are persisted across sessions // and might be used to trigger the re-read of the persisted repositories } else { Uri nUri = SvnTools.GetNormalizedUri(uri); RepositoryTreeNode tn = null; if (_nodeMap.TryGetValue(nUri, out tn)) { CleanupCacheFor(uri, false); tn.Nodes.Clear(); this.BrowseItem(uri); } } }
private void CleanupCacheFor(Uri uri, bool includeBase) { if (uri == null) { throw new InvalidOperationException(); } Uri nUri = SvnTools.GetNormalizedUri(uri); string start = nUri.AbsoluteUri; if (start[start.Length - 1] != '/') { start += '/'; } List <Uri> removeUris = new List <Uri>(); foreach (Uri cachedUri in _nodeMap.Keys) { if (cachedUri.MakeRelativeUri(nUri).IsAbsoluteUri) { continue; } if (cachedUri.AbsoluteUri.StartsWith(start)) { removeUris.Add(cachedUri); } else if (includeBase && cachedUri == nUri) { removeUris.Add(cachedUri); } } foreach (Uri removeUri in removeUris) { _nodeMap.Remove(removeUri); } }
public override void OnExecute(CommandEventArgs e) { Uri target = null; Uri root = null; bool up = false; List <SvnUriTarget> copyFrom = new List <SvnUriTarget>(); foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>()) { SvnUriTarget utt = item.Origin.Target as SvnUriTarget; if (utt == null) { utt = new SvnUriTarget(item.Origin.Uri, item.Origin.Target.Revision); } copyFrom.Add(utt); if (root == null) { root = item.Origin.RepositoryRoot; } if (target == null) { target = item.Origin.Uri; } else { Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri); Uri r = item.Origin.Uri.MakeRelativeUri(target); if (r.IsAbsoluteUri) { target = null; break; } string rs = r.ToString(); if (r.ToString().StartsWith("/", StringComparison.Ordinal)) { target = new Uri(target, "/"); break; } if (!up && r.ToString().StartsWith("../")) { target = new Uri(target, "../"); up = true; } } } bool isMove = e.Command == AnkhCommand.ReposMoveTo; Uri toUri; string logMessage; using (CopyToDialog dlg = new CopyToDialog()) { dlg.RootUri = root; dlg.SelectedUri = target; dlg.Text = isMove ? "Move to Url" : "Copy to Url"; if (dlg.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK) { return; } toUri = dlg.SelectedUri; logMessage = dlg.LogMessage; } // TODO: BH: Make sure the 2 attempts actually make sense e.GetService <IProgressRunner>().RunModal(isMove ? CommandStrings.Moving : CommandStrings.Copying, delegate(object snd, ProgressWorkerArgs a) { if (isMove) { List <Uri> uris = new List <Uri>(); foreach (SvnUriTarget ut in copyFrom) { uris.Add(ut.Uri); } SvnMoveArgs ma = new SvnMoveArgs(); ma.LogMessage = logMessage; ma.CreateParents = true; try { // First try with the full new name a.Client.RemoteMove(uris, toUri, ma); } catch (SvnFileSystemException fs) { if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS) { throw; } // If exists retry below this directory with the existing name ma.AlwaysMoveAsChild = true; a.Client.RemoteMove(uris, toUri, ma); } } else { SvnCopyArgs ca = new SvnCopyArgs(); ca.LogMessage = logMessage; ca.CreateParents = true; try { // First try with the full new name a.Client.RemoteCopy(copyFrom, toUri, ca); } catch (SvnFileSystemException fs) { if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS) { throw; } // If exists retry below this directory with the existing name ca.AlwaysCopyAsChild = true; a.Client.RemoteCopy(copyFrom, toUri, ca); } } }); // TODO: Send some notification to the repository explorer on this change? }
internal void BrowseItem(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } if (DesignMode) { return; } Uri nUri = SvnTools.GetNormalizedUri(uri); if (_running.Contains(nUri)) { return; } _running.Add(nUri); if (_running.Count == 1) { OnRetrievingChanged(EventArgs.Empty); } AnkhAction d = delegate() { bool ok = false; try { SvnListArgs la = new SvnListArgs(); la.RetrieveEntries = RetrieveItems; la.RetrieveLocks = RetrieveLocks; la.Depth = SvnDepth.Children; la.ThrowOnError = false; Collection <SvnListEventArgs> items; using (SvnClient client = Context.GetService <ISvnClientPool>().GetClient()) { client.GetList(uri, la, out items); } AnkhAction addItems = (AnkhAction) delegate() { if (items != null && items.Count > 0) { bool first = true; foreach (SvnListEventArgs a in items) { if (first) { if (a.RepositoryRoot != null) { EnsureRoot(a.RepositoryRoot); } } AddItem(a, a.RepositoryRoot); first = false; } MaybeExpand(uri); } _running.Remove(nUri); if (_running.Count == 0) { OnRetrievingChanged(EventArgs.Empty); } }; if (IsHandleCreated) { BeginInvoke(addItems); } else { addItems(); } ok = true; } finally { if (!ok) { BeginInvoke((AnkhAction) delegate() { _running.Remove(nUri); if (_running.Count == 0) { OnRetrievingChanged(EventArgs.Empty); } }); } } }; d.BeginInvoke(null, null); }
public static bool TryGuessLayout(IAnkhServiceProvider context, Uri uri, out RepositoryLayoutInfo info) { if (context == null) { throw new ArgumentNullException("context"); } else if (uri == null) { throw new ArgumentNullException("uri"); } info = null; uri = SvnTools.GetNormalizedUri(uri); GC.KeepAlive(context); // Allow future external hints string path; if (uri.IsUnc) { string p = uri.GetComponents(UriComponents.Host | UriComponents.Path, UriFormat.SafeUnescaped); if (string.IsNullOrEmpty(p)) { return(false); } path = "//" + p; } else { path = uri.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped); } if (string.IsNullOrEmpty(path)) { return(false); } if (path[0] != '/' && !uri.IsFile) // Don't do this for files, because it will cause duplicate drive roots { path = '/' + path; } if (path[path.Length - 1] != '/') { path += '/'; } if (string.IsNullOrEmpty(path) || path.Length == 1) { return(false); } string r = path; while (r.Length > 0 && !r.EndsWith("/trunk/", StringComparison.OrdinalIgnoreCase)) { int n = r.LastIndexOf('/', r.Length - 1); if (n >= 0) { int lastCharIndex = r.Length - 1; // if '/' is the last character, strip and continue // otherwise include '/' to give "/trunk/" check a chance r = r.Substring(0, (n == lastCharIndex) ? n : (n + 1)); } else { r = ""; } } if (!string.IsNullOrEmpty(r)) { info = new RepositoryLayoutInfo(); info.WorkingRoot = new Uri(uri, r); info.WholeProjectRoot = new Uri(uri, r.Substring(0, r.Length - 6)); info.BranchesRoot = new Uri(info.WholeProjectRoot, "branches/"); info.SelectedBranch = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot); return(true); } if (TryFindBranch(uri, path, "branches", true, out info)) { return(true); } else if (TryFindBranch(uri, path, "tags", false, out info)) { return(true); } else if (TryFindBranch(uri, path, "releases", false, out info)) { return(true); } info = new RepositoryLayoutInfo(); info.WorkingRoot = new Uri(uri, "."); info.WholeProjectRoot = new Uri(info.WorkingRoot, "../"); info.BranchesRoot = new Uri(info.WholeProjectRoot, "branches/"); info.TagsRoot = new Uri(info.WholeProjectRoot, "tags/"); info.SelectedBranch = info.WholeProjectRoot.MakeRelativeUri(info.WorkingRoot); return(true); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="ei"></param> /// <param name="hostUrl">url of directory where the svn external is defined</param> /// <returns></returns> public static bool GetFullReferenceUrl(SvnClient client, SvnExternalItem ei, string hostUrl, out string result) { var url = ei.Reference; result = url; if (url.StartsWith("^/../")) { var relativeUrl = url.Substring(1); // get repo root SvnInfoEventArgs info; if (!client.GetInfo(new Uri(hostUrl), out info)) { return(false); } // normalize <server>/repo1/../repo2/xxx to <server>/repo2/xxx string combinedUrl = CombineUrls(info.RepositoryRoot.AbsoluteUri, relativeUrl); var combinedNormalizedUri = SvnTools.GetNormalizedUri(new Uri(combinedUrl)); result = combinedNormalizedUri.AbsoluteUri; return(true); } else if (url.StartsWith("^/")) { var relativeUrl = url.Substring(1); // get repo root SvnInfoEventArgs info; if (!client.GetInfo(new Uri(hostUrl), out info)) { return(false); } result = CombineUrls(info.RepositoryRoot.AbsoluteUri, relativeUrl); return(true); } else if (url.StartsWith("//")) { // FIXME: add support Logger.Error($"Unsupported relative external '{url}'"); throw new Exception($"Unsupported relative external '{url}'"); //return false; } else if (url.StartsWith("..")) { // FIXME: add support Logger.Error($"Unsupported relative external '{url}'"); throw new Exception($"Unsupported relative external '{url}'"); //return false; } else if (url.StartsWith("/")) { // FIXME: add support Logger.Error($"Unsupported relative external '{url}'"); throw new Exception($"Unsupported relative external '{url}'"); //return false; } else { // leave the result same as url return(true); } //return false; }