summaryrefslogtreecommitdiff
path: root/src/oid.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-06-28 19:15:48 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-28 19:36:27 +0200
commitd5afc0390c3ef919fcde23300d7aefdaeafa5daa (patch)
tree0b661ef8536266c5bf5de645025c8072bc35dc85 /src/oid.c
parent0b10c9ea6ef5d85d862edd044d96561c4fd16e9b (diff)
downloadlibgit2-d5afc0390c3ef919fcde23300d7aefdaeafa5daa.tar.gz
Remove redundant methods from the API
A bunch of redundant methods have been removed from the external API. - All the reference/tag creation methods with `_f` are gone. The force flag is now passed as an argument to the normal create methods. - All the different commit creation methods are gone; commit creation now always requires a `git_commit` pointer for parents and a `git_tree` pointer for tree, to ensure that corrupted commits cannot be generated. - All the different tag creation methods are gone; tag creation now always requires a `git_object` pointer to ensure that tags are not created to inexisting objects.
Diffstat (limited to 'src/oid.c')
-rw-r--r--src/oid.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/oid.c b/src/oid.c
index 3e3237f9c..70dd7c597 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -49,19 +49,37 @@ static signed char from_hex[] = {
};
static char to_hex[] = "0123456789abcdef";
-int git_oid_fromstr(git_oid *out, const char *str)
+int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
{
size_t p;
- for (p = 0; p < sizeof(out->id); p++, str += 2) {
- int v = (from_hex[(unsigned char)str[0]] << 4)
- | from_hex[(unsigned char)str[1]];
+
+ if (length > GIT_OID_HEXSZ)
+ length = GIT_OID_HEXSZ;
+
+ if (length % 2)
+ length--;
+
+ for (p = 0; p < length; p += 2) {
+ int v = (from_hex[(unsigned char)str[p + 0]] << 4)
+ | from_hex[(unsigned char)str[p + 1]];
+
if (v < 0)
return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash");
- out->id[p] = (unsigned char)v;
+
+ out->id[p / 2] = (unsigned char)v;
}
+
+ for (; p < GIT_OID_HEXSZ; p += 2)
+ out->id[p / 2] = 0x0;
+
return GIT_SUCCESS;
}
+int git_oid_fromstr(git_oid *out, const char *str)
+{
+ return git_oid_fromstrn(out, str, GIT_OID_HEXSZ);
+}
+
GIT_INLINE(char) *fmt_one(char *str, unsigned int val)
{
*str++ = to_hex[val >> 4];