PageRenderTime 27ms CodeModel.GetById 21ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Mercurial.Net/Extensions/Churn/ChurnExtension.cs

#
C# | 52 lines | 25 code | 3 blank | 24 comment | 3 complexity | 0c5c8be082a7a81c26297ba1e2c51ac0 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3
 4namespace Mercurial.Extensions.Churn
 5{
 6    /// <summary>
 7    /// This class contains logic for the caseguard Mercurial extension.
 8    /// </summary>
 9    public static class ChurnExtension
10    {
11        /// <summary>
12        /// Gets a value indicating whether the caseguard extension is installed and active.
13        /// </summary>
14        public static bool IsInstalled
15        {
16            get
17            {
18                return ClientExecutable.Configuration.ValueExists("extensions", "churn");
19            }
20        }
21
22        /// <summary>
23        /// Calculates the churn report; a histogram of changes to the repository.
24        /// </summary>
25        /// <param name="repository">
26        /// The <see cref="Repository"/> to calculate the churn report for.
27        /// </param>
28        /// <param name="command">
29        /// Any extra options to the churn method, or <c>null</c> for default options.
30        /// </param>
31        /// <returns>
32        /// A collection of <see cref="ChurnGroup" /> instances.
33        /// </returns>
34        /// <exception cref="ArgumentNullException">
35        /// <para><paramref name="repository"/> is <c>null</c>.</para>
36        /// </exception>
37        /// <exception cref="InvalidOperationException">
38        /// The Churn extension is not installed and active.
39        /// </exception>
40        public static IEnumerable<ChurnGroup> Churn(this Repository repository, ChurnCommand command = null)
41        {
42            if (repository == null)
43                throw new ArgumentNullException("repository");
44            if (!IsInstalled)
45                throw new InvalidOperationException("The churn extension is not installed and active");
46
47            command = command ?? new ChurnCommand();
48            repository.Execute(command);
49            return command.Result;
50        }
51    }
52}