diff options
| author | Carlos Martín Nieto <cmn@elego.de> | 2011-04-05 16:15:54 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-04-09 15:29:48 -0700 |
| commit | 9e9e6ae177332f5c1311eff9c9b5ca9740e04dbd (patch) | |
| tree | 6f596a98ec7cb2fc67614bf805f3b4859b67f609 /src/signature.c | |
| parent | b5c00c6d41ff4eb809f7deda38fe61ccaacb7cbf (diff) | |
| download | libgit2-9e9e6ae177332f5c1311eff9c9b5ca9740e04dbd.tar.gz | |
Add API git_signature_new_now
Most tags will have a timestamp of whenever the code is running and
dealing with time and timezones is error-prone. Optimize for this case
by adding a function which causes the signature to be created with a
current timestamp.
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src/signature.c')
| -rw-r--r-- | src/signature.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/signature.c b/src/signature.c index bd64652ca..0e8331365 100644 --- a/src/signature.c +++ b/src/signature.c @@ -65,6 +65,25 @@ git_signature *git_signature_dup(const git_signature *sig) return git_signature_new(sig->name, sig->email, sig->when.time, sig->when.offset); } +git_signature *git_signature_new_now(const char *name, const char *email) +{ + time_t now; + struct tm utc_tm, local_tm; + int offset; + + time(&now); + + gmtime_r(&now, &utc_tm); + localtime_r(&now, &local_tm); + + offset = mktime(&local_tm) - mktime(&utc_tm); + offset /= 60; + /* mktime takes care of setting tm_isdst correctly */ + if (local_tm.tm_isdst) + offset += 60; + + return git_signature_new(name, email, now, offset); +} static int parse_timezone_offset(const char *buffer, long *offset_out) { |
