diff options
author | nulltoken <emeric.fermas@gmail.com> | 2015-03-17 21:32:22 +0300 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2015-03-17 21:56:17 +0300 |
commit | 964943bf9bed4da87a08befa7df30b8e2d77373d (patch) | |
tree | 8aaab1a700edb2af0c3fe0a2cc020f627a27d89f | |
parent | 930f63ce427d4e749578bf7b689affafc451c756 (diff) |
Introduce Identity type
-rw-r--r-- | LibGit2Sharp.Tests/TestHelpers/Constants.cs | 3 | ||||
-rw-r--r-- | LibGit2Sharp/Identity.cs | 45 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 1 | ||||
-rw-r--r-- | LibGit2Sharp/Signature.cs | 14 |
4 files changed, 62 insertions, 1 deletions
diff --git a/LibGit2Sharp.Tests/TestHelpers/Constants.cs b/LibGit2Sharp.Tests/TestHelpers/Constants.cs index 71f942a5..46f1d4e4 100644 --- a/LibGit2Sharp.Tests/TestHelpers/Constants.cs +++ b/LibGit2Sharp.Tests/TestHelpers/Constants.cs @@ -6,7 +6,8 @@ namespace LibGit2Sharp.Tests.TestHelpers { public const string TemporaryReposPath = "TestRepos"; public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; - public static readonly Signature Signature = new Signature("A. U. Thor", "thor@valhalla.asgard.com", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2))); + public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com"); + public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2))); // Populate these to turn on live credential tests: set the // PrivateRepoUrl to the URL of a repository that requires diff --git a/LibGit2Sharp/Identity.cs b/LibGit2Sharp/Identity.cs new file mode 100644 index 00000000..207e2426 --- /dev/null +++ b/LibGit2Sharp/Identity.cs @@ -0,0 +1,45 @@ +using LibGit2Sharp.Core; + +namespace LibGit2Sharp +{ + /// <summary> + /// Represents the identity used when writing reflog entries. + /// </summary> + public sealed class Identity + { + private readonly string _name; + private readonly string _email; + + /// <summary> + /// Initializes a new instance of the <see cref="Identity"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="email">The email.</param> + public Identity(string name, string email) + { + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(email, "email"); + Ensure.ArgumentDoesNotContainZeroByte(name, "name"); + Ensure.ArgumentDoesNotContainZeroByte(name, "email"); + + _name = name; + _email = email; + } + + /// <summary> + /// Gets the email. + /// </summary> + public string Email + { + get { return _email; } + } + + /// <summary> + /// Gets the name. + /// </summary> + public string Name + { + get { return _name; } + } + } +} diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 3ba75e7a..82ace6aa 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -80,6 +80,7 @@ <Compile Include="EntryExistsException.cs" /> <Compile Include="FetchOptionsBase.cs" /> <Compile Include="IBelongToARepository.cs" /> + <Compile Include="Identity.cs" /> <Compile Include="IndexNameEntryCollection.cs" /> <Compile Include="ContentChangeStats.cs" /> <Compile Include="BuiltInFeatures.cs" /> diff --git a/LibGit2Sharp/Signature.cs b/LibGit2Sharp/Signature.cs index f51e14b0..bc3f8143 100644 --- a/LibGit2Sharp/Signature.cs +++ b/LibGit2Sharp/Signature.cs @@ -44,6 +44,20 @@ namespace LibGit2Sharp this.when = when; } + /// <summary> + /// Initializes a new instance of the <see cref="Signature"/> class. + /// </summary> + /// <param name="identity">The identity.</param> + /// <param name="when">The when.</param> + public Signature(Identity identity, DateTimeOffset when) + { + Ensure.ArgumentNotNull(identity, "identity"); + + this.name = identity.Name; + this.email = identity.Email; + this.when = when; + } + internal SignatureSafeHandle BuildHandle() { return Proxy.git_signature_new(name, email, when); |