summaryrefslogtreecommitdiff
path: root/src/signature.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-04-28 12:47:14 -0400
committerEdward Thomson <ethomson@github.com>2016-04-28 12:47:14 -0400
commitd383c39b3bc9a2bd5e68882db9a12e64ccd262a4 (patch)
tree33f21286bf1148c10cbdde2b289e5e5bbc421885 /src/signature.c
parent88284dfb7905c5990babb4238b7cd30bdf823500 (diff)
downloadlibgit2-d383c39b3bc9a2bd5e68882db9a12e64ccd262a4.tar.gz
Introduce `git_signature_from_buffer`ethomson/signature_from_buffer
Allow users to construct a signature from the type of signature lines that actually appear in commits.
Diffstat (limited to 'src/signature.c')
-rw-r--r--src/signature.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/signature.c b/src/signature.c
index d07c93323..dcc379717 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -200,7 +200,8 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
memset(sig, 0, sizeof(git_signature));
- if ((buffer_end = memchr(buffer, ender, buffer_end - buffer)) == NULL)
+ if (ender &&
+ (buffer_end = memchr(buffer, ender, buffer_end - buffer)) == NULL)
return signature_error("no newline given");
if (header) {
@@ -262,6 +263,30 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
return 0;
}
+int git_signature_from_buffer(git_signature **out, const char *buf)
+{
+ git_signature *sig;
+ const char *buf_end;
+ int error;
+
+ assert(out && buf);
+
+ *out = NULL;
+
+ sig = git__calloc(1, sizeof(git_signature));
+ GITERR_CHECK_ALLOC(sig);
+
+ buf_end = buf + strlen(buf);
+ error = git_signature__parse(sig, &buf, buf_end, NULL, '\0');
+
+ if (error)
+ git__free(sig);
+ else
+ *out = sig;
+
+ return error;
+}
+
void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig)
{
int offset, hours, mins;