diff options
author | Therzok <teromario@yahoo.com> | 2013-08-23 19:04:18 +0400 |
---|---|---|
committer | Therzok <teromario@yahoo.com> | 2013-08-23 19:04:18 +0400 |
commit | c7e3b6c2918a3da14b82e057c6070bbbbc449b4a (patch) | |
tree | 75c53216b3cfebb479b22e681d9a02c74b180555 /main/src | |
parent | c52dd734abd5c20756042b4d9e3c59f3790b3272 (diff) |
[Subversion] Implemented Progress Monitoring for Subversion commands.
TODO: Prettify text output and make progress bar indefinite.
Diffstat (limited to 'main/src')
3 files changed, 96 insertions, 16 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/LibSvnClient.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/LibSvnClient.cs index 2aac8e2843..28ff02b3cb 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/LibSvnClient.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/LibSvnClient.cs @@ -681,7 +681,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix { public delegate IntPtr svn_client_blame_receiver_t (IntPtr baton, Int64 line_no, svn_revnum_t revision, string author, string date, string line, IntPtr pool); - public delegate void svn_ra_progress_notify_func_t (off_t progress, off_t total, off_t baton, IntPtr pool); + public delegate void svn_ra_progress_notify_func_t (off_t progress, off_t total, IntPtr baton, IntPtr pool); public delegate IntPtr svn_wc_conflict_resolver_func_t (out IntPtr result, IntPtr description, IntPtr baton, IntPtr pool); diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/SvnClient.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/SvnClient.cs index b29ab1fd2f..30f1352700 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/SvnClient.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Subversion.Unix/MonoDevelop.VersionControl.Subversion.Unix/SvnClient.cs @@ -9,7 +9,9 @@ using System.Text; using svn_revnum_t = System.IntPtr; using size_t = System.Int32; +using off_t = System.Int64; using MonoDevelop.Projects.Text; +using System.Timers; namespace MonoDevelop.VersionControl.Subversion.Unix { @@ -105,9 +107,9 @@ namespace MonoDevelop.VersionControl.Subversion.Unix int newv = oldVersion; if (File.Exists (file)) { string txt = File.ReadAllText (file); - if (txt.IndexOf ("libapr-0") != -1 && oldVersion != 0) + if (txt.IndexOf ("libapr-0", StringComparison.Ordinal) != -1 && oldVersion != 0) newv = 0; - if (txt.IndexOf ("libapr-1") != -1 && oldVersion != 1) + if (txt.IndexOf ("libapr-1", StringComparison.Ordinal) != -1 && oldVersion != 1) newv = 1; } return newv; @@ -208,6 +210,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix LibSvnClient.NotifyLockState requiredLockState; // retain this so the delegates aren't GC'ed + LibSvnClient.svn_ra_progress_notify_func_t progress_func; LibSvnClient.svn_wc_notify_func2_t notify_func; LibSvnClient.svn_client_get_commit_log_t log_func; IntPtr config_hash; @@ -224,7 +227,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix public UnixSvnBackend () { - pre_1_7 = GetVersion ().StartsWith ("1.6"); + pre_1_7 = GetVersion ().StartsWith ("1.6", StringComparison.Ordinal); // Allocate the APR pool and the SVN client context. pool = newpool (IntPtr.Zero); @@ -246,7 +249,11 @@ namespace MonoDevelop.VersionControl.Subversion.Unix Marshal.WriteIntPtr (ctx, (int) Marshal.OffsetOf (typeof (LibSvnClient.svn_client_ctx_t), "LogMsgFunc"), Marshal.GetFunctionPointerForDelegate (log_func)); - + progress_func = new LibSvnClient.svn_ra_progress_notify_func_t (svn_ra_progress_notify_func_t_impl); + Marshal.WriteIntPtr (ctx, + (int) Marshal.OffsetOf (typeof (LibSvnClient.svn_client_ctx_t), "progress_func"), + Marshal.GetFunctionPointerForDelegate (progress_func)); + // Load user and system configuration svn.config_get_config (ref config_hash, null, pool); Marshal.WriteIntPtr (ctx, @@ -930,7 +937,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix string npath1 = NormalizePath (path1, localpool); string npath2 = NormalizePath (path2, localpool); CheckError (svn.client_diff (options, npath1, ref revision1, npath2, ref revision2, recursive, false, true, outfile, errfile, ctx, localpool)); - return MonoDevelop.Projects.Text.TextFile.ReadFile (fout).Text; + return TextFile.ReadFile (fout).Text; } else { throw new Exception ("Could not get diff information"); } @@ -1056,7 +1063,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix hash_item = apr.hash_next (hash_item); } props_str = props.ToString (); - index = props_str.IndexOf (Path.GetFileName (new_path) + Environment.NewLine); + index = props_str.IndexOf (Path.GetFileName (new_path) + Environment.NewLine, StringComparison.Ordinal); props_str = (index < 0) ? props_str : props_str.Remove (index, Path.GetFileName(new_path).Length+1); new_props = new LibSvnClient.svn_string_t (); @@ -1102,6 +1109,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix throw new SubversionException ("Another Subversion operation is already in progress."); inProgress = true; updatemonitor = monitor; + progressData = new ProgressData (); return newpool (pool); } } @@ -1116,7 +1124,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix } } - private VersionInfo CreateNode (LibSvnClient.StatusEnt ent, Repository repo) + static VersionInfo CreateNode (LibSvnClient.StatusEnt ent, Repository repo) { VersionStatus rs = VersionStatus.Unversioned; Revision rr = null; @@ -1146,7 +1154,7 @@ namespace MonoDevelop.VersionControl.Subversion.Unix return ret; } - private VersionStatus ConvertStatus (LibSvnClient.NodeSchedule schedule, LibSvnClient.svn_wc_status_kind status) { + static VersionStatus ConvertStatus (LibSvnClient.NodeSchedule schedule, LibSvnClient.svn_wc_status_kind status) { switch (schedule) { case LibSvnClient.NodeSchedule.Add: return VersionStatus.Versioned | VersionStatus.ScheduledAdd; case LibSvnClient.NodeSchedule.Delete: return VersionStatus.Versioned | VersionStatus.ScheduledDelete; @@ -1175,10 +1183,42 @@ namespace MonoDevelop.VersionControl.Subversion.Unix { if (string.IsNullOrEmpty (mimeType)) return false; - return !(mimeType.StartsWith ("text/") || + return !(mimeType.StartsWith ("text/", StringComparison.Ordinal) || mimeType == "image/x-xbitmap" || mimeType == "image/x-xpixmap"); } + + class ProgressData + { + public int Bytes; + public Timer LogTimer = new Timer (); + public int Seconds; + } + + ProgressData progressData; + void svn_ra_progress_notify_func_t_impl (off_t progress, off_t total, IntPtr baton, IntPtr pool) + { + if (updatemonitor == null) + return; + + int currentProgress = (int)progress; + int totalProgress = (int)total; + if (totalProgress != -1 && currentProgress >= totalProgress) { + progressData.LogTimer.Close (); + return; + } + + progressData.Bytes = currentProgress; + if (progressData.LogTimer.Enabled) + return; + + progressData.LogTimer.Interval = 1000; + progressData.LogTimer.Elapsed += delegate (object sender, ElapsedEventArgs eea) { + progressData.Seconds += 1; + updatemonitor.Log.WriteLine ("{0} bytes in {1} seconds", progressData.Bytes, progressData.Seconds); + }; + progressData.LogTimer.Start (); + } struct notify_baton { public bool received_some_change; diff --git a/main/src/addins/VersionControl/Subversion.Win32/SvnSharpClient.cs b/main/src/addins/VersionControl/Subversion.Win32/SvnSharpClient.cs index 7e63a392b3..f0de966632 100644 --- a/main/src/addins/VersionControl/Subversion.Win32/SvnSharpClient.cs +++ b/main/src/addins/VersionControl/Subversion.Win32/SvnSharpClient.cs @@ -9,6 +9,7 @@ using SharpSvn.Security; using SvnRevision = MonoDevelop.VersionControl.Subversion.SvnRevision;
using MonoDevelop.Ide;
using MonoDevelop.Projects.Text;
+using System.Timers;
namespace SubversionAddinWindows
{
@@ -77,6 +78,8 @@ namespace SubversionAddinWindows public class SvnSharpBackend: SubversionBackend
{
SvnClient client;
+ IProgressMonitor updateMonitor;
+ ProgressData progressData;
public override string GetTextBase (string file)
{
@@ -109,6 +112,9 @@ namespace SubversionAddinWindows client.Authentication.SslServerTrustHandlers += new EventHandler<SvnSslServerTrustEventArgs> (AuthenticationSslServerTrustHandlers);
client.Authentication.UserNameHandlers += new EventHandler<SvnUserNameEventArgs> (AuthenticationUserNameHandlers);
client.Authentication.UserNamePasswordHandlers += new EventHandler<SvnUserNamePasswordEventArgs> (AuthenticationUserNamePasswordHandlers);
+ client.Progress += delegate (object sender, SvnProgressEventArgs e) {
+ ProgressWork (e, progressData, updateMonitor);
+ };
}
void AuthenticationUserNamePasswordHandlers (object sender, SvnUserNamePasswordEventArgs e)
@@ -217,7 +223,7 @@ namespace SubversionAddinWindows // Redo path link.
repositoryPath = repositoryPath.TrimStart (new char[] { '/' });
foreach (var segment in target.Uri.Segments) {
- if (repositoryPath.StartsWith (segment))
+ if (repositoryPath.StartsWith (segment, StringComparison.Ordinal))
repositoryPath = repositoryPath.Remove (0, segment.Length);
}
@@ -294,7 +300,7 @@ namespace SubversionAddinWindows return list;
}
- private RevisionAction ConvertRevisionAction (SvnChangeAction svnChangeAction)
+ static RevisionAction ConvertRevisionAction (SvnChangeAction svnChangeAction)
{
switch (svnChangeAction) {
case SvnChangeAction.Add: return RevisionAction.Add;
@@ -394,7 +400,7 @@ namespace SubversionAddinWindows return list;
}
- VersionInfo CreateVersionInfo (Repository repo, SvnStatusEventArgs ent)
+ static VersionInfo CreateVersionInfo (Repository repo, SvnStatusEventArgs ent)
{
VersionStatus rs = VersionStatus.Unversioned;
Revision rr = null;
@@ -434,7 +440,7 @@ namespace SubversionAddinWindows return ret;
}
- private VersionStatus ConvertStatus (SvnSchedule schedule, SvnStatus status)
+ static VersionStatus ConvertStatus (SvnSchedule schedule, SvnStatus status)
{
switch (schedule) {
case SvnSchedule.Add: return VersionStatus.Versioned | VersionStatus.ScheduledAdd;
@@ -504,7 +510,7 @@ namespace SubversionAddinWindows lock (client) {
foreach (var path in paths) {
if (client.GetProperty (new SvnPathTarget (path.ParentDirectory), SvnPropertyNames.SvnIgnore, out result)) {
- int index = result.IndexOf (path.FileName + Environment.NewLine);
+ int index = result.IndexOf (path.FileName + Environment.NewLine, StringComparison.Ordinal);
result = (index < 0) ? result : result.Remove (index, path.FileName.Length+Environment.NewLine.Length);
client.SetProperty (path.ParentDirectory, SvnPropertyNames.SvnIgnore, result);
}
@@ -585,9 +591,17 @@ namespace SubversionAddinWindows public bool SendingData;
}
+ class ProgressData
+ {
+ public int Bytes;
+ public Timer LogTimer = new Timer ();
+ public int Seconds;
+ }
+
void BindMonitor (SvnClientArgs args, IProgressMonitor monitor)
{
NotifData data = new NotifData ();
+ progressData = new ProgressData ();
args.Notify += delegate (object o, SvnNotifyEventArgs e) {
Notify (e, data, monitor);
@@ -598,9 +612,35 @@ namespace SubversionAddinWindows args.SvnError += delegate (object o, SvnErrorEventArgs a) {
monitor.ReportError (a.Exception.Message, a.Exception.RootCause);
};
+
+ updateMonitor = monitor;
+ }
+
+ static void ProgressWork (SvnProgressEventArgs e, ProgressData data, IProgressMonitor monitor)
+ {
+ if (monitor == null)
+ return;
+
+ int currentProgress = (int)e.Progress;
+ int totalProgress = (int)e.TotalProgress;
+ if (totalProgress != -1 && currentProgress >= totalProgress) {
+ data.LogTimer.Close ();
+ return;
+ }
+
+ data.Bytes = currentProgress;
+ if (data.LogTimer.Enabled)
+ return;
+
+ data.LogTimer.Interval = 1000;
+ data.LogTimer.Elapsed += delegate (object sender, ElapsedEventArgs eea) {
+ data.Seconds += 1;
+ monitor.Log.WriteLine ("{0} bytes in {1} seconds", data.Bytes, data.Seconds);
+ };
+ data.LogTimer.Start ();
}
- void Notify (SvnNotifyEventArgs e, NotifData notifData, IProgressMonitor monitor)
+ static void Notify (SvnNotifyEventArgs e, NotifData notifData, IProgressMonitor monitor)
{
string actiondesc;
string file = e.Path;
|