public static SplitIntoLines ( string output ) : string[] | ||
output | string | /// The output from the Mercurial command string to split into separate line strings. /// |
Résultat | string[] |
/// <summary> /// This method should parse and store the appropriate execution result output /// according to the type of data the command line client would return for /// the command. /// </summary> /// <param name="exitCode"> /// The exit code from executing the command line client. /// </param> /// <param name="standardOutput"> /// The standard output from executing the command line client. /// </param> /// <exception cref="MercurialResultParsingException"> /// Unable to parse one or more of the lines of output from the 'hg resolve --list' command /// </exception> protected override void ParseStandardOutputForResults(int exitCode, string standardOutput) { if (exitCode != 0 || Action != ResolveAction.List) { return; } var resolutionRegex = new Regex(@"^(?<state>[UR])\s(?<file>.*)$", RegexOptions.IgnoreCase); string[] lines = OutputParsingUtilities.SplitIntoLines(standardOutput); var result = new List <MergeConflict>(); foreach (Match resolutionMatch in lines.Select(line => resolutionRegex.Match(line))) { if (!resolutionMatch.Success) { throw new MercurialResultParsingException(exitCode, "Unable to parse one or more of the lines of output from the 'hg resolve --list' command", standardOutput); } result.Add(new MergeConflict( resolutionMatch.Groups["file"].Value, resolutionMatch.Groups["state"].Value == "R" ? MergeConflictState.Resolved : MergeConflictState.Unresolved)); } Result = result; }
/// <summary> /// Parses the standard output from executing a 'hg summary' command /// and returns a <see cref="RepositorySummary"/>. /// </summary> /// <param name="standardOutput"> /// The standard output from a 'hg summary' command that is to be parsed. /// </param> /// <returns> /// The resulting <see cref="RepositorySummary"/> from parsing <paramref name="standardOutput"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <para><paramref name="standardOutput"/> is <c>null</c>.</para> /// </exception> public static RepositorySummary Parse(string standardOutput) { if (standardOutput == null) { throw new ArgumentNullException("standardOutput"); } var parsers = new List <KeyValuePair <Regex, Action <RepositorySummary, string, Match> > > { new KeyValuePair <Regex, Action <RepositorySummary, string, Match> >( new Regex(@"^parent:\s(?<revnum>-?\d+):[a-f0-9]+\s+.*$", RegexOptions.IgnoreCase), ParseParents), new KeyValuePair <Regex, Action <RepositorySummary, string, Match> >( new Regex(@"^branch:\s(?<name>.*)$", RegexOptions.IgnoreCase), ParseBranch), new KeyValuePair <Regex, Action <RepositorySummary, string, Match> >( new Regex(@"^update:\s((?<new>\d+)\snew changesets? \(update\))$", RegexOptions.IgnoreCase), ParseUpdate), new KeyValuePair <Regex, Action <RepositorySummary, string, Match> >( new Regex(@"^commit:\s((?<modified>\d+) modified(, )?)?((?<unknown>\d+) unknown(, )?)?((?<unresolved>\d+) unresolved(, )?)?(?<inmerge> \(merge\))?( ?\(clean\))?$", RegexOptions.IgnoreCase), ParseCommit) }; var summary = new RepositorySummary { RawOutput = standardOutput }; foreach (string line in OutputParsingUtilities.SplitIntoLines(standardOutput)) { foreach (var parser in parsers) { Match ma = parser.Key.Match(line); if (!ma.Success) { continue; } parser.Value(summary, line, ma); } } return(summary); }
/// <summary> /// This method should parse and store the appropriate execution result output /// according to the type of data the command line client would return for /// the command. /// </summary> /// <param name="exitCode"> /// The exit code from executing the command line client. /// </param> /// <param name="standardOutput"> /// The standard output from executing the command line client. /// </param> /// <exception cref="MercurialResultParsingException"> /// <para><paramref name="standardOutput"/> contains output with invalid/unknown format.</para> /// </exception> protected override void ParseStandardOutputForResults(int exitCode, string standardOutput) { string[] lines = OutputParsingUtilities.SplitIntoLines(standardOutput); var re = new Regex(@"^(?<name>.*)\s+(?<revno>-?\d+):[a-f0-9]+(\s+\(inactive\))?$", RegexOptions.IgnoreCase); var branchHeads = new List <BranchHead>(); foreach (Match ma in lines.Where(l => !StringEx.IsNullOrWhiteSpace(l)).Select(line => re.Match(line))) { if (!ma.Success) { throw new MercurialResultParsingException(exitCode, "Unable to parse output from the branches command", standardOutput); } branchHeads.Add(new BranchHead( int.Parse(ma.Groups["revno"].Value, CultureInfo.InvariantCulture), ma.Groups["name"].Value.Trim())); } Result = branchHeads.OrderBy(b => b.Name).ToArray(); }
/// <summary> /// This method should parse and store the appropriate execution result output /// according to the type of data the command line client would return for /// the command. /// </summary> /// <param name="exitCode"> /// The exit code from executing the command line client. /// </param> /// <param name="standardOutput"> /// The standard output from executing the command line client. /// </param> protected override void ParseStandardOutputForResults(int exitCode, string standardOutput) { base.ParseStandardOutputForResults(exitCode, standardOutput); Result = OutputParsingUtilities.SplitIntoLines(standardOutput); }