diff options
| author | Henry Kleynhans <hkleynhans@bloomberg.net> | 2017-11-12 10:56:50 +0000 |
|---|---|---|
| committer | Henry Kleynhans <hkleynhans@bloomberg.net> | 2017-11-12 12:01:10 +0000 |
| commit | f063dafb1da60625da76a1ea6975a121969cb630 (patch) | |
| tree | 0b9258a114cee911506ac326f736fc236a00dec3 /src | |
| parent | 1d7c15adf983853cf8df03dc0af411df3fa5fa07 (diff) | |
| download | libgit2-f063dafb1da60625da76a1ea6975a121969cb630.tar.gz | |
signature: distinguish +0000 and -0000 UTC offsets
Git considers '-0000' a valid offset for signature lines. They need to
be treated as _not_ equal to a '+0000' signature offset. Parsing a
signature line stores the offset in a signed integer which does not
distinguish between `+0` and `-0`.
This patch adds an additional flag `sign` to the `git_time` in the
`signature` object which is populated with the sign of the offset. In
addition to exposing this information to the user, this information is
also used to compare signatures.
/cc @pks-t @ethomson
Diffstat (limited to 'src')
| -rw-r--r-- | src/signature.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/signature.c b/src/signature.c index bc3cf330a..cd6852326 100644 --- a/src/signature.c +++ b/src/signature.c @@ -90,6 +90,7 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema p->when.time = time; p->when.offset = offset; + p->when.sign = (offset < 0) ? '-' : '+'; *sig_out = p; return 0; @@ -113,6 +114,7 @@ int git_signature_dup(git_signature **dest, const git_signature *source) signature->when.time = source->when.time; signature->when.offset = source->when.offset; + signature->when.sign = source->when.sign; *dest = signature; @@ -137,6 +139,7 @@ int git_signature__pdup(git_signature **dest, const git_signature *source, git_p signature->when.time = source->when.time; signature->when.offset = source->when.offset; + signature->when.sign = source->when.sign; *dest = signature; @@ -257,6 +260,7 @@ int git_signature__parse(git_signature *sig, const char **buffer_out, */ if (hours <= 14 && mins <= 59) { sig->when.offset = (hours * 60) + mins; + sig->when.sign = tz_start[0]; if (tz_start[0] == '-') sig->when.offset = -sig->when.offset; } @@ -299,7 +303,7 @@ void git_signature__writebuf(git_buf *buf, const char *header, const git_signatu assert(buf && sig); offset = sig->when.offset; - sign = (sig->when.offset < 0) ? '-' : '+'; + sign = (sig->when.offset < 0 || sig->when.sign == '-') ? '-' : '+'; if (offset < 0) offset = -offset; @@ -320,6 +324,7 @@ bool git_signature__equal(const git_signature *one, const git_signature *two) git__strcmp(one->name, two->name) == 0 && git__strcmp(one->email, two->email) == 0 && one->when.time == two->when.time && - one->when.offset == two->when.offset; + one->when.offset == two->when.offset && + one->when.sign == two->when.sign; } |
