1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 #ifndef INCLUDE_git_signature_h__ 8 #define INCLUDE_git_signature_h__ 9 10 #include "common.h" 11 #include "types.h" 12 13 /** 14 * @file git2/signature.h 15 * @brief Git signature creation 16 * @defgroup git_signature Git signature creation 17 * @ingroup Git 18 * @{ 19 */ 20 GIT_BEGIN_DECL 21 22 /** 23 * Create a new action signature. 24 * 25 * Call `git_signature_free()` to free the data. 26 * 27 * Note: angle brackets ('<' and '>') characters are not allowed 28 * to be used in either the `name` or the `email` parameter. 29 * 30 * @param out new signature, in case of error NULL 31 * @param name name of the person 32 * @param email email of the person 33 * @param time time (in seconds from epoch) when the action happened 34 * @param offset timezone offset (in minutes) for the time 35 * @return 0 or an error code 36 */ 37 GIT_EXTERN(int) git_signature_new(git_signature **out, const char *name, const char *email, git_time_t time, int offset); 38 39 /** 40 * Create a new action signature with a timestamp of 'now'. 41 * 42 * Call `git_signature_free()` to free the data. 43 * 44 * @param out new signature, in case of error NULL 45 * @param name name of the person 46 * @param email email of the person 47 * @return 0 or an error code 48 */ 49 GIT_EXTERN(int) git_signature_now(git_signature **out, const char *name, const char *email); 50 51 /** 52 * Create a new action signature with default user and now timestamp. 53 * 54 * This looks up the user.name and user.email from the configuration and 55 * uses the current time as the timestamp, and creates a new signature 56 * based on that information. It will return GIT_ENOTFOUND if either the 57 * user.name or user.email are not set. 58 * 59 * @param out new signature 60 * @param repo repository pointer 61 * @return 0 on success, GIT_ENOTFOUND if config is missing, or error code 62 */ 63 GIT_EXTERN(int) git_signature_default(git_signature **out, git_repository *repo); 64 65 /** 66 * Create a new signature by parsing the given buffer, which is 67 * expected to be in the format "Real Name <email> timestamp tzoffset", 68 * where `timestamp` is the number of seconds since the Unix epoch and 69 * `tzoffset` is the timezone offset in `hhmm` format (note the lack 70 * of a colon separator). 71 * 72 * @param out new signature 73 * @param buf signature string 74 * @return 0 on success, or an error code 75 */ 76 GIT_EXTERN(int) git_signature_from_buffer(git_signature **out, const char *buf); 77 78 /** 79 * Create a copy of an existing signature. All internal strings are also 80 * duplicated. 81 * 82 * Call `git_signature_free()` to free the data. 83 * 84 * @param dest pointer where to store the copy 85 * @param sig signature to duplicate 86 * @return 0 or an error code 87 */ 88 GIT_EXTERN(int) git_signature_dup(git_signature **dest, const git_signature *sig); 89 90 /** 91 * Free an existing signature. 92 * 93 * Because the signature is not an opaque structure, it is legal to free it 94 * manually, but be sure to free the "name" and "email" strings in addition 95 * to the structure itself. 96 * 97 * @param sig signature to free 98 */ 99 GIT_EXTERN(void) git_signature_free(git_signature *sig); 100 101 /** @} */ 102 GIT_END_DECL 103 #endif 104