public void ParseBlame(string fileName, int lineNumber) { CaseSensFileName = GetProperFilePathCapitalization(fileName); Revision = 0; Author = "unknown"; try { using (var client = new SvnClient()) { client.Authentication.DefaultCredentials = new NetworkCredential("vivabuild", "#%tsargWV45!@^@gvtRSW"); SvnTarget target = SvnPathTarget.FromString(CaseSensFileName); Collection <SvnBlameEventArgs> list; client.GetBlame(target, out list); int idx = lineNumber - 1; if (0 <= idx && idx < list.Count) { Revision = list[idx].Revision; Author = list[idx].Author; } } } catch (Exception) { ; } AddAuthor(Author); }
/// <summary> /// 更新 /// </summary> /// <param name="fileName">文件夹名称</param> /// <returns></returns> public JsonResult UpdateSvn(string fileName, string user, string pwd, string type) { string result = string.Empty; using (SvnClient client = new SvnClient()) { try { GetPermission(client, user, pwd); SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget("https://" + (type == "local" ? localSVN : onlineSVN) + fileName); SvnPathTarget local = new SvnPathTarget(localPath + "\\" + fileName); client.GetInfo(repos, out serverInfo); client.Update(localPath + "\\" + fileName); client.GetInfo(local, out clientInfo); if (serverInfo.Revision > 0 && clientInfo.Revision > 0) { result = serverInfo.Revision.ToString() + "-" + clientInfo.Revision.ToString(); } return(Json(new { result = true })); } catch (Exception ex) { return(Json(new { result = false, msg = ex.Message.ToString() })); } } }
public void DontCanonicalizeToDotSlash() { SvnPathTarget path = new SvnPathTarget(".\\bladiebla.txt"); Assert.That(path.TargetName, Is.EqualTo("bladiebla.txt")); Assert.That(Path.GetFullPath("c:\\windows\\"), Is.EqualTo("c:\\windows\\")); Assert.That(SvnTools.GetNormalizedFullPath("c:\\windows\\"), Is.EqualTo("C:\\windows")); Assert.That(SvnRevision.Base == SvnRevision.Base); Assert.That(SvnRevision.Base.Equals(SvnRevision.Base)); Assert.That(SvnRevision.Base.Equals(SvnRevisionType.Base)); Assert.That(SvnRevision.Base == SvnRevisionType.Base); Assert.That(SvnRevision.Working == SvnRevision.Working); Assert.That(SvnRevision.Working.Equals(SvnRevision.Working)); Assert.That(SvnRevision.Working.Equals(SvnRevisionType.Working)); Assert.That(SvnRevision.Working == SvnRevisionType.Working); DirectoryInfo dir = new DirectoryInfo("c:\\"); foreach (FileInfo file in dir.GetFiles()) { Assert.That(file.FullName.StartsWith("c:\\")); } dir = new DirectoryInfo("C:\\"); foreach (FileInfo file in dir.GetFiles()) { Assert.That(file.FullName.StartsWith("C:\\")); } }
/// <summary> /// 执行获取本地项目svn信息的操作 /// </summary> /// <param name="projectInfo">传入想要获取信息的projectInfo实例对象</param> /// <returns>获取完信息的projectInfo的实例对象</returns> public ProjectInfo GetLocalInfo(ProjectInfo projectInfo) { using (SvnClient svnClient = new SvnClient()) { try { SvnInfoEventArgs clientInfo; SvnPathTarget local = new SvnPathTarget(projectInfo.WorkDirectory); svnClient.GetInfo(local, out clientInfo); string author = clientInfo.LastChangeAuthor; string revision = clientInfo.LastChangeRevision.ToString(); projectInfo.Author = author; SvnLogArgs getLogMessage = new SvnLogArgs(); Collection <SvnLogEventArgs> col; getLogMessage.Start = int.Parse(revision); getLogMessage.End = int.Parse(revision); bool gotLog = svnClient.GetLog(new Uri(projectInfo.RepositoryPath), getLogMessage, out col); if (gotLog) { projectInfo.LogMessage = col[0].LogMessage; } return(projectInfo); } catch (Exception ex) { return(projectInfo); } } }
public bool Updata(string SvnPathTarget) { ShowState(String.Format("{0} start updata", SvnPathTarget)); //SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; //SvnUpdateResult svnUpdateResult; //System.Collections.ObjectModel.Collection<SvnLogEventArgs> logSvnArgs; //SvnUriTarget repos = new SvnUriTarget(svnUriTarget); SvnPathTarget local = new SvnPathTarget(SvnPathTarget); //client.GetInfo(repos, out serverInfo); //client.GetLog(SvnPathTarget, out logSvnArgs); if (!client.Update(SvnPathTarget)) { ShowState(String.Format("[updata errer] {0}", SvnPathTarget)); return(false); } try { client.GetInfo(local, out clientInfo); } catch (Exception ex) { ShowState(String.Format("[updata errer] {0}", ex.Message)); return(false); } ShowState(string.Format("Svn remote path is :{0} \r\nLocal path is :{1} \r\nLast change revision is :{2} \r\nLast change time is :{3} \r\nLast change author is :{4} \r\n", clientInfo.Uri, clientInfo.Path, clientInfo.LastChangeRevision, clientInfo.LastChangeTime, clientInfo.LastChangeAuthor, clientInfo.Revision)); return(true); }
/// <summary> /// Update to revision performs a reverse merge /// </summary> /// <param name="filePath"></param> /// <param name="startRevision"></param> /// <param name="endRevision"></param> /// <returns></returns> public bool ReverseMerge(string filePath, long startRevision, long endRevision) { var svnRange = new SvnRevisionRange(startRevision, endRevision); var svnPathTarget = new SvnPathTarget(filePath); return(_svnClient.Merge(filePath, svnPathTarget, svnRange)); }
/// <summary> /// Initializes a new instance of the <see cref="SvnOrigin"/> class from a SvnTarget /// </summary> /// <param name="context">The context.</param> /// <param name="target">The target.</param> /// <param name="reposRoot">The repos root or <c>null</c> to retrieve the repository root from target</param> public SvnOrigin(IAnkhServiceProvider context, SvnTarget target, Uri reposRoot) { if (context == null) { throw new ArgumentNullException("context"); } else if (target == null) { throw new ArgumentNullException("target"); } SvnPathTarget pt = target as SvnPathTarget; if (pt != null) { SvnItem item = context.GetService <ISvnStatusCache>()[pt.FullPath]; if (item == null || !item.IsVersioned) { throw new InvalidOperationException("Can only create a SvnOrigin from versioned items"); } _target = target; _uri = item.Status.Uri; _reposRoot = item.WorkingCopy.RepositoryRoot; // BH: Prefer the actual root over the provided return; } SvnUriTarget ut = target as SvnUriTarget; if (ut != null) { _target = ut; _uri = ut.Uri; if (reposRoot != null) { _reposRoot = reposRoot; } else { using (SvnClient client = context.GetService <ISvnClientPool>().GetClient()) { _reposRoot = client.GetRepositoryRoot(ut.Uri); if (_reposRoot == null) { throw new InvalidOperationException("Can't retrieve the repository root of the UriTarget"); } #if DEBUG Debug.Assert(!_reposRoot.MakeRelativeUri(_uri).IsAbsoluteUri); #endif } } return; } throw new InvalidOperationException("Invalid target type"); }
public string GetModifications(string fileName) { if (!filesystem.FileExists(fileName)) { throw new Exception("File does not exists"); } try { var working = new SvnPathTarget(fileName, SvnRevisionType.Working); var @base = new SvnPathTarget(fileName, SvnRevisionType.Base); using (var client = new SvnClient()) using (var ms = new MemoryStream()) { if (!client.Diff(@base, working, ms)) { return(null); } ms.Position = 0; return(Encoding.UTF8.GetString(ms.ToArray())); } } catch (Exception) { return(null); } }
private async Task LoadRevisions(string path) { Revisions = new List <Revision>(); SvnTarget target; if (path.Contains("://")) { target = new SvnUriTarget(path); } else { target = new SvnPathTarget(path); } var svnFileVersionsArgs = new SvnFileVersionsArgs { Start = SvnRevision.Zero, End = SvnRevision.Head }; svnClient.FileVersions(target, svnFileVersionsArgs, (sender, args) => { var revision = new Revision { Author = args.Author, Message = args.LogMessage, RevisionId = args.Revision.ToString(CultureInfo.InvariantCulture), RevisionTime = args.Time, }; using (TextReader reader = new StreamReader(args.GetContentStream())) { revision.Content = reader.ReadToEnd(); } Revisions.Insert(0, revision); // Put them in newest-to-oldest order }); }
private void GetSVNRevision() { using (SvnClient client = new SvnClient()) { SvnInfoEventArgs info; SVNVersion = client.GetInfo(SvnPathTarget.FromString(Path), out info) ? info.Revision : 0; } }
private void SvnUpdate(bool isMandatory, string[] targetDirs) { string workingCopyPath = ConfigurationManager.AppSettings["WorkingCopy.Path"]; string svnUsername = ConfigurationManager.AppSettings["Svn.Username"]; string svnPassword = ConfigurationManager.AppSettings["Svn.Password"]; using (SvnClient client = new SvnClient()) { client.Authentication.ForceCredentials(svnUsername, svnPassword); client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "sharpsvn"), true); SvnPathTarget local = new SvnPathTarget(workingCopyPath); SvnInfoEventArgs clientInfo; client.GetInfo(local, out clientInfo); SvnLockInfo lockInfo = clientInfo.Lock; if (lockInfo != null) { client.CleanUp(workingCopyPath); lockInfo = clientInfo.Lock; if (lockInfo != null) { client.Unlock(workingCopyPath); } } SvnUpdateArgs updateArgs = new SvnUpdateArgs(); updateArgs.AllowObstructions = false; updateArgs.Depth = SvnDepth.Infinity; updateArgs.IgnoreExternals = false; updateArgs.UpdateParents = true; updateArgs.Revision = SvnRevision.Head; updateArgs.Conflict += new EventHandler <SvnConflictEventArgs>(UpdateArgs_Conflict); foreach (string targetDir in targetDirs) { string localPath = workingCopyPath + targetDir; if (isMandatory) { ClearFiles(client, localPath, targetDir, 0); } foreach (string file in Directory.GetFiles(localPath, "*.css")) { File.Delete(file); } client.Update(localPath, updateArgs); } } }
public override Annotation[] GetAnnotations(Repository repo, FilePath file, SvnRevision revStart, SvnRevision revEnd) { if (file == FilePath.Null) { throw new ArgumentNullException(); } var target = new SvnPathTarget(file, SharpSvn.SvnRevision.Base); int numAnnotations = 0; using (var data = new MemoryStream()) { lock (client) client.Write(target, data); using (var reader = new StreamReader(data)) { reader.BaseStream.Seek(0, SeekOrigin.Begin); while (reader.ReadLine() != null) { numAnnotations++; } } } System.Collections.ObjectModel.Collection <SvnBlameEventArgs> list; var args = new SvnBlameArgs { Start = GetRevision(revStart), End = GetRevision(revEnd), }; bool success; lock (client) { success = client.GetBlame(target, args, out list); } if (success) { var annotations = new Annotation [numAnnotations]; foreach (var annotation in list) { if (annotation.LineNumber < annotations.Length) { annotations [(int)annotation.LineNumber] = new Annotation(annotation.Revision.ToString(), annotation.Author, annotation.Time); } } return(annotations); } return(new Annotation[0]); }
public void getInfo() { //var target = new SvnUriTarget(this._uri); var target = new SvnPathTarget(this._src); SvnInfoEventArgs result; this._svncl.GetInfo(target, out result); this._uri = result.Uri; this._reporoot = result.RepositoryRoot; this._repoIdntfr = result.Uri.ToString().Replace( this._reporoot.ToString(), @"" ); }
private SvnTarget GetTarget() { SvnTarget target; SvnRevision revision = RevisionParser.SafeParse(Revision); if (Uri.IsWellFormedUriString(RepositoryPath, UriKind.Absolute)) { target = new SvnUriTarget(RepositoryPath, revision); } else { target = new SvnPathTarget(RepositoryPath, revision); } return target; }
public override string GetUnifiedDiff(FilePath path1, SvnRevision revision1, FilePath path2, SvnRevision revision2, bool recursive) { SvnPathTarget t1 = new SvnPathTarget(path1, GetRevision(revision1)); SvnPathTarget t2 = new SvnPathTarget(path2, GetRevision(revision2)); SvnDiffArgs args = new SvnDiffArgs(); args.Depth = recursive ? SvnDepth.Infinity : SvnDepth.Children; MemoryStream ms = new MemoryStream(); client.Diff(t1, t2, args, ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { return(sr.ReadToEnd()); } }
/// <summary> /// 两个版本之间的不同 /// </summary> /// <param name="from"></param> /// <param name="to"></param> private void deff(string from, string to) { using (SvnClient client = new SvnClient()) { SvnPathTarget path1 = new SvnPathTarget(WORKSPACE, SvnRevision.One); SvnUriTarget path2 = new SvnUriTarget(WORKSPACE, SvnRevision.Head); Collection <SvnDiffSummaryEventArgs> diffEvents = new Collection <SvnDiffSummaryEventArgs>(); client.GetDiffSummary(path1, path2, out diffEvents); foreach (var item in diffEvents) { Console.WriteLine(item.Path + " " + item.NodeKind + " " + item.DiffKind); } } }
/// <summary> /// 获取本地Working Copy中某个文件的信息 /// </summary> public static SvnInfoEventArgs GetLocalFileInfo(string localPath, out SvnException svnException) { SvnInfoEventArgs localFileInfo; SvnPathTarget localPathTarget = new SvnPathTarget(localPath); try { _svnClient.GetInfo(localPathTarget, out localFileInfo); svnException = null; return(localFileInfo); } catch (SvnException exception) { svnException = exception; return(null); } }
public bool CreateNewVersion(SourceControlVersion from, SourceControlVersion to) { NetworkCredential credentials = new NetworkCredential( from.SourceControl.GetStringProperty("Login"), from.SourceControl.GetStringProperty("Password")); using (SvnClient client = new SvnClient()) { client.Authentication.DefaultCredentials = credentials; SvnTarget svnTarget = new SvnPathTarget(this.GetVersionURI(from)); client.RemoteCopy(svnTarget, new Uri(this.GetVersionURI(to))); return(true); } }
/// <summary> /// 检查版本号,如果版本号不符, 则更新 /// </summary> /// <returns></returns> public bool CheckVer() { bool result = true; var repos = new SvnUriTarget(svnurl); var local = new SvnPathTarget(GetAppLoc()); try { notiny = "正在检查服务器版本..."; ShowInfo(); SvnInfoEventArgs serverInfo; bool oks = SC.GetInfo(repos, out serverInfo); notiny = "正在检查本地版本..."; ShowInfo(); SvnInfoEventArgs clientInfo; bool okc = SC.GetInfo(local, out clientInfo); if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令 { { result = (serverInfo.Revision > clientInfo.Revision); } } ShowInfo(string.Format("检查完毕,服务器版本{0}客户端版本{1}", (serverInfo != null ? serverInfo.Revision.ToString() : "(未知)"), (clientInfo != null ? clientInfo.Revision.ToString() : "(未知)") )); } catch(Exception) { ShowInfo("检查文件是出现错误..."); } return result; }
/// <summary> /// Actual method to be executed for the implementing task /// </summary> /// <param name="client">The instance of the SVN client</param> /// <returns></returns> public override bool ExecuteCommand(SvnClient client) { SvnTarget target = new SvnPathTarget(RepositoryPath); SvnInfoArgs args = new SvnInfoArgs(); Collection<SvnInfoEventArgs> infoResult = new Collection<SvnInfoEventArgs>(); bool result = client.GetInfo(target, args, out infoResult); SvnInfoEventArgs info = infoResult[0]; Revision = info.Revision; RepositoryId = info.RepositoryId; NodeKind = info.NodeKind.ToString(); Schedule = info.Schedule.ToString(); LastChangedRevision = info.LastChangeRevision; LastChangedAuthor = info.LastChangeAuthor; LastChangeDate = info.LastChangeTime; return result; }
public string ComposeForPath(string wc) { // find root (where .svn reside) var wcRoot = SvnUtils.FindSvnWC(wc); if (wcRoot == null) throw new ApplicationException("Can't find working copy root for " + wc); using (_client = new SvnClient()) { var wcTarg = new SvnPathTarget(wcRoot); SvnInfoEventArgs info; _client.GetInfo(wcTarg, out info); _cancellationToken.ThrowIfCancellationRequested(); _repoRoot = info.RepositoryRoot; _requestedMergeMessageForBranch = "/" + info.Path.Trim('/') + "/"; SvnTargetPropertyCollection mergeInfoPre; if (!_client.GetProperty(wcTarg, "svn:mergeinfo", new SvnGetPropertyArgs { Revision = SvnRevision.Base }, out mergeInfoPre)) throw new ApplicationException("Error in GetProperty"); string mergeInfoNew; if (!_client.GetProperty(wcTarg, "svn:mergeinfo", out mergeInfoNew)) throw new ApplicationException("Error in GetProperty"); var baseMergeInfo = new Dictionary<string, RevRangeSet>(); if (mergeInfoPre != null && mergeInfoPre.Count != 0) { baseMergeInfo = ParseMegeinfoLines(mergeInfoPre[0].StringValue); } var currentMergeInfo = ParseMegeinfoLines(mergeInfoNew); var newRevs = Subtract(currentMergeInfo, baseMergeInfo); LoadLogEntries(newRevs); return BuildMessage(newRevs); } }
/// <summary> /// Let the user browse for a directory to export from /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void exportFromDirButton_Click(object sender, System.EventArgs e) { using (FolderBrowserDialog browser = new FolderBrowserDialog()) { SvnPathTarget pt = ExportSource as SvnPathTarget; if (pt != null) { browser.SelectedPath = pt.FullPath; } browser.ShowNewFolderButton = false; if (browser.ShowDialog(this) != DialogResult.OK) { return; } this.originBox.Text = browser.SelectedPath; } }
public void Path_NormalizingPathsDot() { Assert.That(SvnTools.IsNormalizedFullPath("C:\\source\\."), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("C:\\source\\.\\"), Is.False); Assert.That(SvnTools.IsNormalizedFullPath("C:\\source\\.\\dump"), Is.False); Assert.That(SvnTools.IsAbsolutePath("C:\\source\\."), Is.False); Assert.That(SvnTools.IsAbsolutePath("C:\\source\\.\\"), Is.False); Assert.That(SvnTools.IsAbsolutePath("C:\\source\\.\\dump"), Is.False); Assert.That(SvnPathTarget.FromString("C:\\source\\.").TargetPath, Is.EqualTo("C:\\source")); Assert.That(SvnPathTarget.FromString("C:\\source\\.\\").TargetPath, Is.EqualTo("C:\\source")); Assert.That(SvnPathTarget.FromString("C:\\source\\.\\dump").TargetPath, Is.EqualTo("C:\\source\\dump")); Assert.That(SvnTools.IsNormalizedFullPath("c:\\source"), Is.False); Assert.That(SvnTools.IsAbsolutePath("c:\\source"), Is.True); Assert.That(SvnPathTarget.FromString("c:\\source\\.").TargetPath, Is.EqualTo("C:\\source")); Assert.That(SvnPathTarget.FromString("c:\\source\\.\\").TargetPath, Is.EqualTo("C:\\source")); Assert.That(SvnPathTarget.FromString("c:\\source\\.\\dump").TargetPath, Is.EqualTo("C:\\source\\dump")); }
public IEnumerable <AnkhRevisionType> GetRevisionTypes(Ankh.Scc.SvnOrigin origin) { if (origin == null) { throw new ArgumentNullException("origin"); } SvnPathTarget pt = origin.Target as SvnPathTarget; bool isPath = (pt != null); yield return(_head); if (isPath) { SvnItem item = GetService <ISvnStatusCache>()[pt.FullPath]; if (item.IsVersioned) { yield return(_working); yield return(_base); } if (item.HasCopyableHistory) { yield return(_committed); yield return(_previous); } else { yield break; } } yield return(new DateRevisionType(this, origin)); yield return(new ExplicitRevisionType(this, origin)); }
public void GetPropertyValues() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); Uri trunk = new Uri(CollabReposUri, "trunk"); string dir = sbox.GetTempDir(); Client.CheckOut(trunk, dir); SvnGetPropertyArgs pa = new SvnGetPropertyArgs(); pa.Depth = SvnDepth.Infinity; SvnTargetPropertyCollection pc; Client.GetProperty(trunk, SvnPropertyNames.SvnEolStyle, pa, out pc); foreach (SvnPropertyValue pv in pc) { SvnUriTarget ut = pv.Target as SvnUriTarget; Assert.That(ut, Is.Not.Null); Uri relative = trunk.MakeRelativeUri(ut.Uri); Assert.That(!relative.ToString().StartsWith("/")); Assert.That(!relative.ToString().StartsWith("../")); } Client.GetProperty(dir, SvnPropertyNames.SvnEolStyle, pa, out pc); dir += "\\"; foreach (SvnPropertyValue pv in pc) { SvnPathTarget pt = pv.Target as SvnPathTarget; Assert.That(pt, Is.Not.Null); Assert.That(pt.TargetPath.StartsWith(dir)); } Assert.That(pc[dir + "index.html"], Is.Not.Null, "Can get wcroot\\index.html?"); }
/// <summary> /// Obtiene una lista con todas las versiones de un archivo. /// </summary> /// <param name="doc"></param> /// <param name="msj"></param> /// <returns></returns> public static Collection <SvnFileVersionEventArgs> ObtenerLstVersionesAnteriores(Documento doc, out string msj) { var colFileVersionEventArgs = new Collection <SvnFileVersionEventArgs>(); msj = ""; try { string rutaEnRepo = (doc.Activo.GetValueOrDefault()) ? doc.Ruta : doc.RutaEliminado; Debug.WriteLine("rutaEnRepo: " + rutaEnRepo); using (var client = new SvnClient()) { var target = new SvnPathTarget(rutaEnRepo); client.GetFileVersions(target, out colFileVersionEventArgs); foreach (var fileVersionEventArgs in colFileVersionEventArgs) { Debug.WriteLine("-------------------------"); Debug.WriteLine("Autor: " + fileVersionEventArgs.Author); Debug.WriteLine("Revision: " + fileVersionEventArgs.Revision); Debug.WriteLine("VersionFile: " + fileVersionEventArgs.VersionFile); } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); msj += "Error al consultar las versiones del archivo: " + ex.Message; if (ex.InnerException != null) { msj += " " + ex.InnerException.Message; } } return(colFileVersionEventArgs); }
/// <summary> /// Checks the SVN. /// </summary> private void checkSVN() { SvnClient __svnClient = new SvnClient(); SvnInfoEventArgs __sieaInfo; bool __getInfo; //MessageBox.Show(__versionFilePath); if (__versionFilePath != "") { try { __getInfo = __svnClient.GetInfo(SvnPathTarget.FromString(GetSourcePath() + __versionFilePath + settingObject.ClassName + ".as"), out __sieaInfo); //MessageBox.Show(__sieaInfo.ToString()); pluginUI.Revision.Text = __sieaInfo.LastChangeRevision.ToString(); __vRevision = (int)__sieaInfo.LastChangeRevision; } catch (SvnException e) { try { //MessageBox.Show(">" + e.Message); __getInfo = __svnClient.GetInfo(SvnPathTarget.FromString(GetSourcePath() + __versionFilePath), out __sieaInfo); pluginUI.Revision.Text = __sieaInfo.LastChangeRevision.ToString(); __vRevision = (int)__sieaInfo.LastChangeRevision; } catch (SvnException ex) { __vRevision = 0; pluginUI.Revision.Text = ""; } } } else { __vRevision = 0; pluginUI.Revision.Text = ""; } }
void UpdateForRevChanges(ILogControl logWindow, CommandUpdateEventArgs e) { SvnOrigin first = EnumTools.GetSingle(logWindow.Origins); if (first == null) { e.Enabled = false; return; } SvnPathTarget pt = first.Target as SvnPathTarget; if (pt != null) { if (e.GetService <ISvnStatusCache>()[pt.FullPath].IsDirectory) { // We can't diff directories at this time e.Enabled = false; return; } } // Note: We can't have a local directory, but we can have a remote one. }
public void OnUpdate(CommandUpdateEventArgs e) { ISvnLogItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnLogItem>()); if (item != null) { ILogControl logWindow = e.Selection.GetActiveControl <ILogControl>(); if (logWindow != null) { SvnOrigin origin = EnumTools.GetSingle(logWindow.Origins); if (origin != null) { SvnPathTarget pt = origin.Target as SvnPathTarget; if (pt != null) { SvnItem svnItem = e.GetService <ISvnStatusCache>()[pt.FullPath]; if (svnItem != null && !svnItem.IsDirectory) { if (null == e.Selection.GetActiveControl <ILogControl>()) { e.Enabled = false; } return; } } } } } e.Enabled = false; }
public static string GetSVNVersion(string filePath) { if (SVNVersion.svnPath == null || SVNVersion.svnPath == "") { return(""); } string ver = ""; if (UseVersionSuffix) { string path = SVNVersion.svnPath + "/" + filePath; SvnInfoEventArgs clientInfo; SvnPathTarget target = new SvnPathTarget(filePath); try { client.GetInfo(target, out clientInfo); ver = "?v=" + clientInfo.LastChangeRevision; } catch { //还没有提交到svn的文件,使用svn最新版本号 ver = "?v=" + latestRevision; } } return(ver); }
public void Path_ParsePaths() { SvnUriTarget ut; SvnPathTarget pt; SvnTarget st; Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/", out ut)); Assert.That(ut.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", out ut)); Assert.That(ut.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(ut.TargetName.Contains("@")); Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", true, out ut)); Assert.That(ut.Revision, Is.EqualTo((SvnRevision)123L)); Assert.That(SvnPathTarget.TryParse("C:\\A", out pt)); Assert.That(pt.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(SvnPathTarget.TryParse("C:\\A@123", out pt)); Assert.That(pt.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(pt.TargetName.Contains("@")); Assert.That(SvnPathTarget.TryParse("C:\\@123", true, out pt)); Assert.That(pt.Revision, Is.EqualTo((SvnRevision)123L)); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", true, out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("C:\\A", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); Assert.That(SvnTarget.TryParse("C:\\A@123", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); Assert.That(SvnTarget.TryParse("C:\\@123", true, out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); }
private static string GetPath(IAnkhServiceProvider context, SvnRevision revision, SvnItem item, string tempDir) { if (revision == SvnRevision.Working) { return item.FullPath; } string strRevision; if (revision.RevisionType == SvnRevisionType.Time) strRevision = revision.Time.ToLocalTime().ToString("yyyyMMdd_hhmmss"); else strRevision = revision.ToString(); string tempFile = Path.GetFileNameWithoutExtension(item.Name) + "." + strRevision + Path.GetExtension(item.Name); tempFile = Path.Combine(tempDir, tempFile); // we need to get it from the repos context.GetService<IProgressRunner>().RunModal("Retrieving file for diffing", delegate(object o, ProgressWorkerArgs ee) { SvnTarget target; switch(revision.RevisionType) { case SvnRevisionType.Head: case SvnRevisionType.Number: case SvnRevisionType.Time: target = new SvnUriTarget(item.Uri); break; default: target = new SvnPathTarget(item.FullPath); break; } SvnWriteArgs args = new SvnWriteArgs(); args.Revision = revision; args.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_UNRELATED_RESOURCES); using (FileStream stream = File.Create(tempFile)) { ee.Client.Write(target, stream, args); } }); return tempFile; }
public Boolean GetAmendCode() { Boolean Result = false; log.WriteFileLog("文件版本:" + Version + " SvnUri:" + Uri + " 本地路径:" + Path); uritarget = new SvnUriTarget(Uri); pathtarget = new SvnPathTarget(Path); // Get Info //log.WriteLog("取服务端信息......"); long endRevision = 0; try { client.GetInfo(uritarget, out uriinfo); endRevision = uriinfo.LastChangeRevision; // Revision代表整个版本库的当前版本,LastChangeRevision 表示这个文件最后的版本 } catch (Exception e) { log.WriteLog("取版本库信息异常: " + uritarget.Uri + " 错误信息:" + e.Message, LogLevel.Error); return false; } //log.WriteLog("取本地文件信息......"); long startRevision = 0; try { client.GetInfo(pathtarget, out pathinfo); startRevision = pathinfo.LastChangeRevision; } catch (Exception e) { log.WriteLog(",取本地版本库信息异常:" + pathtarget.FileName + " 错误信息:" + e.Message, LogLevel.Error); return false; } // 本地文件版本已经最新,不重新获取服务器版本 if (startRevision >= endRevision) { log.WriteLog(pathtarget.FileName + ",本地文件与服务器版本一致,不检查Svn服务器版本。" + "Revision = " + startRevision.ToString()); return true; } // Get Log System.Collections.ObjectModel.Collection<SvnLogEventArgs> logs; SvnLogArgs arg = new SvnLogArgs(); // 时间正序,版本历史从小到大;时间反向,版本历史从大到小 //arg.Range = new SvnRevisionRange(new SvnRevision(DateTime.Now.AddDays(-10)), new SvnRevision(DateTime.Now.AddDays(-20))); arg.Range = new SvnRevisionRange(endRevision, startRevision); //log.WriteLog("取历史......"); client.GetLog(uritarget.Uri, arg, out logs); SvnLogEventArgs l = null; foreach (SvnLogEventArgs g in logs) { // 20111215020-V6.1.4.10-V1,考虑多个修改单递交,文件的修改单号可能不是主修改单号,从修改单列表中检索 // 考虑融资融券和证券公用的修改单资源,按修改单号检查可能会有问题,按照版本直接检查 if (g.LogMessage.IndexOf(Version) >= 0) { l = g; break; } } if (l == null) { log.WriteLog("[无法确认Svn版本信息]," + pathtarget.FileName + ",endRevision = " + endRevision.ToString() + ",startRevision " + startRevision.ToString(), LogLevel.Error); return false; } else if (l.Revision == startRevision) { log.WriteLog("本地文件版本满足,不再检出。Revision = " + l.Revision.ToString()); return true; } else { log.WriteLog("[版本信息] " + pathtarget.FileName + "," + l.LogMessage.Trim() + ",时间:" + l.Time.ToString() + ",版本:" + l.Revision); } // Svn Update //log.WriteLog("更新文件......"); SvnUpdateArgs uarg = new SvnUpdateArgs(); // svn 1.7 使用 uarg.UpdateParents = true; uarg.Depth = SvnDepth.Infinity; uarg.Revision = l.Revision; Result = client.Update(pathtarget.FullPath, uarg); /* Result 更新不到也是true if (Result) { log.WriteLog("更新文件成功!"); } else { log.WriteLog("更新文件失败!"); } * */ return Result; }
/// <summary> /// 检查版本号,如果版本号不符, 则更新 /// </summary> /// <returns></returns> public bool CheckVer() { bool result = true; var repos = new SvnUriTarget(svnurl); var local = new SvnPathTarget(GetAppLoc()); try { notiny = "正在检查服务器版本..."; ShowInfo(); SvnInfoEventArgs serverInfo; bool oks = SC.GetInfo(repos, out serverInfo); notiny = "正在检查本地版本..."; ShowInfo(); SvnInfoEventArgs clientInfo; bool okc = SC.GetInfo(local, out clientInfo); if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令 { result = (serverInfo.Revision > clientInfo.Revision); } ShowInfo(string.Format("检查完毕,服务器版本{0}客户端版本{1}", (serverInfo != null ? serverInfo.Revision.ToString() : "(未知)"), (clientInfo != null ? clientInfo.Revision.ToString() : "(未知)") )); } catch (Exception) { ShowInfo("检查文件是出现错误..."); } return result; }
public override Annotation[] GetAnnotations (Repository repo, FilePath file, SvnRevision revStart, SvnRevision revEnd) { if (file == FilePath.Null) throw new ArgumentNullException (); SvnPathTarget target = new SvnPathTarget (file, SharpSvn.SvnRevision.Base); MemoryStream data = new MemoryStream (); int numAnnotations = 0; client.Write (target, data); using (StreamReader reader = new StreamReader (data)) { reader.BaseStream.Seek (0, SeekOrigin.Begin); while (reader.ReadLine () != null) numAnnotations++; } System.Collections.ObjectModel.Collection<SvnBlameEventArgs> list; SvnBlameArgs args = new SvnBlameArgs (); args.Start = GetRevision (revStart); args.End = GetRevision (revEnd); if (client.GetBlame (target, args, out list)) { Annotation[] annotations = new Annotation [numAnnotations]; foreach (var annotation in list) { if (annotation.LineNumber < annotations.Length) annotations [(int)annotation.LineNumber] = new Annotation (annotation.Revision.ToString (), annotation.Author, annotation.Time); } return annotations; } return new Annotation[0]; }
public override string GetUnifiedDiff (FilePath path1, SvnRevision revision1, FilePath path2, SvnRevision revision2, bool recursive) { SvnPathTarget t1 = new SvnPathTarget (path1, GetRevision (revision1)); SvnPathTarget t2 = new SvnPathTarget (path2, GetRevision (revision2)); SvnDiffArgs args = new SvnDiffArgs (); args.Depth = recursive ? SvnDepth.Infinity : SvnDepth.Children; MemoryStream ms = new MemoryStream (); lock (client) client.Diff (t1, t2, args, ms); ms.Position = 0; using (StreamReader sr = new StreamReader (ms)) { return sr.ReadToEnd (); } }
/// <summary> /// 执行获取本地项目svn信息的操作 /// </summary> /// <param name="projectInfo">传入想要获取信息的projectInfo实例对象</param> /// <returns>获取完信息的projectInfo的实例对象</returns> public ProjectInfo GetLocalInfo(ProjectInfo projectInfo) { using (SvnClient svnClient = new SvnClient()) { try { SvnInfoEventArgs clientInfo; SvnPathTarget local = new SvnPathTarget(projectInfo.Workdirectory); svnClient.GetInfo(local, out clientInfo); //string revision = // Regex.Match(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision), // @"\d+").Value; string author = clientInfo.LastChangeAuthor; string changeTime = clientInfo.LastChangeTime.ToLocalTime().ToString(); projectInfo.Author = author; //projectInfo.Revision = revision; //projectInfo.Changetime = changeTime; return projectInfo; } catch (Exception exception) { return projectInfo; } } }
public void OnExecute(CommandEventArgs e) { ILogControl logWindow = e.Selection.GetActiveControl <ILogControl>(); IProgressRunner progressRunner = e.GetService <IProgressRunner>(); if (logWindow == null) { return; } List <SvnRevisionRange> revisions = new List <SvnRevisionRange>(); if (e.Command == AnkhCommand.LogRevertTo) { ISvnLogItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnLogItem>()); if (item == null) { return; } // Revert to revision, is revert everything after revisions.Add(new SvnRevisionRange(SvnRevision.Working, item.Revision)); } else { foreach (ISvnLogItem item in e.Selection.GetSelection <ISvnLogItem>()) { revisions.Add(new SvnRevisionRange(item.Revision, item.Revision - 1)); } } if (revisions.Count == 0) { return; } IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); HybridCollection <string> nodes = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (SvnOrigin o in logWindow.Origins) { SvnPathTarget pt = o.Target as SvnPathTarget; if (pt == null) { continue; } foreach (string file in tracker.GetDocumentsBelow(pt.FullPath)) { if (!nodes.Contains(file)) { nodes.Add(file); } } } if (nodes.Count > 0) { tracker.SaveDocuments(nodes); // Saves all open documents below all specified origins } using (DocumentLock dl = tracker.LockDocuments(nodes, DocumentLockType.NoReload)) using (dl.MonitorChangesForReload()) { SvnMergeArgs ma = new SvnMergeArgs(); progressRunner.RunModal(LogStrings.Reverting, delegate(object sender, ProgressWorkerArgs ee) { foreach (SvnOrigin item in logWindow.Origins) { SvnPathTarget target = item.Target as SvnPathTarget; if (target == null) { continue; } ee.Client.Merge(target.FullPath, target, revisions, ma); } }); } }
public void Path_TryParseShouldReturnFalse() { SvnPathTarget pt; Assert.That(SvnPathTarget.TryParse("http://qqn.nl/2233234", out pt), Is.False); }