This class contains a summary of the repository state, as returned by the SummaryCommand.
        /// <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;
        }
Beispiel #2
0
 /// <summary>
 /// Parses the <c>commit: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseCommit(RepositorySummary summary, string line, Match match)
 {
     if (match.Groups["modified"].Success)
     {
         summary.NumberOfModifiedFiles = int.Parse(match.Groups["modified"].Value, CultureInfo.InvariantCulture);
     }
     if (match.Groups["unknown"].Success)
     {
         summary.NumberOfUnknownFiles = int.Parse(match.Groups["unknown"].Value, CultureInfo.InvariantCulture);
     }
     if (match.Groups["unresolved"].Success)
     {
         summary.NumberOfUnresolvedFiles = int.Parse(match.Groups["unresolved"].Value, CultureInfo.InvariantCulture);
     }
     summary.IsInMerge = match.Groups["inmerge"].Success;
 }
Beispiel #3
0
        /// <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>
 /// Parses the <c>parent: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseParents(RepositorySummary summary, string line, Match match)
 {
     int revisionNumber = int.Parse(match.Groups["revnum"].Value, CultureInfo.InvariantCulture);
     summary._ParentRevisionNumbers.Add(revisionNumber);
 }
 /// <summary>
 /// Parses the <c>branch: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseBranch(RepositorySummary summary, string line, Match match)
 {
     summary.Branch = match.Groups["name"].Value;
 }
 /// <summary>
 /// Parses the <c>commit: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseCommit(RepositorySummary summary, string line, Match match)
 {
     if (match.Groups["modified"].Success)
         summary.NumberOfModifiedFiles = int.Parse(match.Groups["modified"].Value, CultureInfo.InvariantCulture);
     if (match.Groups["unknown"].Success)
         summary.NumberOfUnknownFiles = int.Parse(match.Groups["unknown"].Value, CultureInfo.InvariantCulture);
     if (match.Groups["unresolved"].Success)
         summary.NumberOfUnresolvedFiles = int.Parse(match.Groups["unresolved"].Value, CultureInfo.InvariantCulture);
     summary.IsInMerge = match.Groups["inmerge"].Success;
 }
 /// <summary>
 /// Parses the <c>update: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseUpdate(RepositorySummary summary, string line, Match match)
 {
     if (match.Groups["current"].Success)
         summary.NumberOfNewChangesets = 0;
     else if (match.Groups["new"].Success)
         summary.NumberOfNewChangesets = int.Parse(match.Groups["new"].Value, CultureInfo.InvariantCulture);
 }
Beispiel #8
0
 /// <summary>
 /// Parses the <c>branch: </c> line from the summary command.
 /// </summary>
 /// <param name="summary">
 /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
 /// </param>
 /// <param name="line">
 /// The line for which the parse method was called.
 /// </param>
 /// <param name="match">
 /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
 /// </param>
 private static void ParseBranch(RepositorySummary summary, string line, Match match)
 {
     summary.Branch = match.Groups["name"].Value;
 }
Beispiel #9
0
        /// <summary>
        /// Parses the <c>parent: </c> line from the summary command.
        /// </summary>
        /// <param name="summary">
        /// The <see cref="RepositorySummary"/> instance to write the parsed information into.
        /// </param>
        /// <param name="line">
        /// The line for which the parse method was called.
        /// </param>
        /// <param name="match">
        /// The <see cref="Match"/> object resulting in matching up a regular expression with the line.
        /// </param>
        private static void ParseParents(RepositorySummary summary, string line, Match match)
        {
            int revisionNumber = int.Parse(match.Groups["revnum"].Value, CultureInfo.InvariantCulture);

            summary._ParentRevisionNumbers.Add(revisionNumber);
        }