public static bool GetExternalType(SvnExternalItem ei, out EPinType oldType) { if (ei.Revision.RevisionType == SvnRevisionType.None) { oldType = EPinType.Head; return(true); } if (ei.Revision.RevisionType == SvnRevisionType.Number) { oldType = EPinType.Peg; return(true); } if (ei.Reference.Contains("/branches/")) { oldType = EPinType.Branch; return(true); } if (ei.Reference.Contains("/tags/")) { oldType = EPinType.Tag; return(true); } oldType = EPinType.Invalid; Logger.Error($"Pin type of external ref '{ei}' can't be determmined"); return(false); }
private void RowRefresh(DataGridViewRow r, SvnExternalItem ii) { r.SetValues( ii.Reference, null, ii.Revision.ToString(), null, ii.Target); }
public void ParseFlat() { SvnExternalItem item; Assert.That(SvnExternalItem.TryParse("a b", out item), Is.True); Assert.That(item.Target, Is.EqualTo("b")); Assert.That(item.Reference, Is.EqualTo("a")); Assert.That(SvnExternalItem.TryParse(item.ToString(), out item), Is.True); Assert.That(item.Target, Is.EqualTo("b")); Assert.That(item.Reference, Is.EqualTo("a")); }
static bool MakePeg(SvnClient client, ref SvnExternalItem ei, string hostUrl) { Exter.EPinType oldType; if (!Exter.GetExternalType(ei, out oldType)) { return(false); } switch (oldType) { case Exter.EPinType.Head: case Exter.EPinType.Branch: { // resolve relative url references string fullRefUrl; if (!Exter.GetFullReferenceUrl(client, ei, hostUrl, out fullRefUrl)) { return(false); } // find the revision of the external SvnInfoEventArgs info; if (!client.GetInfo(new SvnUriTarget(fullRefUrl, SvnRevision.Head), out info)) { return(false); } // change to peg revision ei = new SvnExternalItem(ei.Target, ei.Reference, info.Revision); return(true); } case Exter.EPinType.Peg: { // no change needed, already a peg external return(true); } case Exter.EPinType.Tag: { // no change needed, tag is considered unchangeable, keep it as it is return(true); } default: { // unknown Pin type return(false); } } //return true; }
public void ParseFail() { SvnExternalItem[] items; Assert.That(SvnExternalItem.TryParse("", out items), Is.True); Assert.That(items, Is.Not.Null); Assert.That(items.Length, Is.EqualTo(0)); Assert.That(SvnExternalItem.TryParse("q", out items), Is.False); Assert.That(SvnExternalItem.TryParse("q r", out items), Is.True); // But junk Assert.That(SvnExternalItem.TryParse("q r q", out items), Is.False); Assert.That(SvnExternalItem.TryParse("-r q r", out items), Is.False); SvnExternalItem item; Assert.That(SvnExternalItem.TryParse("-r 12 q r", out item), Is.True); Assert.That(item.Reference, Is.EqualTo("q")); Assert.That(item.Target, Is.EqualTo("r")); Assert.That(item.OperationalRevision, Is.EqualTo(SvnRevision.None)); Assert.That(item.Revision, Is.EqualTo((SvnRevision)12L)); Assert.That(SvnExternalItem.TryParse("q -r 12 r", out item), Is.True); Assert.That(item.Reference, Is.EqualTo("r")); Assert.That(item.Target, Is.EqualTo("q")); Assert.That(item.OperationalRevision, Is.EqualTo((SvnRevision)12)); Assert.That(item.Revision, Is.EqualTo((SvnRevision)12L)); Assert.That(SvnExternalItem.TryParse("/q@12 r", out item), Is.True); Assert.That(item.Reference, Is.EqualTo("/q")); Assert.That(item.Target, Is.EqualTo("r")); Assert.That(item.OperationalRevision, Is.EqualTo((SvnRevision)12)); Assert.That(item.Revision, Is.EqualTo((SvnRevision)12L)); Assert.That(SvnExternalItem.TryParse(item.ToString(), out items)); Assert.That(item.Equals(items[0])); Assert.That(SvnExternalItem.TryParse("-r 1 http://host@1 'tg q'", out item)); Assert.That(item.Reference, Is.EqualTo("http://host")); Assert.That(item.Target, Is.EqualTo("tg q")); Assert.That(item.Revision, Is.EqualTo((SvnRevision)1)); Assert.That(item.OperationalRevision, Is.EqualTo((SvnRevision)1)); Assert.That(item.ToString(false), Is.EqualTo("http://host@1 \"tg q\"")); Assert.That(item.ToString(true), Is.EqualTo("\"tg q\" -r 1 http://host")); Assert.That(SvnExternalItem.TryParse("q http://q", out items), Is.True); Assert.That(SvnExternalItem.TryParse("http://q q", out items), Is.True); Assert.That(SvnExternalItem.TryParse("q http://q\r\nr http://r", out items), Is.True); Assert.That(items.Length, Is.EqualTo(2)); Assert.That(SvnExternalItem.TryParse("http://q q\nr http://r", out items), Is.True); Assert.That(items.Length, Is.EqualTo(2)); }
//static void Test1() //{ // var cwd = System.IO.Directory.GetCurrentDirectory(); // using (Lua lua = new Lua()) // { // lua.State.Encoding = Encoding.UTF8; // //lua.DoString("Externals={{Path='Bin', Name='All', URL='myUrl/blabla' }} res = 'Файл'"); // lua.DoFile("Config/Templates/IG/externals.lua"); // //string res = (string)lua["res"]; // var exts = lua["Externals"] as LuaTable; // foreach( LuaTable ext in exts.Values ) // { // var path = (string)ext["Path"]; // var name = (string)ext["Name"]; // var unknown = (string)ext["unknown"]; // } // //int i = 1; // } //} static void Test2() { var client = new SvnClient(); string val; var result = client.GetProperty(new SvnUriTarget("file:///D:/Work/svn/BIST/repo/releases/IG/Head/Config"), "svn:externals", out val); if (!result) { return; } SvnExternalItem[] items; result = SvnExternalItem.TryParse(val, out items); }
public static bool LinkModule(SvnClient client, string installUrl, string moduleName, string releaseUrl) { // check if a link for given module exists at all SvnExternalItem[] extItems; if (!Exter.ReadExternals(client, installUrl, out extItems)) { return(false); } // if not, do not do anything // (adding a new module to an installation is too responsible operation to be done automatically) int foundAt = -1; for (int i = 0; i < extItems.Length; i++) { if (extItems[i].Target == moduleName) { foundAt = i; break; } } if (foundAt < 0) // module not linked yet { return(true); } SvnInfoEventArgs info; if (!client.GetInfo(new SvnUriTarget(installUrl), out info)) { return(false); } // replace the link with a new one var ei = extItems[foundAt]; string relativizedUrl; Exter.TryMakeRelativeReference(client, releaseUrl, info.RepositoryRoot.AbsoluteUri, out relativizedUrl); var newEI = new SvnExternalItem(ei.Target, relativizedUrl); extItems[foundAt] = newEI; if (!Exter.WriteExternals(client, installUrl, extItems, info.Revision)) { return(false); } return(true); }
public void ParseReturn() { SvnExternalItem item; string txt = new SvnExternalItem("a b c", "http://host/path with space/").ToString(); Assert.That(SvnExternalItem.TryParse(txt, out item)); Assert.That(item.Target, Is.EqualTo("a b c")); Assert.That(item.Reference, Is.EqualTo("http://host/path with space/")); txt = new SvnExternalItem("'a b c\"", "http://host/path with \"\'/").ToString(); Assert.That(SvnExternalItem.TryParse(txt, out item)); Assert.That(item.Target, Is.EqualTo("'a b c\"")); Assert.That(item.Reference, Is.EqualTo("http://host/path with \"\'/")); }
public void ParseSome() { SvnExternalItem[] items; Assert.That(SvnExternalItem.TryParse("dir http://sharpsvn.net/qqn", out items)); Assert.That(items, Is.Not.Null); Assert.That(items.Length, Is.EqualTo(1)); Assert.That(items[0].Target, Is.EqualTo("dir")); Assert.That(items[0].Reference, Is.EqualTo("http://sharpsvn.net/qqn")); Assert.That(items[0].Revision, Is.EqualTo(SvnRevision.None)); Assert.That(items[0].OperationalRevision, Is.EqualTo(SvnRevision.None)); Assert.That(items[0].ToString(), Is.EqualTo("dir http://sharpsvn.net/qqn")); Assert.That(items[0].ToString(false), Is.EqualTo("http://sharpsvn.net/qqn dir")); }
public void ParseHEAD() { SvnExternalItem item; Assert.That(SvnExternalItem.TryParse("-r 1 http://sharpsvn.net/qqn@124 dir", out item)); Assert.That(item, Is.Not.Null); Assert.That(item.Target, Is.EqualTo("dir")); Assert.That(item.Reference, Is.EqualTo("http://sharpsvn.net/qqn")); // Blanks returns head -> We create blanks Assert.That(item.Revision.Revision, Is.EqualTo(1)); Assert.That(item.OperationalRevision.Revision, Is.EqualTo(124)); Assert.That(item.ToString(), Is.EqualTo("-r 1 http://sharpsvn.net/qqn@124 dir")); Assert.That(item.ToString(false), Is.EqualTo("-r 1 http://sharpsvn.net/qqn@124 dir")); }
static bool ModifyExternal(SvnClient client, ref SvnExternalItem ei, Exter.EPinType newType, string hostUrl, string releaseName = null) { switch (newType) { case Exter.EPinType.Head: { if (!MakeHead(client, ref ei, hostUrl)) { return(false); } break; } case Exter.EPinType.Peg: { if (!MakePeg(client, ref ei, hostUrl)) { return(false); } break; } case Exter.EPinType.Branch: { if (!MakeBranch(client, ref ei, hostUrl, releaseName)) { return(false); } break; } case Exter.EPinType.Tag: { if (!MakeTag(client, ref ei, hostUrl, releaseName)) { return(false); } break; } } return(true); }
private void Rebind(SvnExternalItem[] items) { externalGrid.Rows.Clear(); foreach (SvnExternalItem i in items) { int n = externalGrid.Rows.Add(); externalGrid.Rows[n].Tag = i; } foreach (DataGridViewRow r in externalGrid.Rows) { SvnExternalItem ii = r.Tag as SvnExternalItem; if (ii != null) { RowRefresh(r, ii); } } }
static void Test7() { var client = new SvnClient(); string val; var hostUrl = "file:///D:/Work/svn/BIST/repo/releases/IG/Head"; var result = client.GetProperty(new SvnUriTarget(hostUrl), "svn:externals", out val); if (!result) { return; } SvnExternalItem[] items; result = SvnExternalItem.TryParse(val, out items); //var uriTarget = new SvnUriTarget( url ); //var uri = new Uri(url); //uri. //ReleaseMaker.GetFullReferenceUrl(client, items[0], hostUrl); }
public static bool ReadExternals(SvnClient client, string externalsHostUrl, out SvnExternalItem[] extItems) { //SvnExternalItem[] extItems; extItems = new SvnExternalItem[0]; { string externalsPropVal; if (!client.GetProperty(new SvnUriTarget(externalsHostUrl), "svn:externals", out externalsPropVal)) { return(false); } if (!String.IsNullOrEmpty(externalsPropVal)) { if (!SvnExternalItem.TryParse(externalsPropVal, out extItems)) { return(false); } } } return(true); }
private static bool TryCreateItemFromRow(DataGridViewRow r, out SvnExternalItem item) { if (r == null) { throw new ArgumentNullException("r"); } string url = r.Cells[0].Value as string; string target = r.Cells[4].Value as string; string rev = r.Cells[2].Value as string; SvnRevision rr = string.IsNullOrEmpty(rev) ? SvnRevision.None : long.Parse(rev); if (url.Contains("://")) { Uri uri; if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) { item = null; return(false); } url = uri.AbsoluteUri; } SvnExternalItem ei = new SvnExternalItem(target, url, rr, rr); SvnExternalItem p; if (!SvnExternalItem.TryParse(ei.ToString(), out p) || !p.Equals(ei)) { item = null; return(false); } item = ei; 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; }
static bool MakeTag(SvnClient client, ref SvnExternalItem ei, string hostUrl, string releaseName) { return(MakeTagBranch(client, ref ei, hostUrl, releaseName, "tags")); }
private static void CheckOutAndOpenProject(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri) { IProgressRunner runner = e.GetService <IProgressRunner>(); runner.RunModal(CommandStrings.CheckingOutSolution, delegate(object sender, ProgressWorkerArgs ee) { PerformCheckout(ee, checkoutLocation, revision, localDir); }); Uri file = projectTop.MakeRelativeUri(projectUri); string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString()))); AddProject(e, projectFile); using (ProjectAddInfoDialog pai = new ProjectAddInfoDialog()) { IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); SvnItem rootItem; pai.EnableSlnConnection = false; if (ss == null || cache == null || string.IsNullOrEmpty(ss.ProjectRoot) || !SvnItem.IsBelowRoot(localDir, ss.ProjectRoot) || null == (rootItem = cache[localDir])) { pai.EnableExternal = false; pai.EnableCopy = false; } else { SvnItem dir = rootItem.Parent; if (ss.ProjectRootSvnItem != null && ss.ProjectRootSvnItem.IsVersioned) { HybridCollection <string> dirs = new HybridCollection <string>(); SvnItem exDir = dir; while (exDir != null && exDir.IsBelowPath(ss.ProjectRoot)) { if (exDir.IsVersioned && exDir.WorkingCopy == ss.ProjectRootSvnItem.WorkingCopy) { dirs.Add(exDir.FullPath); } exDir = exDir.Parent; } pai.SetExternalDirs(dirs); pai.EnableExternal = true; } else { pai.EnableExternal = false; } if (rootItem.WorkingCopy != null && dir.WorkingCopy != null) { pai.EnableCopy = (rootItem.WorkingCopy.RepositoryRoot == dir.WorkingCopy.RepositoryRoot) && (rootItem.WorkingCopy.RepositoryId == dir.WorkingCopy.RepositoryId); } else { pai.EnableCopy = false; } } if (pai.ShowDialog(e.Context) == DialogResult.OK) { switch (pai.SelectedMode) { case ProjectAddMode.External: if (pai.ExternalLocation != null) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient()) { string externals; if (!cl.TryGetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, out externals)) { externals = ""; } SvnExternalItem sei; if (pai.ExternalLocked) { sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri, revision, revision); } else { sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri); } externals = sei.ToString(true) + Environment.NewLine + externals; cl.SetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, externals); } } break; case ProjectAddMode.Copy: using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) { string tmpDir = localDir + "-Src-copyTmp"; Directory.CreateDirectory(tmpDir); Directory.Move(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), Path.Combine(tmpDir, SvnClient.AdministrativeDirectoryName)); SvnCopyArgs ma = new SvnCopyArgs(); ma.MetaDataOnly = true; cl.Copy(tmpDir, localDir, ma); SvnItem.DeleteDirectory(tmpDir, true); cache.MarkDirtyRecursive(localDir); } break; case ProjectAddMode.Unversioned: cache.MarkDirtyRecursive(localDir); SvnItem.DeleteDirectory(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), true); e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(projectFile); // And everything else in the project break; } } } }
static bool MakeHead(SvnClient client, ref SvnExternalItem ei, string hostUrl) { Exter.EPinType oldType; if (!Exter.GetExternalType(ei, out oldType)) { return(false); } switch (oldType) { case Exter.EPinType.Head: { // no change needed, already a head external return(true); } case Exter.EPinType.Peg: { // remove peg ei = new SvnExternalItem(ei.Target, ei.Reference); return(true); } case Exter.EPinType.Branch: { // replace the /branches/... part with /trunk var orig = ei.Reference; int tagPos = orig.IndexOf("/branches/"); if (tagPos >= 0) { var trunkized = orig.Substring(0, tagPos) + "/trunk"; ei = new SvnExternalItem(ei.Target, trunkized); return(true); } else { Logger.Error($"external '{orig}' is not a branch!"); return(false); } } case Exter.EPinType.Tag: { // replace the /tags/... part with /trunk var orig = ei.Reference; int tagPos = orig.IndexOf("/tags/"); if (tagPos >= 0) { var trunkized = orig.Substring(0, tagPos) + "/trunk"; ei = new SvnExternalItem(ei.Target, trunkized); return(true); } else { Logger.Error($"external '{orig}' is not a tag!"); return(false); } } default: { // unknown Pin type return(false); } } //return true; }
static bool MakeTagBranch(SvnClient client, ref SvnExternalItem ei, string hostUrl, string releaseName, string branchTagType) { Exter.EPinType oldType; if (!Exter.GetExternalType(ei, out oldType)) { return(false); } string fullRefUrl; if (!Exter.GetFullReferenceUrl(client, ei, hostUrl, out fullRefUrl)) { return(false); } var origBaseUrl = Exter.StripStdSvnLayoutFromUrl(ei.Reference); var origTaggizedUrl = $"{origBaseUrl}/{branchTagType}/{releaseName}"; var fullBaseUrl = Exter.StripStdSvnLayoutFromUrl(fullRefUrl); var fullTaggizedUrl = $"{fullBaseUrl}/{branchTagType}/{releaseName}"; switch (oldType) { case Exter.EPinType.Head: case Exter.EPinType.Branch: { // create tag by svncopying from the head try { SvnCommitResult copyResult; var args = new SvnCopyArgs(); args.LogMessage = ""; args.CreateParents = true; if (!client.RemoteCopy(new SvnUriTarget(fullRefUrl, SvnRevision.Head), new Uri(fullTaggizedUrl), args, out copyResult)) { return(false); } } catch (SvnException ex) { Logger.Warn(ex, $"Failed creating tag/branch '{fullTaggizedUrl}'"); } ei = new SvnExternalItem(ei.Target, origTaggizedUrl); return(true); } case Exter.EPinType.Peg: { // create tag by svncopying from given peg revision try { SvnCommitResult copyResult; var args = new SvnCopyArgs(); args.LogMessage = ""; args.CreateParents = true; if (!client.RemoteCopy(new SvnUriTarget(fullRefUrl, ei.Revision), new Uri(fullTaggizedUrl), args, out copyResult)) { return(false); } } catch (SvnException ex) { Logger.Warn(ex, $"Failed creating tag/branch '{fullTaggizedUrl}'"); } ei = new SvnExternalItem(ei.Target, origTaggizedUrl); return(true); } case Exter.EPinType.Tag: { // leave the tag as is return(false); } default: { // unknown Pin type return(false); } } //return false; }
private void Rebind(SvnExternalItem[] items) { externalGrid.Rows.Clear(); foreach (SvnExternalItem i in items) { int n = externalGrid.Rows.Add(); externalGrid.Rows[n].Tag = i; } foreach (DataGridViewRow r in externalGrid.Rows) { SvnExternalItem ii = r.Tag as SvnExternalItem; if (ii != null) RowRefresh(r, ii); } }
private static bool TryCreateItemFromRow(DataGridViewRow r, out SvnExternalItem item) { if (r == null) throw new ArgumentNullException("r"); string url = r.Cells[0].Value as string; string target = r.Cells[4].Value as string; string rev = r.Cells[2].Value as string; SvnRevision rr = string.IsNullOrEmpty(rev) ? SvnRevision.None : long.Parse(rev); if (url.Contains("://")) { Uri uri; if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) { item = null; return false; } url = uri.AbsoluteUri; } SvnExternalItem ei = new SvnExternalItem(target, url, rr, rr); SvnExternalItem p; if (!SvnExternalItem.TryParse(ei.ToString(), out p) || !p.Equals(ei)) { item = null; return false; } item = ei; return true; }