public Task<string> CreatePatchAsync(SubversionArguments arguments) { return Task.Run(() => { Thread.Sleep(3000); return @"C:\test.diff"; }); }
public static Task<string> GetMessageForRevision(SubversionArguments svnArguments) { return Task.Run(() => { Thread.Sleep(3000); return string.Format("Test commit message for revision range {0} - {1}. Fixed bug #313.", svnArguments.RevisionFrom, svnArguments.RevisionTo); }); }
public GollumForm(ProjectSettings projectSettings, SubversionArguments subversionArguments) { InitializeComponent(); using (var graphics = CreateGraphics()) { _dpiX = graphics.DpiX; _dpiY = graphics.DpiY; } _projectSettings = projectSettings; _subversionArguments = subversionArguments; _bugMatcher = new Regex(@"(?<=(fixed bug #)|(fix for bug #)|(fixed bug )|(fix for bug ))\s?\d+", RegexOptions.Compiled | RegexOptions.IgnoreCase); ToggleBugzillaVisibility(false); }
public static async Task<string> GetMessageForRevision(SubversionArguments svnArguments) { string arguments = String.Format("log -r{0} --xml", svnArguments.RevisionTo); string output = await GetProcessOutputAsync("svn", arguments, svnArguments.Cwd).ConfigureAwait(false); // XML, because of enterprise! var xml = new XmlDocument(); xml.LoadXml(output); var node = xml.SelectSingleNode("log/logentry/msg"); if (node == null || node.FirstChild == null || node.FirstChild.Value == null) { throw new Exception("SVN error: No such revision!"); } return node.FirstChild.Value; }
public static async Task <string> GetMessageForRevision(SubversionArguments svnArguments) { string arguments = String.Format("log -r{0} --xml", svnArguments.RevisionTo); string output = await GetProcessOutputAsync("svn", arguments, svnArguments.Cwd).ConfigureAwait(false); // XML, because of enterprise! var xml = new XmlDocument(); xml.LoadXml(output); var node = xml.SelectSingleNode("log/logentry/msg"); if (node == null || node.FirstChild == null || node.FirstChild.Value == null) { throw new Exception("SVN error: No such revision!"); } return(node.FirstChild.Value); }
/// <summary> /// Creates the patch. /// </summary> /// <param name="svnArguments">The SVN arguments.</param> /// <returns> /// A task that represents the asynchronous patch operation. /// The value of the Result property contains the file path of created patch file. /// </returns> /// <exception cref="ArgumentException"> /// Thrown when revision from is greater than or equal to revision to /// </exception> /// <exception cref="InvalidOperationException"> /// Failed to start SVN process or could not get process output. /// </exception> public async Task <string> CreatePatchAsync(SubversionArguments svnArguments) { if (svnArguments.RevisionFrom >= svnArguments.RevisionTo) { throw new ArgumentException("SVN error: RevisionFrom must be less than RevisionTo!"); } string arguments = String.Format("diff -r {0}:{1}", svnArguments.RevisionFrom, svnArguments.RevisionTo); string patchFilePath = null; try { string output = await GetProcessOutputAsync("svn", arguments, svnArguments.Cwd).ConfigureAwait(false); patchFilePath = Path.GetTempFileName().Replace(".tmp", ".patch"); // Save output to file using (var tw = new StreamWriter(patchFilePath, false, Encoding.UTF8)) { tw.Write(output); } return(patchFilePath); } catch (InvalidOperationException) { if (patchFilePath != null) { File.Delete(patchFilePath); } throw; } catch (Exception ex) { if (patchFilePath != null) { File.Delete(patchFilePath); } throw new InvalidOperationException("An error occurred SVN process: " + ex.Message, ex); } }
/// <summary> /// Creates the patch. /// </summary> /// <param name="svnArguments">The SVN arguments.</param> /// <returns> /// A task that represents the asynchronous patch operation. /// The value of the Result property contains the file path of created patch file. /// </returns> /// <exception cref="ArgumentException"> /// Thrown when revision from is greater than or equal to revision to /// </exception> /// <exception cref="InvalidOperationException"> /// Failed to start SVN process or could not get process output. /// </exception> public async Task<string> CreatePatchAsync(SubversionArguments svnArguments) { if (svnArguments.RevisionFrom >= svnArguments.RevisionTo) { throw new ArgumentException("SVN error: RevisionFrom must be less than RevisionTo!"); } string arguments = String.Format("diff -r {0}:{1}", svnArguments.RevisionFrom, svnArguments.RevisionTo); string patchFilePath = null; try { string output = await GetProcessOutputAsync("svn", arguments, svnArguments.Cwd).ConfigureAwait(false); patchFilePath = Path.GetTempFileName().Replace(".tmp", ".patch"); // Save output to file using (var tw = new StreamWriter(patchFilePath, false, Encoding.UTF8)) { tw.Write(output); } return patchFilePath; } catch (InvalidOperationException) { if (patchFilePath != null) { File.Delete(patchFilePath); } throw; } catch (Exception ex) { if (patchFilePath != null) { File.Delete(patchFilePath); } throw new InvalidOperationException("An error occurred SVN process: " + ex.Message, ex); } }
private async void ButtonGoClick(object sender, EventArgs e) { int revisionTo; int revisionFrom = -1; if (string.IsNullOrWhiteSpace(textBoxProjectDirectory.Text) || !Directory.Exists(textBoxProjectDirectory.Text) || string.IsNullOrWhiteSpace(textBoxRevisionTo.Text) || !int.TryParse(textBoxRevisionTo.Text, out revisionTo) || (!string.IsNullOrWhiteSpace(textBoxRevisionFrom.Text) && !int.TryParse(textBoxRevisionFrom.Text, out revisionFrom)) || revisionFrom >= revisionTo ) { MessageBox.Show("Fill fields better"); return; } var cwd = textBoxProjectDirectory.Text; #if !TEST string projectRootDirectory; try { projectRootDirectory = Program.FindProjectRootDirectory(cwd, ProjectSettings.DefaultFileName); } catch { MessageBox.Show("Directory not gollum-compatible."); return; } #else const string projectRootDirectory = "C:\\"; #endif var subversionArguments = new SubversionArguments { RevisionTo = revisionTo, RevisionFrom = revisionFrom, Cwd = cwd, LocalProjectRootDirectory = projectRootDirectory }; buttonGo.Enabled = false; try { #if TEST subversionArguments.Message = await DummyPatchCreator.GetMessageForRevision(subversionArguments); ProjectSettings = new ProjectSettings { RepositoryBasePath = "/trunk", ReviewBoardGroup = "Ware", ReviewBoardRepositoryName = "Ware" }; #else subversionArguments.Message = await SvnPatchCreator.GetMessageForRevision(subversionArguments); ProjectSettings = ProjectSettings.Load(Path.Combine(subversionArguments.LocalProjectRootDirectory, ProjectSettings.DefaultFileName)); #endif SubversionArguments = subversionArguments; } catch (Exception ex) { MessageBox.Show("Unable to get message for revision: " + ex.Message); buttonGo.Enabled = true; return; } DialogResult = DialogResult.OK; Close(); }
private static ProjectSettings LoadProjectSettings(SubversionArguments subversionArguments) { return ProjectSettings.Load(Path.Combine(subversionArguments.LocalProjectRootDirectory, ProjectSettings.DefaultFileName)); }
private static SubversionArguments ReadCommandLineArguments(string[] args) { if (args.Length < 2 || args.Length > 3) { ShowHelp(); return null; } int revision; if (!int.TryParse(args[1], out revision)) { ShowHelp(); Console.Error.WriteLine("Revision must be integer"); return null; } string cwd = Directory.GetCurrentDirectory(); if (args.Length == 3) { cwd = args[2]; if (!Directory.Exists(cwd)) { ShowHelp(); Console.Error.WriteLine("Cwd doesn't exist"); return null; } } var svnArgs = new SubversionArguments { RevisionTo = revision, Cwd = cwd, LocalProjectRootDirectory = FindProjectRootDirectory(cwd, ProjectSettings.DefaultFileName) }; try { #if TEST svnArgs.Message = DummyPatchCreator.GetMessageForRevision(svnArgs).Result; #else svnArgs.Message = SvnPatchCreator.GetMessageForRevision(svnArgs).Result; #endif } catch (Exception ex) { Console.Error.WriteLine("Unable to get message for revision: " + ex.Message); return null; } return svnArgs; }