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

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-02-02 02:39:39 +0400
committernulltoken <emeric.fermas@gmail.com>2012-02-02 02:39:39 +0400
commit9196a4823cb75dea011a97b4f1b5a12b9d3c041b (patch)
tree08e7de9268a879c8f1b8d233bab6c6fbb249fc1c /LibGit2Sharp/Signature.cs
parent839c659c35d8fe42407ef3a749a251eb4daff254 (diff)
Simplify handling of native signature handle
Diffstat (limited to 'LibGit2Sharp/Signature.cs')
-rw-r--r--LibGit2Sharp/Signature.cs47
1 files changed, 20 insertions, 27 deletions
diff --git a/LibGit2Sharp/Signature.cs b/LibGit2Sharp/Signature.cs
index fe486740..32075609 100644
--- a/LibGit2Sharp/Signature.cs
+++ b/LibGit2Sharp/Signature.cs
@@ -9,16 +9,18 @@ namespace LibGit2Sharp
/// </summary>
public class Signature
{
- private readonly GitSignature handle = new GitSignature();
- private DateTimeOffset? when;
+ private readonly DateTimeOffset when;
+ private readonly string name;
+ private readonly string email;
- internal Signature(IntPtr signaturePtr, bool ownedByRepo = true)
+ internal Signature(IntPtr signaturePtr)
{
+ var handle = new GitSignature();
Marshal.PtrToStructure(signaturePtr, handle);
- if (!ownedByRepo)
- {
- NativeMethods.git_signature_free(signaturePtr);
- }
+
+ name = handle.Name;
+ email = handle.Email;
+ when = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset);
}
/// <summary>
@@ -28,30 +30,28 @@ namespace LibGit2Sharp
/// <param name = "email">The email.</param>
/// <param name = "when">The when.</param>
public Signature(string name, string email, DateTimeOffset when)
- : this(CreateSignature(name, email, when), false)
{
+ this.name = name;
+ this.email = email;
+ this.when = when;
}
- private static IntPtr CreateSignature(string name, string email, DateTimeOffset when)
+ internal SignatureSafeHandle BuildHandle()
{
- IntPtr signature;
- int result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(), (int)when.Offset.TotalMinutes);
- Ensure.Success(result);
+ SignatureSafeHandle signature;
+ int result = NativeMethods.git_signature_new(out signature, name, email, when.ToSecondsSinceEpoch(),
+ (int) when.Offset.TotalMinutes);
+ Ensure.Success(result);
return signature;
}
- internal GitSignature Handle
- {
- get { return handle; }
- }
-
/// <summary>
/// Gets the name.
/// </summary>
public string Name
{
- get { return handle.Name; }
+ get { return name; }
}
/// <summary>
@@ -59,7 +59,7 @@ namespace LibGit2Sharp
/// </summary>
public string Email
{
- get { return handle.Email; }
+ get { return email; }
}
/// <summary>
@@ -67,14 +67,7 @@ namespace LibGit2Sharp
/// </summary>
public DateTimeOffset When
{
- get
- {
- if (when == null)
- {
- when = Epoch.ToDateTimeOffset(handle.When.Time, handle.When.Offset);
- }
- return when.Value;
- }
+ get { return when; }
}
}
}