public bool Login() { Initialize(m_strUser, m_strPassword); if (m_initialized) { using (m_client = new SvnClient()) { m_client.Authentication.Clear(); m_client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(m_strUser, m_strPassword); m_client.Authentication.SslServerTrustHandlers += delegate(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e) { e.AcceptedFailures = e.Failures; e.Save = true; // save acceptance to authentication store }; System.Collections.ObjectModel.Collection<SvnLogEventArgs> logEntries; SvnLogArgs logArgs = new SvnLogArgs(); logArgs.Limit = 1; try { m_client.GetLog(m_uriRepository.Uri, logArgs, out logEntries); m_loggedIn = true; } catch (SvnException ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "SVN Connect Error", System.Windows.Forms.MessageBoxButtons.OK); m_loggedIn = false; return false; } } return true; } return false; }
/// <summary> /// Gets the username from an SVN revision. /// </summary> /// <param name="revision">The revision.</param> /// <returns>The username.</returns> public string GetUsername(string revision) { Uri svnUrl = new Uri(this.credentials.Url); long revisionLong = long.Parse(revision); SvnLogArgs args = new SvnLogArgs { Range = new SvnRevisionRange(revisionLong, revisionLong) }; Collection<SvnLogEventArgs> logItems; this.client.GetLog(svnUrl, args, out logItems); return logItems[0].Author; }
protected Collection<SvnLogEventArgs> QueryChangesetsLog() { if (changesetsLog == null) { Collection<SvnLogEventArgs> log; SvnLogArgs svnLogArgs = new SvnLogArgs(); svnLogArgs.Range = new SvnRevisionRange(MinChangeset() + 1, long.MaxValue); svnClient.GetLog(new Uri(repositoryUrl), svnLogArgs, out log); changesetsLog = log; } return changesetsLog; }
public void Log_ExpectLogException() { using (SvnClient client = new SvnClient()) { // Throws an SvnRepositoryIOException in 1.5.x@29330 List<Uri> uris = new List<Uri>(); uris.Add(new Uri("http://svn.apache.org/repos/asf/subversion/README")); uris.Add(new Uri("http://svn.apache.org/repos/asf/subversion/INSTALL")); SvnLogArgs args = new SvnLogArgs(); client.Log(uris, args, delegate(object sender, SvnLogEventArgs e) { }); } }
public void Copy(long startRevision, long endRevision) { _g.StopRequested = false; _g.Source.Init(endRevision); _n = new RevisionProcessor(_g) { CopyAuthor = CopyAuthor, CopyDateTime = CopyDateTime, CopySourceRevision = CopySourceRevision, }; var destinationDirExists = PrepareDestinationDir(); if (destinationDirExists) { _n.ResyncRevision(); } PrepareWorkingDir(); NormalizeDestinationUri(); var lastChange = _g.Source.LastChangeRevision; endRevision = endRevision < 0 ? lastChange : Math.Min(endRevision, lastChange); var svnLogArgs = new SvnLogArgs { End = endRevision, OperationalRevision = endRevision, Limit = LogBatchSize, }; while (startRevision <= endRevision) { svnLogArgs.Start = startRevision; Collection <SvnLogEventArgs> logEvents; _g.Svn.GetLog(_g.Source.Uri, svnLogArgs, out logEvents); foreach (var e in logEvents) { if (_g.StopRequested) { return; } _n.ProcessRevisionLog(e); if (e.Cancel) { return; } startRevision = e.Revision + 1; } } }
private Collection <SvnLogEventArgs> getLog(int limit, SvnRevision rev) { var arg = new SvnLogArgs() { Limit = limit , Start = rev }; Collection <SvnLogEventArgs> results; if (!_svncl.GetLog(_uri, arg, out results)) { return(null); } return(results); }
private bool FileWasDeleted(string path, SvnRevisionId changeset) { var revisionId = new RevisionId { Value = changeset.Value.ToString() }; var arg = new SvnLogArgs(CreateSvnRevisionRangeBy(new RevisionRange(revisionId, revisionId))) { BaseUri = new Uri(_root), ThrowOnError = true }; var revisions = GetSvnRevisions(arg); var item = revisions[0].ChangedPaths.FirstOrDefault(itemCollection => itemCollection.Path == path); return(item != null && item.Action == SvnChangeAction.Delete); }
public void Log_TestLocalLogVariants() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); SvnLogArgs a = new SvnLogArgs(); string dir = sbox.Wc; Client.CheckOut(new Uri(CollabReposUri, "trunk/"), dir); bool touched = false; Client.Log(dir, delegate(object sender, SvnLogEventArgs e) { touched = true; }); Assert.That(touched); touched = false; touched = false; Client.Log(dir, a, delegate(object sender, SvnLogEventArgs e) { touched = true; }); Assert.That(touched); touched = false; Client.Log(Path.Combine(dir, "index.html"), a, delegate(object sender, SvnLogEventArgs e) { touched = true; }); Assert.That(touched); touched = false; Client.Log(new string[] { dir, Path.Combine(dir, "index.html") }, a, delegate(object sender, SvnLogEventArgs e) { touched = true; }); Assert.That(touched); }
public override IEnumerable <SvnRevision> Log(Repository repo, FilePath path, SvnRevision revisionStart, SvnRevision revisionEnd) { List <SvnRevision> list = new List <SvnRevision> (); SvnLogArgs args = new SvnLogArgs(); args.Range = new SvnRevisionRange(GetRevision(revisionStart), GetRevision(revisionEnd)); client.Log(path, args, delegate(object o, SvnLogEventArgs a) { List <RevisionPath> paths = new List <RevisionPath> (); foreach (SvnChangeItem item in a.ChangedPaths) { paths.Add(new RevisionPath(item.Path, ConvertRevisionAction(item.Action), "")); } SvnRevision r = new SvnRevision(repo, (int)a.Revision, a.Time, a.Author, a.LogMessage, paths.ToArray()); list.Add(r); }); return(list); }
public override IEnumerable <WorkItem> GetHistory(int maxRevisions) { var args = new SvnLogArgs { Limit = maxRevisions }; Collection <SvnLogEventArgs> entries; _svn.GetLog(_root.Uri, args, out entries); if (entries != null && entries.Count > 0) { return(entries.Select(ToWorkItem)); } return(null); }
public Tuple <List <string>, List <string> > ChangedPaths(string path, long revision) { var client = _client.GetObject(); var args = new SvnLogArgs { Start = new SvnRevision(revision), End = new SvnRevision(revision), OperationalRevision = new SvnRevision(revision) }; client.GetLog(new Uri(_svnPath, path), args, out var items); _client.PutObject(client); return(Tuple.Create( items[0].ChangedPaths.Where(a => a.NodeKind == SvnNodeKind.File) .Select(a => a.Path.Remove(0, path.Length + 2)).ToList(), items[0].ChangedPaths.Where(a => a.NodeKind == SvnNodeKind.Directory && (a.Action != SvnChangeAction.Add || a.CopyFromPath != null)) .Select(a => a.Path.Remove(0, path.Length + 2)).ToList())); }
public void Log_TestLogNonAsciiChars() { SvnSandBox sbox = new SvnSandBox(this); Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Default); sbox.InstallRevpropHook(ReposUrl); this.RunCommand("svn", "propset svn:log --revprop -r 1 \" e i a , sj\" " + ReposUrl); SvnLogArgs a = new SvnLogArgs(); a.Range = new SvnRevisionRange(1, 1); this.Client.Log(ReposUrl, a, LogCallback); Assert.That(this.logMessages.Count, Is.EqualTo(1)); Assert.That(this.logMessages[0].LogMessage, Is.EqualTo(" e i a , sj")); }
public void Commit_SetCustomProps() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; string fp = Path.Combine(WcPath, "NewFile.cs"); Touch2(fp); Client.Add(fp); SvnCommitArgs ca = new SvnCommitArgs(); ca.LogMessage = "Committed extra"; ca.LogProperties.Add("my:prop", "PropValue"); ca.RunTortoiseHooks = true; SvnCommitResult cr; Client.Commit(WcPath, ca, out cr); string value; Client.GetRevisionProperty(sbox.RepositoryUri, cr.Revision, "my:prop", out value); Assert.That(value, Is.EqualTo("PropValue")); SvnLogArgs la = new SvnLogArgs(); la.RetrieveProperties.Add("my:prop"); la.Start = la.End = cr.Revision; Collection <SvnLogEventArgs> lc; Client.GetLog(WcPath, la, out lc); Assert.That(lc.Count, Is.EqualTo(1)); Assert.That(lc[0].RevisionProperties.Contains("my:prop")); SvnLogEventArgs l = lc[0]; Assert.That(l.RevisionProperties["my:prop"].StringValue, Is.EqualTo("PropValue")); Assert.That(l.Author, Is.EqualTo(Environment.UserName)); }
private void ana_logs(long strtRev, long endRev, string expDir, bool excDel, string toRootPath, string tmpKickBatPath) { var args = new SvnLogArgs() { Range = new SvnRevisionRange(strtRev, endRev) }; Collection <SvnLogEventArgs> logs; this._svncl.GetLog(this._uri, args, out logs); logs = new Collection <SvnLogEventArgs>(logs.OrderBy(v => v.Revision).Select(v => v).ToArray()); var trgtLst = ana_revfiles(logs, expDir, excDel); var batFlNm = string.Format(@"r{0}to{1}.bat", trgtLst[0][1], trgtLst[trgtLst.Count - 1][1]); var existTrgtCmd = @"rem rev:{0}" + Environment.NewLine + @"call ""%workDir%\{0}.bat"" ""{1}""" + Environment.NewLine; var notExistTrgtCmd = @"rem rev:{0} 対象なし" + Environment.NewLine + @"rem call %workDir%\{0}.bat ""{1}""" + Environment.NewLine; using (var sw = createAutoBatStrm(expDir, batFlNm)) { foreach (var trgt in trgtLst) { if (trgt[0] > 0) { sw.WriteLine(string.Format(existTrgtCmd, @"r" + retPadLeftZero(trgt[1]), @"%dstDir%")); } else { sw.WriteLine(string.Format(notExistTrgtCmd, @"r" + retPadLeftZero(trgt[1]), @"dstDir%")); } } } var kickBatPath = Path.Combine(toRootPath, @"autoCommit.bat"); File.Copy(tmpKickBatPath, kickBatPath); string cmdtxt; using (var sr = new StreamReader(kickBatPath, Encoding.GetEncoding(932))) cmdtxt = sr.ReadToEnd(); using (var sw = new StreamWriter(kickBatPath, false, Encoding.GetEncoding(932))) sw.WriteLine(string.Format(cmdtxt, batFlNm)); }
public override RevisionInfo[] GetRevisions(RevisionRange revisionRange) { try { SvnRevisionId fromChangeset = revisionRange.FromChangeset; SvnRevisionId toChangeset = revisionRange.ToChangeset; _logger.DebugFormat("Getting revision infos [{0}:{1}]", fromChangeset, toChangeset); var arg = new SvnLogArgs(new SvnRevisionRange(fromChangeset.Value, toChangeset.Value)) { ThrowOnError = true }; return(SubversionUtils.ArrayOfSvnRevisionToArrayOfRevisionInfo(GetSvnRevisions(arg), this).ToArray()); } catch (SvnException e) { throw new VersionControlException(String.Format("Subversion exception: {0}", e.Message), e); } }
public void Start(LogMode mode) { lock (_instanceLock) { _mode = mode; SvnLogArgs args = new SvnLogArgs(); args.Start = LogSource.Start; args.End = LogSource.End; // If we have EndRevision set, we want all items until End if (args.End == null || args.End.RevisionType == SvnRevisionType.None) { args.Limit = 10; } args.StrictNodeHistory = LogSource.StopOnCopy; args.RetrieveMergedRevisions = LogSource.IncludeMergedRevisions; StartFetch(args); } }
private void UpdateLogListView() { RedisClient redis = new RedisClient(MainWindow.myRedisIP, MainWindow.myRedisPort, null, MainWindow.database); SvnClient svn = new SvnClient(); svn.Authentication.UserNamePasswordHandlers += new EventHandler <SharpSvn.Security.SvnUserNamePasswordEventArgs>( delegate(Object s, SharpSvn.Security.SvnUserNamePasswordEventArgs e1) { e1.UserName = GlobalVariable.svnUserName; e1.Password = GlobalVariable.svnPassword; }); while (running) { this.Dispatcher.BeginInvoke( (ThreadStart) delegate() { Collection <SvnLogEventArgs> svnLogs = new Collection <SvnLogEventArgs>(); svnLogs.Clear(); { SvnLogArgs logarg = new SvnLogArgs(); logarg.Limit = maxNumOfDisplay; if (svnLogTabControl.SelectedIndex >= 0 && svnLogTabControl.SelectedIndex <= 3) { if (svn.GetLog((Uri)svnLogUris[svnLogTabControl.SelectedIndex], logarg, out svnLogs)) { UpdateListView(svnLogs, (ListView)svnLogListViews[svnLogTabControl.SelectedIndex]); } } //for (int i = 0; i < svnLogUris.Count; i++) //{ // if (svn.GetLog((Uri)svnLogUris[i], logarg, out svnLogs)) // UpdateListView(svnLogs, (ListView)svnLogListViews[i]); //} } }); Thread.Sleep(5000); } redis.Quit(); }
public void Authentication_TestSimpleProvider() { Client.Authentication.Clear(); bool arrived = false; SvnLogArgs a = new SvnLogArgs(); a.Limit = 1; //Assert.That(Client.Log(new Uri("svn://svn.tartarus.org/sgt/putty-0.60/misc.c"), // delegate(object sender, SvnLogEventArgs e) // { // arrived = true; // })); //Assert.That(arrived); arrived = false; Assert.That(Client.Info(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); arrived = false; Client.Authentication.SslServerTrustHandlers += new EventHandler <SvnSslServerTrustEventArgs>(Authenticator_SslServerTrustHandlersAllow); Assert.That(Client.List(new Uri("https://svn.apache.org/repos/asf/apr/"), delegate(object sender, SvnListEventArgs e) { arrived = true; })); Assert.That(arrived); SvnClient cl2 = new SvnClient(); cl2.Authentication.CopyAuthenticationCache(Client); cl2.Authentication.ClearAuthenticationCache(); }
internal void FetchAll() { lock (_instanceLock) { if (_running) { _fetchAll = true; return; } _fetchAll = false; SvnLogArgs args = new SvnLogArgs(); if (_lastRevision >= 0) { long startRev = _lastRevision - 1; args.Start = startRev < 0 ? SvnRevision.Zero : startRev; } else { lock (_logItems) { if (_logItems.Count > 0) { LogRevisionItem[] items = _logItems.ToArray(); long revision = items[items.Length - 1].Revision - 1; // revision should not be < 0 args.Start = revision < 0 ? SvnRevision.Zero : revision; } } } args.End = LogSource.End; args.StrictNodeHistory = LogSource.StopOnCopy; args.RetrieveMergedRevisions = LogSource.IncludeMergedRevisions; StartFetch(args); } }
public void Log_TestLog() { SvnSandBox sbox = new SvnSandBox(this); Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.AnkhSvnCases); ClientLogMessage[] clientLogs = this.ClientLog(ReposUrl); //the client prints them in a reverse order by default Array.Reverse(clientLogs); SvnLogArgs a = new SvnLogArgs(); a.Range = new SvnRevisionRange(1, SvnRevision.Head); a.RetrieveChangedPaths = false; this.Client.Log(ReposUrl, a, LogCallback); Assert.That(this.logMessages.Count, Is.EqualTo(clientLogs.Length), "Number of log entries differs"); for (int i = 0; i < this.logMessages.Count; i++) { clientLogs[i].CheckMatch(this.logMessages[i]); } }
/// <summary> /// because the library use UTC datetime, so can not believe datetime /// </summary> /// <param name="startDateTime"></param> /// <param name="endDateTime"></param> /// <returns></returns> private long[] GetVersion(DateTime startDateTime, DateTime endDateTime) { SvnRevisionRange range = new SvnRevisionRange(new SvnRevision(startDateTime.AddDays(-1)), new SvnRevision(endDateTime.AddDays(2))); SvnLogArgs logArgs = new SvnLogArgs() { Limit = 0, Range = range, RetrieveAllProperties = true, }; Collection <SvnLogEventArgs> logs; client.GetLog(new Uri(serverPath), logArgs, out logs); long[] revisions = new long[2] { -1, -1 }; foreach (var log in logs) { if (log.Time.ToLocalTime().Date >= startDateTime.Date && revisions[0] == -1) { revisions[0] = log.Revision; } revisions[1] = log.Revision; if (log.Time.ToLocalTime().Date > endDateTime.Date) { break; } } if (revisions[0] == -1) { return(null); } return(revisions); }
/// <exception cref="ArgumentNullException"><paramref name="baseVersion" /> is <see langword="null" />.</exception> protected override Version PatchVersionBeforeCalculatingTheSemVersion(Version baseVersion) { if (baseVersion == null) { throw new ArgumentNullException(nameof(baseVersion)); } Collection <SvnLogEventArgs> logItems; using (var svnClient = new SvnClient()) { // TODO if there is any chance, rather use svnClient.GetInfo(URL)...LastChangeRevision var svnLogArgs = new SvnLogArgs { StrictNodeHistory = false, Range = new SvnRevisionRange(SvnRevision.Head, SvnRevision.Zero), Limit = 1 }; if (!svnClient.GetLog(this.RepositoryPath, svnLogArgs, out logItems) || logItems == null) { this.LogError?.Invoke($"Could not get log for repository in {this.RepositoryPath}"); return(null); } } var recentLogItem = logItems.Single(); var patchedBaseVersion = new Version(baseVersion.Major, baseVersion.Minor, baseVersion.Build, (int)recentLogItem.Revision); return(patchedBaseVersion); }
public HashSet <string> GetLogByTime(DateTime startDateTime, DateTime endDateTime) { long[] revisions = GetVersion(startDateTime, endDateTime); if (revisions == null) { return(null); } SvnRevisionRange range = new SvnRevisionRange(revisions[0], revisions[1]); SvnLogArgs logArgs = new SvnLogArgs() { Limit = 0, Range = range, RetrieveAllProperties = true, }; Collection <SvnLogEventArgs> logs; client.GetLog(new Uri(serverPath), logArgs, out logs); HashSet <string> fetchFiles = new HashSet <string>(); foreach (var log in logs) { foreach (var changeItem in log.ChangedPaths) { if (changeItem.Action == SvnChangeAction.Modify || changeItem.Action == SvnChangeAction.Add || changeItem.Action == SvnChangeAction.Replace) { fetchFiles.Add(ChangeToLocalPath(changeItem.Path)); } } } return(fetchFiles); }
private IEnumerable<Commit> GetCommits(SvnClient client, string repoUrl, long endRevision, int count, Func<SvnLogEventArgs, bool> filter) { var repoDiscoveryStep = RepoDiscoveryStepCoef * count; var commits = new List<Commit>(); long discoveredDepth = 0; while (commits.Count < count && discoveredDepth <= MaxRepositoryDiscoverDepth && endRevision > 1) { var startRevision = endRevision > repoDiscoveryStep ? endRevision - repoDiscoveryStep : 1; var logArguments = new SvnLogArgs { Start = startRevision, End = endRevision }; Collection<SvnLogEventArgs> logEvents; client.GetLog(new Uri(repoUrl), logArguments, out logEvents); commits.AddRange(_mapper.Map<SvnLogEventArgs, Commit>(logEvents.Where(filter))); discoveredDepth += endRevision - startRevision; endRevision = endRevision - 1 > repoDiscoveryStep ? endRevision - repoDiscoveryStep - 1 : 1; } return commits; }
public static void GetLog(Source source, long startRevision, out Collection<SvnLogEventArgs> collection) { SvnLogArgs args = new SvnLogArgs { Limit = ApplicationSettingsManager.Settings.LogEntriesPageSize, ThrowOnError = true }; if (startRevision >= 0L) { args.Start = new SvnRevision(startRevision); args.End = new SvnRevision(SvnRevisionType.Head); } using (SvnClient client = GetSvnClient(source)) { if (source.IsURL) { client.GetLog(new Uri(source.Path), args, out collection); } else { client.GetLog(source.Path, args, out collection); } } }
// svn 日志的渲染及更新 public void DrawSvnLog() { svnLogUris.Clear(); { try { svnLogUris.Add(new Uri(thisWindowRedis.Get <string>("svn_assist:config:svn_log:1:link"))); svnLogUris.Add(new Uri(thisWindowRedis.Get <string>("svn_assist:config:svn_log:3:link"))); svnLogUris.Add(new Uri(thisWindowRedis.Get <string>("svn_assist:config:svn_log:2:link"))); svnLogUris.Add(new Uri(thisWindowRedis.Get <string>("svn_assist:config:svn_log:4:link"))); } catch (Exception) { if (MessageBox.Show("svn的部分Uri无效,是否退出程序?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { running = false; this.Close(); } else { return; } } } try { { Thread firstDrawLog = new Thread(new ThreadStart(() => { this.Dispatcher.BeginInvoke( (ThreadStart) delegate() { SvnClient svn = new SvnClient(); svn.Authentication.UserNamePasswordHandlers += new EventHandler <SharpSvn.Security.SvnUserNamePasswordEventArgs>( delegate(Object s, SharpSvn.Security.SvnUserNamePasswordEventArgs e1) { e1.UserName = GlobalVariable.svnUserName; e1.Password = GlobalVariable.svnPassword; }); Collection <SvnLogEventArgs> svnLogs = new Collection <SvnLogEventArgs>(); SvnLogArgs logarg = new SvnLogArgs(); logarg.Limit = maxNumOfDisplay; for (int i = 0; i < svnLogUris.Count; i++) { if (svn.GetLog((Uri)svnLogUris[i], logarg, out svnLogs)) { UpdateListView(svnLogs, (ListView)svnLogListViews[i]); } } svn.Dispose(); }); })); firstDrawLog.IsBackground = true; firstDrawLog.Start(); } StartUpdateSvnLog(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Warning); } }
void LoadLogEntries(Uri branchUri, RevRangeSet revRangesSet) { var min = revRangesSet.Ranges.First().RangeStart; var max = revRangesSet.Ranges.Last().RangeEnd; var args = new SvnLogArgs(new SvnRevisionRange(min, max)) { RetrieveChangedPaths = true, OperationalRevision = min }; Collection<SvnLogEventArgs> logEntries; _client.GetLog(branchUri, args, out logEntries); _cancellationToken.ThrowIfCancellationRequested(); foreach (var logEntry in logEntries) { if (!revRangesSet.ContainsRevision(logEntry.Revision)) continue; if (_revLogEntries.ContainsKey(logEntry.Revision)) continue; // mark as in progress _revLogEntries[logEntry.Revision] = null; var changedDirs = logEntry.ChangedPaths.Where(IsPossibleMergeRevision).ToArray(); var mergeRevision = false; foreach (var cd in changedDirs) { var changedUri = new Uri(_repoRoot.ToString().TrimEnd('/') + cd.Path); var merged = GetMergedRevisions(changedUri.ToString(), logEntry.Revision); if (merged.Count > 0) { mergeRevision = true; // exclude merged revisions from branch which was requested. to avoid merged messages from // trunk < reintegrate feature < sync trunc // sync trunk messages shall be droped while (true) { var removed = false; foreach (var kvp in merged) { if ((kvp.Key.TrimEnd('/') + "/").StartsWith(_requestedMergeMessageForBranch)) { merged.Remove(kvp.Key); removed = true; break; } } if (!removed) break; } if (merged.Count > 0) LoadLogEntries(merged); } } // not store merge revisions message if (mergeRevision) continue; // check if it is agan merge revision _revLogEntries[logEntry.Revision] = new RevLogEntry { Author = logEntry.Author, Message = logEntry.LogMessage, Revision = logEntry.Revision }; } }
protected void btnSubmit_Click(object sender, EventArgs e) { reposUri = GetAbsoluteUri(ddlSecMasterVersion.SelectedValue); radioButtonSelectedItem = optionList.SelectedValue; if (radioButtonSelectedItem == "Updates") { Collection<SvnLogEventArgs> logcollection = null; SvnLogArgs logargs = null; logargs = new SvnLogArgs { Range = new SvnRevisionRange(Int32.Parse(txtRevision.Text), SvnRevisionType.Head) }; client.GetLog(reposUri, logargs, out logcollection); int i = 1; foreach (SvnLogEventArgs logEventArgs in logcollection) { Debug.WriteLine("Entry " + i); foreach (var changedpaths in logEventArgs.ChangedPaths) { Uri absolute = GetAbsoluteUri(reposUri.ToString() + changedpaths.RepositoryPath.ToString()); if (changedpaths.Action.ToString() != "Delete") { SvnExportArgs exportargs = new SvnExportArgs(); exportargs.Overwrite = true; System.Diagnostics.Debug.WriteLine(changedpaths.Action); string[] directorytemp = changedpaths.RepositoryPath.ToString().Split('/'); string directorypath = null; for (int j = 0; j < directorytemp.Length - 1; j++) { directorypath = directorypath + directorytemp[j] + '\\'; } string temptarget = "C:\\Back Up\\Crap\\svnexport\\Updates" + directorypath; Directory.CreateDirectory(temptarget); string target = temptarget + directorytemp[directorytemp.Length - 1]; Collection<SvnInfoEventArgs> info = null; bool flag = client.GetInfo(absolute, new SvnInfoArgs { ThrowOnError = false }, out info); if (flag) { client.Export(absolute, target, exportargs); Debug.WriteLine("File Created"); } } Debug.WriteLine(changedpaths.RepositoryPath); } i++; Debug.WriteLine("\n\n"); } } else if (radioButtonSelectedItem == "Install") { string storepath = "C:\\Back Up\\Crap\\svnexport\\Install"; SvnUpdateResult exportResult = null; client.Export(reposUri, storepath, new SvnExportArgs { Overwrite = true, Revision = SvnRevision.Head },out exportResult); Debug.WriteLine(exportResult.Revision); } else if (radioButtonSelectedItem == "Batch") { string storepath = "C:\\Back Up\\Crap\\svnexport\\Batch"; SvnUpdateResult exportResult = null; client.Export(reposUri, storepath, new SvnExportArgs { Overwrite = true, Revision = new SvnRevision(long.Parse(txtRevision.Text))}, out exportResult); Debug.WriteLine(exportResult.Revision); } }
public IEnumerable<SvnCommit> ListCommits(TimeSpan span) { using (var a = this.CreateClient()) { var results = new List<SvnCommit>(); var arg = new SvnLogArgs() { RetrieveAllProperties = true, RetrieveChangedPaths = true, Range = new SvnRevisionRange(new SvnRevision(DateTime.Now - span), new SvnRevision(DateTime.Now)) }; a.Log( this.RepositoryUri, arg, (sender, args) => results.Add(new SvnCommit() { Revision = args.Revision, LogMessage = args.LogMessage.Replace("\r", "").Replace("\n", " "), Author = MapName(args.Author), Root = CommonPrefix(args.ChangedPaths.Select(p=>p.Path).ToArray()), FilesChanged = args.ChangedPaths.Count }) ); return results; } }
public override RevisionInfo[] GetRevisions(RevisionRange revisionRange) { try { SvnRevisionId fromChangeset = revisionRange.FromChangeset; SvnRevisionId toChangeset = revisionRange.ToChangeset; _logger.DebugFormat("Getting revision infos [{0}:{1}]", fromChangeset, toChangeset); var arg = new SvnLogArgs(new SvnRevisionRange(fromChangeset.Value, toChangeset.Value)) {ThrowOnError = true}; return SubversionUtils.ArrayOfSvnRevisionToArrayOfRevisionInfo(GetSvnRevisions(arg), this).ToArray(); } catch (SvnException e) { throw new VersionControlException(String.Format("Subversion exception: {0}", e.Message), e); } }
private Collection<SvnLogEventArgs> GetSvnRevisions(SvnLogArgs arg, string path) { var targetPath = GetPath(path); Collection<SvnLogEventArgs> svnRevisions; if (Client.GetLog(targetPath, arg, out svnRevisions)) { RemoveChangedItemFromOtherProject(svnRevisions); return svnRevisions; } return null; }
/// <summary> /// 从SVN检出并自动更新项目 /// </summary> public List <string> CheckOutPrograme() { using (SvnClient client = new SvnClient()) { SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget(SVNAdress); //SvnPathTarget local = new SvnPathTarget(@"C:\demo"); client.Authentication.UserNamePasswordHandlers += new EventHandler <SvnUserNamePasswordEventArgs>( delegate(object s, SvnUserNamePasswordEventArgs e) { e.UserName = SVNUserName; e.Password = SVNUserPwd; }); client.Authentication.SslServerTrustHandlers += new EventHandler <SharpSvn.Security.SvnSslServerTrustEventArgs>( delegate(Object ssender, SharpSvn.Security.SvnSslServerTrustEventArgs se) { // Look at the rest of the arguments of E whether you wish to accept // If accept: se.AcceptedFailures = se.Failures; se.Save = true; // Save acceptance to authentication store }); //string path = @"C:\Demo"; //client.CleanUp(path); //client.Revert(path); if (!Directory.Exists(SVNPath)) { Directory.CreateDirectory(SVNPath); } client.CheckOut(repos, SVNPath); client.Update(SVNPath); client.GetInfo(repos, out serverInfo); client.GetInfo(SVNPath, out clientInfo); List <string> listMsg = new List <string>(); SvnLogArgs logArgs = new SvnLogArgs(); logArgs.Range = new SvnRevisionRange(clientInfo.LastChangeRevision, serverInfo.LastChangeRevision); logArgs.RetrieveAllProperties = true; EventHandler <SvnLogEventArgs> logHandler = new EventHandler <SvnLogEventArgs>(delegate(object lo, SvnLogEventArgs le) { foreach (SvnChangeItem changeItem in le.ChangedPaths) { string str = string.Format( "[操作]:{0} [路径]:{1} [作者]:{2} [日志]:{3} [版本]:{4} ", changeItem.Action, changeItem.Path, //changeItem.CopyFromRevision, //changeItem.CopyFromPath, le.Author, le.LogMessage, le.Revision); listMsg.Add(str); } }); client.Log(new Uri(SVNAdress), logArgs, logHandler); return(listMsg); // this.txtLog.Text += DateTime.Now.ToLongTimeString() + "\r\n"; //Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision)); //Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision)); } //using (SvnClient client = new SvnClient()) //{ // client. // client.Authentication.UserNamePasswordHandlers += // new EventHandler<SvnUserNamePasswordEventArgs>( // delegate (object s, SvnUserNamePasswordEventArgs e) // { // e.UserName = "******"; // e.Password = "******"; // }); //} //using (SvnClient client = new SvnClient()) //{ // SharpSvn.UI.SvnUIBindArgs uiBindArgs = new SharpSvn.UI.SvnUIBindArgs(); // SharpSvn.UI.SvnUI.Bind(client, uiBindArgs); //} }
public long GetLastRevisionNumber(Uri url) { Collection<SvnLogEventArgs> logItems; var svnLogArgs = new SvnLogArgs {StrictNodeHistory = true}; bool success = _client.GetLog(url, svnLogArgs, out logItems); if (!success) { throw new NotSupportedException(); } return logItems.Max(x => x.Revision); }
public bool Commit() { if (!m_loggedIn) return false; using (m_client = new SvnClient()) { m_client.Authentication.Clear(); m_client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(m_strUser, m_strPassword); m_client.Authentication.SslServerTrustHandlers += delegate(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e) { e.AcceptedFailures = e.Failures; e.Save = true; // save acceptance to authentication store }; System.Collections.ObjectModel.Collection<SvnLogEventArgs> logEntries; SvnLogArgs logArgs = new SvnLogArgs(); logArgs.Limit = 1; try { m_client.GetLog(m_uriRepository.Uri, logArgs, out logEntries); m_loggedIn = true; } catch (SvnException ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "SVN Connect Error", System.Windows.Forms.MessageBoxButtons.OK); m_loggedIn = false; return false; } try { SvnCommitArgs args = new SvnCommitArgs(); args.LogMessage = "Update release data " + DateTime.Now.ToString(); args.Depth = SvnDepth.Infinity; return m_client.Commit(m_client.GetWorkingCopyRoot(m_strCheckoutPath), args); } catch (SvnException ex) { String msg = ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace.ToString(); System.Windows.Forms.MessageBox.Show(ex.Message, "SVN Commit Error", System.Windows.Forms.MessageBoxButtons.OK); return false; } } }
public void ChangeInfo_GetInfoCompare() { SvnSandBox sbox = new SvnSandBox(this); Uri reposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string reposPath = reposUri.LocalPath; using (SvnClient cl = new SvnClient()) { SvnSetPropertyArgs sa = new SvnSetPropertyArgs(); sa.BaseRevision = 17; sa.LogMessage = "Message"; cl.RemoteSetProperty(reposUri, "MyProp", "Value", sa); } for (long ii = 1; ii < 19; ii++) { using (SvnLookClient lcl = new SvnLookClient()) using (SvnClient cl = new SvnClient()) { SvnChangeInfoEventArgs r; SvnChangeInfoArgs ia = new SvnChangeInfoArgs(); SvnLookOrigin origin = new SvnLookOrigin(reposPath, ii); SvnLogArgs la = new SvnLogArgs(); la.Start = la.End = ii; Collection<SvnLogEventArgs> lrc; //ia.RetrieveChangedPaths = false; // Will fail if true Assert.That(lcl.GetChangeInfo(origin, ia, out r)); Assert.That(cl.GetLog(reposUri, la, out lrc)); Assert.That(r, Is.Not.Null); Assert.That(lrc.Count, Is.EqualTo(1)); SvnLogEventArgs lr = lrc[0]; Assert.That(r.Author, Is.EqualTo(lr.Author)); Assert.That(r.Revision, Is.EqualTo(lr.Revision)); Assert.That(r.BaseRevision, Is.EqualTo(lr.Revision - 1)); Assert.That(r.LogMessage, Is.EqualTo(lr.LogMessage)); Assert.That(r.Time, Is.EqualTo(lr.Time)); Assert.That(r.ChangedPaths, Is.Not.Null, "r.ChangedPaths({0})", ii); Assert.That(lr.ChangedPaths, Is.Not.Null, "lr.ChangedPaths({0})", ii); Assert.That(r.ChangedPaths.Count, Is.EqualTo(lr.ChangedPaths.Count)); for (int i = 0; i < r.ChangedPaths.Count; i++) { SvnChangeItem c = r.ChangedPaths[i]; SvnChangeItem lc = lr.ChangedPaths[c.Path]; Assert.That(c.Path, Is.EqualTo(lc.Path)); Assert.That(c.Action, Is.EqualTo(lc.Action)); Assert.That(c.CopyFromPath, Is.EqualTo(lc.CopyFromPath)); Assert.That(c.CopyFromRevision, Is.EqualTo(lc.CopyFromRevision)); } } } }
public SvnLogArgs Optimize(Specification<Changeset> specification) { var args = new SvnLogArgs(); handler.Request(new SpecificationRequest(specification, args)); return args; }
public void Copy() { Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = true; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler<SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair<long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.simulationOnly) continue; SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList<string, SvnChangeItem> changeItems = new SortedList<string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } foreach (SvnChangeItem changeItem in changeItems.Values) { string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine("{0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: { Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } break; case SvnChangeAction.Delete: { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; _client.Delete(targetPath, svnDeleteArgs); } break; } } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Commiting {0}", _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') break; if (k == 'n') throw new Exception("Aborted by user."); } } _client.Commit(_args.Destination, commitArgs); } }
protected override IEnumerable <string> GetCommitMessages() { SvnWorkingCopyVersion svnWorkingCopyVersion; using (var svnWorkingCopyClient = new SvnWorkingCopyClient()) { if (!svnWorkingCopyClient.GetVersion(this.RepositoryPath, out svnWorkingCopyVersion) || svnWorkingCopyVersion == null) { this.LogError?.Invoke($"Could not get working copy version for {this.RepositoryPath}"); return(Enumerable.Empty <string>()); } } if (svnWorkingCopyVersion.Modified) { this.LogError?.Invoke($"Could not calculate version for {this.RepositoryPath} due to local uncomitted changes"); return(Enumerable.Empty <string>()); } Collection <SvnLogEventArgs> logItems; using (var svnClient = new SvnClient()) { SvnRevision start; if (this.BaseRevision == null) { start = SvnRevision.Zero; } else { int startRevision; if (!int.TryParse(this.BaseRevision, out startRevision)) { this.LogError?.Invoke($"could not parse {nameof(this.BaseRevision)} to {typeof (int).FullName}: {this.BaseRevision}"); return(Enumerable.Empty <string>()); } start = startRevision; } this.LogInfo?.Invoke($"retrieving commits from {this.RepositoryPath} since {start}"); var svnLogArgs = new SvnLogArgs { StrictNodeHistory = false, Range = new SvnRevisionRange(start, SvnRevision.Head) }; if (!svnClient.GetLog(this.RepositoryPath, svnLogArgs, out logItems) || logItems == null) { this.LogError?.Invoke($"Could not get log for repository in {this.RepositoryPath}"); return(null); } } var commitMessages = logItems.OrderBy(arg => arg.Revision) .Select(arg => arg.LogMessage); return(commitMessages); }
public void repoStart() { SvnRevertArgs revertArgs = new SvnRevertArgs() { Depth = SvnDepth.Infinity }; Stopwatch stopwatch = Stopwatch.StartNew(); Parallel.ForEach(repoDataSet.Tables["Repo"].Rows.Cast <DataRow>(), row => { string repoName = row[0].ToString(); string repoType = row[1].ToString() + "s"; string repoUrl = row[2].ToString(); string repoPath = $@"{repoType}\{repoName}"; long currentLap; long totalLap; currentLap = stopwatch.ElapsedMilliseconds; try { using (SvnClient client = new SvnClient()) { if (System.IO.Directory.Exists($@"{repoPath}\.svn")) { Collection <SvnLogEventArgs> logitems; SvnInfoEventArgs remoteRev; client.GetInfo(repoUrl, out remoteRev); SvnInfoEventArgs localRev; client.GetInfo(repoPath, out localRev); SvnLogArgs logArgs = new SvnLogArgs() { Start = localRev.Revision + 1, End = remoteRev.Revision }; if (localRev.Revision < remoteRev.Revision) { client.Revert(repoPath, revertArgs); client.Update(repoPath); totalLap = stopwatch.ElapsedMilliseconds - currentLap; client.GetLog(repoPath, logArgs, out logitems); foreach (var logentry in logitems) { String logString = logentry.LogMessage.Replace(System.Environment.NewLine, " "); WriteLog(repoLog, $@"[{Name}-v{Version}] {repoName} r{logentry.Revision}: {logString}"); } WriteLog(repoLog, $"[{Name}-v{Version}] updated [{repoType}] {repoName} from {localRev.Revision} to {remoteRev.Revision} in {totalLap} ms."); if (repoType != "Profiles") { restartNeeded = true; } } } else { client.CheckOut(new Uri(repoUrl), repoPath); totalLap = stopwatch.ElapsedMilliseconds - currentLap; WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} checkout complete in {totalLap} ms."); if (repoType != "Profiles") { restartNeeded = true; } } } } catch (SharpSvn.SvnAuthenticationException e) { WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} No more credentials or we tried too many times. {e}"); } catch (System.AccessViolationException e) { WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} Access Violation, something is locking the folder. {e}"); } catch (SharpSvn.SvnFileSystemException e) { WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} FileSystemException, repo has probably been moved/deleted. {e}"); } catch (SharpSvn.SvnException e) { WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} Generic SvnException, do you have tortoiseSVN monitoring this folder? CN users may need a VPN to access GitHub. {e}"); WriteLog(repoLog, $"[{Name}-v{Version}] **************************"); WriteLog(repoLog, $"[{Name}-v{Version}] This will prevent further updates, delete the {repoName} .svn folder and make sure tortoiseSVN doesn't manage anything repoBuddy does."); WriteLog(repoLog, $"[{Name}-v{Version}] **************************"); restartNeeded = false; } }); stopwatch.Stop(); Logging.Write(LogColor, $"[{Name}-v{Version}] processes complete in {stopwatch.ElapsedMilliseconds} ms."); MigrateLlamaLibrary(); if (repoLog.Count > 0) { using (StreamWriter file = File.CreateText(@"Plugins\repoBuddy\repoLog.json")) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, repoLog); } } if (restartNeeded) { Logging.Write(LogColor, $"[{Name}-v{Version}] Restarting to reload assemblies."); RestartRebornBuddy(); } }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler<SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair<long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision ) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) continue; SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList<string, SvnChangeItem> changeItems = new SortedList<string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List<string> filesAdd = new List<string>(); List<string> filesDelete = new List<string>(); List<string> filesModify = new List<string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (! changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (! File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') break; if (k == 'n') throw new Exception("Aborted by user."); } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
public override IEnumerable<SvnRevision> Log (Repository repo, FilePath path, SvnRevision revisionStart, SvnRevision revisionEnd) { List<SvnRevision> list = new List<SvnRevision> (); SvnLogArgs args = new SvnLogArgs (); args.Range = new SvnRevisionRange (GetRevision (revisionStart), GetRevision (revisionEnd)); lock (client) client.Log (path, args, delegate (object o, SvnLogEventArgs a) { List<RevisionPath> paths = new List<RevisionPath> (); foreach (SvnChangeItem item in a.ChangedPaths) { paths.Add (new RevisionPath (item.Path, ConvertRevisionAction (item.Action), "")); } SvnRevision r = new SvnRevision (repo, (int) a.Revision, a.Time, a.Author, a.LogMessage, paths.ToArray ()); list.Add (r); }); return list; }
public void Copy() { long lastSyncRevision = 0; if (_args.Incremental) { SvnLogParser logParser = new SvnLogParser(_args.Destination); lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination(); Console.WriteLine("Last revision synched: {0}", lastSyncRevision); } Console.Write("Collecting svn log: "); if (_args.RevisionRange != null) { Console.Write("{0}:{1} ", _args.RevisionRange.StartRevision, _args.RevisionRange.EndRevision); } // fetch the source svn respository and SvnInfo sourceInfo = new SvnInfo(_args.Source); Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot); Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri); string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove( 0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1); Console.WriteLine("Relative path: {0}", sourceRelativePath); if (!string.IsNullOrEmpty(_args.Root)) { sourceRelativePath = _args.Root; Console.WriteLine("Substituting relative path: {0}", sourceRelativePath); } SvnLogArgs logArgs = new SvnLogArgs(); logArgs.StrictNodeHistory = _args.StopOnCopy; logArgs.ThrowOnError = true; logArgs.Range = _args.RevisionRange; logArgs.RetrieveChangedPaths = true; _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog)); Console.WriteLine(); Console.WriteLine("Collected {0} revisions.", _revisions.Count); SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source); foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions) { SvnLogEventArgs revision = revisionPair.Value; if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision) { Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time); continue; } Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time); if (_args.SimulationOnly) { continue; } SvnExportArgs exportArgs = new SvnExportArgs(); exportArgs.Overwrite = true; exportArgs.ThrowOnError = true; exportArgs.Revision = revision.Revision; SvnUpdateResult exportResult = null; _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult); if (revision.ChangedPaths == null) { throw new Exception(string.Format("No changed paths in rev. {0}", revision.Revision)); } SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>(); foreach (SvnChangeItem changeItem in revision.ChangedPaths) { changeItems.Add(changeItem.Path, changeItem); } List <string> filesAdd = new List <string>(); List <string> filesDelete = new List <string>(); List <string> filesModify = new List <string>(); // add files in forward order (add directories first) // delete files in reverse order (delete files first) foreach (SvnChangeItem changeItem in changeItems.Values) { // anything above (outside) of the source path is ignored, we didn't export that if (!changeItem.Path.StartsWith(sourceRelativePath)) { Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path); continue; } string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length); string targetOSPath = targetSvnPath.Replace("/", @"\"); string targetPath = Path.Combine(_args.Destination, targetOSPath); Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path); switch (changeItem.Action) { case SvnChangeAction.Add: case SvnChangeAction.Replace: filesAdd.Add(targetPath); break; case SvnChangeAction.Delete: filesDelete.Insert(0, targetPath); break; case SvnChangeAction.Modify: filesModify.Add(targetPath); break; } } Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision); foreach (string targetPath in filesModify) { Console.WriteLine(" M {0}", targetPath); } foreach (string targetPath in filesAdd) { if (!File.Exists(targetPath)) { throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?", targetPath)); } Console.WriteLine(" A {0}", targetPath); SvnAddArgs svnAddArgs = new SvnAddArgs(); svnAddArgs.ThrowOnError = true; svnAddArgs.Depth = SvnDepth.Empty; _client.Add(targetPath, svnAddArgs); } foreach (string targetPath in filesDelete) { Console.WriteLine(" D {0}", targetPath); SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs(); svnDeleteArgs.ThrowOnError = true; svnDeleteArgs.Force = true; _client.Delete(targetPath, svnDeleteArgs); } SvnCommitArgs commitArgs = new SvnCommitArgs(); commitArgs.LogMessage = revision.LogMessage; commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}", sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString()); commitArgs.ThrowOnError = true; Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination); Console.WriteLine("----------------------------------------------------------------------------"); Console.WriteLine(commitArgs.LogMessage); Console.WriteLine("----------------------------------------------------------------------------"); if (_args.Prompt) { while (true) { Console.Write("Commit? [Y/N] "); char k = Char.ToLower(Console.ReadKey().KeyChar); Console.WriteLine(); if (k == 'y') { break; } if (k == 'n') { throw new Exception("Aborted by user."); } } } SvnCommitResult commitResult = null; _client.Commit(_args.Destination, commitArgs, out commitResult); if (commitResult != null) { Console.WriteLine("Commited revision {0}.", commitResult.Revision); } else { Console.WriteLine("There were no committable changes."); Console.WriteLine("Subversion property changes are not supported."); } } }
/// <summary> /// svn日志 /// </summary> /// <param name="url"></param> /// <param name="startReversion"></param> /// <param name="endReversion"></param> /// <returns></returns> public List <SvnReversionModel> GetLogs(string url, int startReversion, int endReversion) { List <SvnReversionModel> list = new List <SvnReversionModel>(); using (SvnClient client = GetSvnClient()) { Collection <SvnLogEventArgs> logs; SvnInfoEventArgs info; Uri repos = new Uri(url); SvnLogArgs svnLogArgs = null; if (startReversion == 0 && endReversion == 0) { svnLogArgs = new SvnLogArgs(); } else if (startReversion == 0 && endReversion != 0) { svnLogArgs = new SvnLogArgs(new SvnRevisionRange(startReversion, endReversion)); } else if (startReversion != 0 && endReversion == 0) { client.GetInfo(repos, out info); if (startReversion == info.LastChangeRevision) { //没有更新 return(list); } svnLogArgs = new SvnLogArgs(new SvnRevisionRange(startReversion + 1, info.LastChangeRevision)); } else { if (startReversion == endReversion) { //没有更新 return(list); } svnLogArgs = new SvnLogArgs(new SvnRevisionRange(startReversion, endReversion)); } if (client.GetLog(repos, svnLogArgs, out logs)) { foreach (var log in logs) { var reversion = new SvnReversionModel() { Reversion = log.Revision, Author = log.Author, Time = log.Time.AddHours(8), LogMessage = log.LogMessage, PathList = new List <SvnPathMessage>() }; if (log.ChangedPaths != null) { foreach (var path in log.ChangedPaths) { var svnPath = new SvnPathMessage() { Path = path.Path, Action = path.Action.ToString(), Time = reversion.Time, Reversion = log.Revision, Author = log.Author, LogMessage = log.LogMessage }; reversion.PathList.Add(svnPath); } } list.Add(reversion); } } return(list.OrderByDescending(p => p.Time).ToList()); } }
public LogRequest(SvnLogArgs args, EventHandler <SvnLoggingEventArgs> receivedItem) : this(args) { args.Log += ReceiveItem; ReceivedItem += receivedItem; }
private Collection<SvnLogEventArgs> GetSvnRevisions(SvnLogArgs arg) { return GetSvnRevisions(arg, _projectPath); }
public void RepositoryOperation_SetupRepository() { SvnSandBox sbox = new SvnSandBox(this); Uri uri = sbox.CreateRepository(SandBoxRepository.Empty); SvnCommitResult cr; SvnRepositoryOperationArgs oa = new SvnRepositoryOperationArgs(); oa.LogMessage = "Everything in one revision"; using (SvnMultiCommandClient mucc = new SvnMultiCommandClient(uri, oa)) { mucc.CreateDirectory("trunk"); mucc.CreateDirectory("branches"); mucc.CreateDirectory("tags"); mucc.CreateDirectory("trunk/src"); mucc.SetProperty("", "svn:auto-props", "*.cs = svn:eol-style=native"); mucc.SetProperty("", "svn:global-ignores", "bin obj"); mucc.CreateFile("trunk/README", new MemoryStream(Encoding.UTF8.GetBytes("Welcome to this project"))); mucc.SetProperty("trunk/README", "svn:eol-style", "native"); Assert.That(mucc.Commit(out cr)); // Commit r1 Assert.That(cr, Is.Not.Null); } using (SvnClient svn = new SvnClient()) { Collection<SvnListEventArgs> members; svn.GetList(uri, out members); Assert.That(members, Is.Not.Empty); MemoryStream ms = new MemoryStream(); SvnPropertyCollection props; svn.Write(new Uri(uri, "trunk/README"), ms, out props); Assert.That(props, Is.Not.Empty); Assert.That(Encoding.UTF8.GetString(ms.ToArray()), Is.EqualTo("Welcome to this project")); Assert.That(props.Contains("svn:eol-style")); Collection<SvnLogEventArgs> la; SvnLogArgs ll = new SvnLogArgs(); ll.Start = 1; svn.GetLog(uri, ll, out la); Assert.That(la, Is.Not.Empty); Assert.That(la[0].LogMessage, Is.EqualTo("Everything in one revision")); } }
private bool FileWasDeleted(string path, SvnRevisionId changeset) { var revisionId = new RevisionId {Value = changeset.Value.ToString()}; var arg = new SvnLogArgs(CreateSvnRevisionRangeBy(new RevisionRange(revisionId, revisionId))) {BaseUri = new Uri(_root), ThrowOnError = true}; var revisions = GetSvnRevisions(arg, String.Empty); var item = revisions[0].ChangedPaths.FirstOrDefault(itemCollection => itemCollection.Path == path); return item != null && item.Action == SvnChangeAction.Delete; }
public void Commit_CommitWithNonAnsiCharsInLogMessage() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string filepath = Path.Combine(WcPath, "Form.cs"); using (StreamWriter w = new StreamWriter(filepath)) w.Write("Moo"); SvnCommitArgs a = new SvnCommitArgs(); a.LogMessage = " ¥ · £ · € · $ · ¢ · ₡ · ₢ · ₣ · ₤ · ₥ · ₦ · ₧ · ₨ · ₩ · ₪ · ₫ · ₭ · ₮ · ₯"; Assert.That(Client.Commit(WcPath, a)); SvnLogArgs la = new SvnLogArgs(); la.Start = SvnRevision.Head; la.End = SvnRevision.Head; Collection<SvnLogEventArgs> logList; Client.GetLog(WcPath, la, out logList); Assert.That(logList, Is.Not.Null); Assert.That(logList.Count, Is.EqualTo(1)); Assert.That(logList[0].LogMessage, Is.EqualTo(a.LogMessage)); }
private Collection <SvnLogEventArgs> GetSvnRevisions(SvnLogArgs arg) { return(GetSvnRevisions(arg, _projectPath)); }
public void Log_LogCreate() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string WcPath = sbox.Wc; Uri WcUri = new Uri(CollabReposUri, "trunk/"); Client.CheckOut(WcUri, WcPath); string logFile = Path.Combine(WcPath, "LogTestFileBase"); TouchFile(logFile); Client.Add(logFile); SvnCommitArgs a = new SvnCommitArgs(); a.LogMessage = "Commit 1\rWith\nSome\r\nRandom\n\rNewlines\nAdded\n\r\n"; Client.Commit(WcPath, a); File.AppendAllText(logFile, Guid.NewGuid().ToString()); a.LogMessage = "Commit 2"; Client.SetProperty(logFile, "TestProperty", "TestValue"); Client.Commit(WcPath, a); string renamedLogFile = Path.Combine(WcPath, "LogTestFileDest"); Client.Move(logFile, renamedLogFile); a.LogMessage = "Commit 3" + Environment.NewLine + "With newline"; Client.Commit(WcPath, a); int n = 0; SvnLogArgs la = new SvnLogArgs(); la.StrictNodeHistory = false; EventHandler <SvnLogEventArgs> verify = delegate(object sender, SvnLogEventArgs e) { SvnChangeItem ci; SvnChangeItem ci2; Assert.That(e.Author, Is.EqualTo(Environment.UserName)); Assert.That(e.Cancel, Is.False); Assert.That(e.Time, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 5, 0))); Assert.That(e.HasChildren, Is.False); Assert.That(e.RevisionProperties, Is.Not.Null); Assert.That(e.RevisionProperties.Count, Is.GreaterThanOrEqualTo(3)); switch (n) { case 0: Assert.That(e.LogMessage, Is.EqualTo("Commit 3" + Environment.NewLine + "With newline")); Assert.That(e.ChangedPaths, Is.Not.Null); Assert.That(e.ChangedPaths.Count, Is.EqualTo(2)); Assert.That(e.ChangedPaths.Contains("/trunk/LogTestFileBase")); Assert.That(e.ChangedPaths.Contains("/trunk/LogTestFileDest")); ci = e.ChangedPaths["/trunk/LogTestFileBase"]; ci2 = e.ChangedPaths["/trunk/LogTestFileDest"]; Assert.That(ci, Is.Not.Null); Assert.That(ci2, Is.Not.Null); Assert.That(ci.Path, Is.EqualTo("/trunk/LogTestFileBase")); Assert.That(ci.Action, Is.EqualTo(SvnChangeAction.Delete)); Assert.That(ci.CopyFromPath, Is.Null); Assert.That(ci.CopyFromRevision, Is.EqualTo(-1)); Assert.That(ci2.Path, Is.EqualTo("/trunk/LogTestFileDest")); Assert.That(ci2.Action, Is.EqualTo(SvnChangeAction.Add)); Assert.That(ci2.CopyFromPath, Is.EqualTo("/trunk/LogTestFileBase")); Assert.That(ci2.CopyFromRevision, Is.Not.EqualTo(-1)); break; case 1: Assert.That(e.LogMessage, Is.EqualTo("Commit 2")); Assert.That(e.ChangedPaths, Is.Not.Null); Assert.That(e.ChangedPaths.Count, Is.EqualTo(1)); ci = e.ChangedPaths[0]; Assert.That(ci, Is.Not.Null); Assert.That(ci.Path, Is.EqualTo("/trunk/LogTestFileBase")); Assert.That(ci.Action, Is.EqualTo(SvnChangeAction.Modify)); Assert.That(ci.CopyFromPath, Is.Null); Assert.That(ci.CopyFromRevision, Is.EqualTo(-1)); break; case 2: Assert.That(e.LogMessage, Is.EqualTo("Commit 1" + Environment.NewLine + "With" + Environment.NewLine + "Some" + Environment.NewLine + "Random" + Environment.NewLine + "Newlines" + Environment.NewLine + "Added" + Environment.NewLine + Environment.NewLine)); Assert.That(e.ChangedPaths, Is.Not.Null); Assert.That(e.ChangedPaths.Count, Is.EqualTo(1)); ci = e.ChangedPaths[0]; Assert.That(ci, Is.Not.Null); Assert.That(ci.Path, Is.EqualTo("/trunk/LogTestFileBase")); Assert.That(ci.Action, Is.EqualTo(SvnChangeAction.Add)); Assert.That(ci.CopyFromPath, Is.Null); Assert.That(ci.CopyFromRevision, Is.EqualTo(-1)); break; default: Assert.That(false); break; } n++; }; Client.Log(new Uri(WcUri, "LogTestFileDest"), verify); Assert.That(n, Is.EqualTo(3)); n = 0; Client.Log(Path.Combine(WcPath, "LogTestFileDest"), verify); Assert.That(n, Is.EqualTo(3)); }
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; }
private static void GetLogs(bool console_mode, string application_path, string repository_location, long last_revision, Output_Type output_type) { SvnTarget repository; SvnClient client = new SvnClient(); long current_revision = -1; if (SvnTarget.TryParse(repository_location, out repository) == true) { try { SvnInfoEventArgs info; client.GetInfo(new Uri(repository_location), out info); current_revision = info.Revision; } catch (Exception ex) { Debug.WriteLine(ex.Message); if (console_mode == true) { Console.WriteLine(ex.Message); } } if (last_revision < current_revision) { DataTable datatable = new DataTable("log"); datatable.Columns.Add("Revision", typeof(long)); datatable.Columns.Add("Author", typeof(string)); datatable.Columns.Add("Time", typeof(DateTime)); datatable.Columns.Add("ChangedPaths", typeof(string)); datatable.Columns.Add("LogMessage", typeof(string)); try { System.Collections.ObjectModel.Collection<SvnLogEventArgs> logitems = new System.Collections.ObjectModel.Collection<SvnLogEventArgs>(); SvnLogArgs logargs = new SvnLogArgs(new SvnRevisionRange(current_revision, last_revision + 1)); client.GetLog(new Uri(repository_location), logargs, out logitems); datatable.BeginLoadData(); foreach (SvnLogEventArgs logitem in logitems) { StringBuilder ChangedPaths = new StringBuilder(); if (logitem.ChangedPaths != null) { foreach (SvnChangeItem path in logitem.ChangedPaths) { ChangedPaths.AppendFormat("{1} {2}{0}", Environment.NewLine, path.Action, path.Path); if (path.CopyFromRevision != -1) { ChangedPaths.AppendFormat("{1} -> {2}{0}", Environment.NewLine, path.CopyFromPath, path.CopyFromRevision); } } } DataRow datarow = datatable.NewRow(); datarow["Revision"] = logitem.Revision; datarow["Author"] = logitem.Author; datarow["Time"] = logitem.Time.ToLocalTime(); datarow["ChangedPaths"] = ChangedPaths.ToString(); datarow["LogMessage"] = logitem.LogMessage; datatable.Rows.Add(datarow); } datatable.EndLoadData(); datatable.AcceptChanges(); switch (output_type) { case Output_Type.Console: OutputToConsole(console_mode, application_path, datatable); break; case Output_Type.Txt: OutputToTxt(console_mode, application_path, datatable); break; case Output_Type.XML: OutputToXML(console_mode, application_path, datatable); break; case Output_Type.XMLTransform: OutputToXMLTransform(console_mode, application_path, datatable); break; case Output_Type.RSS: OutputToRSS(console_mode, application_path, datatable); break; default: break; } last_revision = Convert.ToInt32(datatable.Compute("max(Revision)", string.Empty)); System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings.Remove("last_revision"); config.AppSettings.Settings.Add("last_revision", last_revision.ToString()); config.Save(); } catch (Exception ex) { Debug.WriteLine(ex.Message); if (console_mode == true) { Console.WriteLine(ex.Message); } } } client.Dispose(); } else { Debug.WriteLine("Unable to connect to repository"); if (console_mode == true) { Console.WriteLine("Unable to connect to repository"); } } }
public void Commit_SetCustomProps() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string WcPath = sbox.Wc; string fp = Path.Combine(WcPath, "NewFile.cs"); Touch2(fp); Client.Add(fp); SvnCommitArgs ca = new SvnCommitArgs(); ca.LogMessage = "Committed extra"; ca.LogProperties.Add("my:prop", "PropValue"); ca.RunTortoiseHooks = true; SvnCommitResult cr; Client.Commit(WcPath, ca, out cr); string value; Client.GetRevisionProperty(sbox.RepositoryUri, cr.Revision, "my:prop", out value); Assert.That(value, Is.EqualTo("PropValue")); SvnLogArgs la = new SvnLogArgs(); la.RetrieveProperties.Add("my:prop"); la.Start = la.End = cr.Revision; Collection<SvnLogEventArgs> lc; Client.GetLog(WcPath, la, out lc); Assert.That(lc.Count, Is.EqualTo(1)); Assert.That(lc[0].RevisionProperties.Contains("my:prop")); SvnLogEventArgs l = lc[0]; Assert.That(l.RevisionProperties["my:prop"].StringValue, Is.EqualTo("PropValue")); Assert.That(l.Author, Is.EqualTo(Environment.UserName)); }
public static ICollection<SvnLogEventArgs> GetLogSince(string repositoryUri, string target, long revision) { var svnLogArgs = new SvnLogArgs { StrictNodeHistory = true, End = revision, BaseUri = new Uri(repositoryUri) }; Collection<SvnLogEventArgs> logItems; using (var svnClient = new SvnClient()) { if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri, target), svnLogArgs, out logItems)) { logItems = new Collection<SvnLogEventArgs>(); } } return logItems; }
public void Log_MultiLogs() { bool touched = false; Assert.That(Client.Log(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/"), delegate(object sender, SvnLogEventArgs e) { touched = true; e.Cancel = true; Assert.That(e.MergeLogNestingLevel, Is.EqualTo(0)); Assert.That(e.Revision, Is.GreaterThan(20000L)); Assert.That(e.LogMessage, Is.Not.Null); Assert.That(e.Time, Is.GreaterThan(new DateTime(2008, 01, 01))); Assert.That(e.Author, Is.Not.Null); Assert.That(e.ChangedPaths, Is.Not.Null); Assert.That(e.LogOrigin, Is.Null); }), Is.False); Assert.That(touched); List <Uri> uris = new List <Uri>(); long rev = 0; Assert.That(Client.Log(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/"), delegate(object sender, SvnLogEventArgs e) { foreach (SvnChangeItem item in e.ChangedPaths) { Uri uri = new Uri(new Uri("http://svn.collab.net/repos/asf/"), item.Path.TrimStart('/')); if (item.Action == SvnChangeAction.Delete) { uris.Remove(uri); } else if (item.Action == SvnChangeAction.Add || item.Action == SvnChangeAction.Modify) { uris.Add(uri); } } if (uris.Count > 10) { e.Cancel = true; rev = e.Revision - 1; } }), Is.False); Assert.That(uris.Count, Is.GreaterThan(10)); uris.Clear(); uris.Add(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/README")); uris.Add(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/INSTALL")); SvnLogArgs args = new SvnLogArgs(); args.Start = 863074; args.End = 859074; args.Limit = 100; args.OperationalRevision = 863074; touched = false; Client.Log(uris, args, delegate(object sender, SvnLogEventArgs e) { Assert.That(e.LogOrigin, Is.Not.Null); touched = true; }); Assert.That(touched); }
public static SvnLogEventArgs GetInitialLogItem(string repositoryUri, string target) { var svnLogArgs = new SvnLogArgs { StrictNodeHistory = true, BaseUri = new Uri(repositoryUri), Start = SvnRevision.Zero, End = SvnRevision.Head, Limit = 1 }; Collection<SvnLogEventArgs> logItems; using (var svnClient = new SvnClient()) { if (!svnClient.GetLog(new Uri(svnLogArgs.BaseUri, target), svnLogArgs, out logItems)) { logItems = new Collection<SvnLogEventArgs>(); } } var logItem = logItems.SingleOrDefault(); return logItem; }
public void Authentication_TestSimpleProvider() { Client.Authentication.Clear(); bool arrived = false; SvnLogArgs a = new SvnLogArgs(); a.Limit = 1; Assert.That(Client.Log(new Uri("svn://svn.tartarus.org/sgt/putty-0.60/misc.c"), delegate(object sender, SvnLogEventArgs e) { arrived = true; })); Assert.That(arrived); arrived = false; Assert.That(Client.Info(new Uri("http://svn.apache.org/repos/asf/subversion/trunk/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); arrived = false; Client.Authentication.SslServerTrustHandlers += new EventHandler<SvnSslServerTrustEventArgs>(Authenticator_SslServerTrustHandlersAllow); Assert.That(Client.List(new Uri("https://svn.apache.org/repos/asf/apr/"), delegate(object sender, SvnListEventArgs e) { arrived = true; })); Assert.That(arrived); SvnClient cl2 = new SvnClient(); cl2.Authentication.CopyAuthenticationCache(Client); cl2.Authentication.ClearAuthenticationCache(); }
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); }
public SpecificationRequest(Specification<Changeset> specification, SvnLogArgs svnLogArgs) { Specification = specification; SvnLogArgs = svnLogArgs; }
public override IEnumerable<SvnRevision> Log (Repository repo, FilePath path, SvnRevision revisionStart, SvnRevision revisionEnd) { var list = new List<SvnRevision> (); var args = new SvnLogArgs { Range = new SvnRevisionRange (GetRevision (revisionStart), GetRevision (revisionEnd)), }; lock (client) client.Log (path, args, (o, a) => list.Add (new SvnRevision (repo, (int)a.Revision, a.Time, a.Author, a.LogMessage, a.ChangedPaths == null ? new RevisionPath[0] : a.ChangedPaths.Select (item => new RevisionPath (item.Path, ConvertRevisionAction (item.Action), "")).ToArray ()))); return list; }