diff options
author | Vicent Marti <tanoku@gmail.com> | 2014-08-18 12:41:06 +0200 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2014-08-18 12:41:06 +0200 |
commit | 4ca0b566ca811550b4db31045e580b4970e5b8e3 (patch) | |
tree | e34ed66136f5a6cdf496b4d8c8a52fcb9c17702e /src | |
parent | 59403f1ff55346c64bfaa0744ea7f3375da71725 (diff) | |
download | libgit2-4ca0b566ca811550b4db31045e580b4970e5b8e3.tar.gz |
oid: Export `git_oid_tostr_s` instead of `_allocfmt`vmg/tostr_s
The old `allocfmt` is of no use to callers, as they are not able to free
the returned buffer. Export a new API that returns a static string that
doesn't need to be freed.
Diffstat (limited to 'src')
-rw-r--r-- | src/global.h | 1 | ||||
-rw-r--r-- | src/oid.c | 8 | ||||
-rw-r--r-- | src/oid.h | 11 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/global.h b/src/global.h index 745df3e4a..106504628 100644 --- a/src/global.h +++ b/src/global.h @@ -13,6 +13,7 @@ typedef struct { git_error *last_error; git_error error_t; + char oid_fmt[41]; } git_global_st; #ifdef GIT_SSL @@ -8,6 +8,7 @@ #include "common.h" #include "git2/oid.h" #include "repository.h" +#include "global.h" #include <string.h> #include <limits.h> @@ -99,6 +100,13 @@ void git_oid_pathfmt(char *str, const git_oid *oid) str = fmt_one(str, oid->id[i]); } +char *git_oid_tostr_s(const git_oid *oid) +{ + char *str = GIT_GLOBAL->oid_fmt; + git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid); + return str; +} + char *git_oid_allocfmt(const git_oid *oid) { char *str = git__malloc(GIT_OID_HEXSZ + 1); @@ -9,6 +9,17 @@ #include "git2/oid.h" +/** + * Format a git_oid into a newly allocated c-string. + * + * The c-string is owned by the caller and needs to be manually freed. + * + * @param id the oid structure to format + * @return the c-string; NULL if memory is exhausted. Caller must + * deallocate the string with git__free(). + */ +char *git_oid_allocfmt(const git_oid *id); + GIT_INLINE(int) git_oid__hashcmp(const unsigned char *sha1, const unsigned char *sha2) { int i; |