예제 #1
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="System.Text.RegularExpressions.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;
 }
예제 #2
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="System.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);
        }
예제 #3
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="System.Text.RegularExpressions.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;
 }
예제 #4
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="System.Text.RegularExpressions.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);
        }