diff options
| author | Ramsay Jones <ramsay@ramsay1.demon.co.uk> | 2009-08-28 21:22:46 +0100 |
|---|---|---|
| committer | Ramsay Jones <ramsay@ramsay1.demon.co.uk> | 2009-10-13 16:27:33 +0100 |
| commit | 960ca1d7799e02b72ca828373c3fff04e2cf0334 (patch) | |
| tree | f85c76fe4882c7a4befdea9224fa8c01574fdfce /src/oid.c | |
| parent | e45535849cb7187e22c9fd11d14e0eb37f5d7dc8 (diff) | |
| download | libgit2-960ca1d7799e02b72ca828373c3fff04e2cf0334.tar.gz | |
Add the git_oid_to_string() utility function
Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Diffstat (limited to 'src/oid.c')
| -rw-r--r-- | src/oid.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -94,3 +94,23 @@ char *git_oid_allocfmt(const git_oid *oid) str[GIT_OID_HEXSZ] = '\0'; return str; } + +char *git_oid_to_string(char *out, size_t n, const git_oid *oid) +{ + char str[GIT_OID_HEXSZ]; + + if (!out || n == 0 || !oid) + return ""; + + n--; /* allow room for terminating NUL */ + + if (n > 0) { + git_oid_fmt(str, oid); + memcpy(out, str, n > GIT_OID_HEXSZ ? GIT_OID_HEXSZ : n); + } + + out[n] = '\0'; + + return out; +} + |
