Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Version.cs « LibGit2Sharp - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a3f7edb6bece5f4458fa9cd76273065164d86ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using LibGit2Sharp.Core;

namespace LibGit2Sharp
{
    /// <summary>
    /// Gets the current LibGit2Sharp version.
    /// </summary>
    public class Version
    {
        private readonly Assembly assembly = typeof(Repository).Assembly;

        /// <summary>
        /// Needed for mocking purposes.
        /// </summary>
        protected Version()
        { }

        internal static Version Build()
        {
            return new Version();
        }

        /// <summary>
        /// Returns version of the LibGit2Sharp library.
        /// </summary>
        public virtual string InformationalVersion
        {
            get
            {
                var attribute = (AssemblyInformationalVersionAttribute)assembly
                   .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
                   .Single();

                return attribute.InformationalVersion;
            }
        }

        /// <summary>
        /// Returns all the optional features that were compiled into
        /// libgit2.
        /// </summary>
        /// <returns>A <see cref="BuiltInFeatures"/> enumeration.</returns>
        public virtual BuiltInFeatures Features
        {
            get
            {
                return Proxy.git_libgit2_features();
            }
        }

        /// <summary>
        /// Returns the SHA hash for the libgit2 library.
        /// </summary>
        public virtual string LibGit2CommitSha
        {
            get
            {
                return ReadContentFromResource(assembly, "libgit2_hash.txt").Substring(0, 7);
            }
        }

        /// <summary>
        /// Returns the SHA hash for the LibGit2Sharp library.
        /// </summary>
        public virtual string LibGit2SharpCommitSha
        {
            get
            {
                return ReadContentFromResource(assembly, "libgit2sharp_hash.txt").Substring(0, 7);
            }
        }

        /// <summary>
        /// Returns a string representing the LibGit2Sharp version.
        /// </summary>
        /// <para>
        ///   The format of the version number is as follows:
        ///   <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)</para>
        /// </para>
        /// <returns></returns>
        public override string ToString()
        {
            return RetrieveVersion();
        }

        private string RetrieveVersion()
        {
            string features = Features.ToString();

            return string.Format(
                CultureInfo.InvariantCulture,
                "{0}-{1}-{2} ({3} - {4})",
                InformationalVersion,
                LibGit2SharpCommitSha,
                LibGit2CommitSha,
                Platform.ProcessorArchitecture,
                features);
        }

        private string ReadContentFromResource(Assembly assembly, string partialResourceName)
        {
            string name = string.Format(CultureInfo.InvariantCulture, "LibGit2Sharp.{0}", partialResourceName);
            using (var sr = new StreamReader(assembly.GetManifestResourceStream(name)))
            {
                return sr.ReadLine();
            }
        }
    }
}