1 /*
2  *             Copyright Sönke Ludwig 2014.
3  *  Distributed under the Boost Software License, Version 1.0.
4  *     (See accompanying file LICENSE_1_0.txt or copy at
5  *           http://www.boost.org/LICENSE_1_0.txt)
6  */
7 module git.signature;
8 
9 import git.commit;
10 import git.oid;
11 import git.repository;
12 import git.tag;
13 import git.types;
14 import git.util;
15 import git.version_;
16 
17 import deimos.git2.signature;
18 import deimos.git2.types;
19 
20 import std.conv : to;
21 import std.datetime;
22 import std.string : toStringz;
23 
24 static if (targetLibGitVersion >= VersionInfo(0, 20, 0)) {
25 	GitSignature createDefaultSignature(GitRepo repo)
26 	{
27 		git_signature* ret;
28 		require(git_signature_default(&ret, repo.cHandle) == 0);
29 		return GitSignature(ret);
30 	}
31 }
32 
33 /*GitSignature createSignature(string name, string email, SysTime time)
34 {
35 	git_signature* ret;
36 	require(git_signature_new(&ret, name.toStringz, email.toStringz, gtime, gofffset) == 0);
37 	return GitSignature(ret);
38 }*/
39 
40 GitSignature createSignature(string name, string email)
41 {
42 	git_signature* ret;
43 	require(git_signature_now(&ret, name.toStringz, email.toStringz) == 0);
44 	return GitSignature(ret);
45 }
46 
47 struct GitSignature {
48 	package this(git_signature* sig)
49 	{
50 		_commit = GitCommit.init;
51 		_tag = GitTag.init;
52 		_data = Data(sig);
53 	}
54 
55 	package this(GitCommit owner, const(git_signature)* sig)
56 	{
57 		_commit = owner;
58 		_tag = GitTag.init;
59 		_sig = sig;
60 	}
61 
62 	package this(GitTag owner, const(git_signature)* sig)
63 	{
64 		_commit = GitCommit.init;
65 		_tag = owner;
66 		_sig = sig;
67 	}
68 
69 	@property SysTime time() const { return _sig.when.toSysTime(); }
70 	@property string name() const { return _sig.name.to!string; }
71 	@property string email() const { return _sig.email.to!string; }
72 	@property GitSignature dup() { return GitSignature(git_signature_dup(this.cHandle)); }
73 
74 	package const(git_signature)* cHandle() const { return _sig ? _sig : _data._payload; }
75 
76 	mixin RefCountedGitObject!(git_signature, git_signature_free, false);
77 
78 private:
79 	// Reference to the parent commit to keep it alive.
80 	GitCommit _commit;
81 	GitTag _tag;
82 	const(git_signature)* _sig;
83 }