signature: Lenient when dupping, strict when creating
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
diff --git a/src/signature.c b/src/signature.c
index 649dbcd..48bdd81 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -66,10 +66,12 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
p->name = extract_trimmed(name, strlen(name));
p->email = extract_trimmed(email, strlen(email));
- if (p->name == NULL || p->email == NULL ||
- p->name[0] == '\0' || p->email[0] == '\0') {
+ if (p->name == NULL || p->email == NULL)
+ return -1; /* oom */
+
+ if (p->name[0] == '\0') {
git_signature_free(p);
- return signature_error("Empty name or email");
+ return signature_error("Signature cannot have an empty name");
}
p->when.time = time;
@@ -81,9 +83,16 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
git_signature *git_signature_dup(const git_signature *sig)
{
- git_signature *new;
- if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < 0)
+ git_signature *new = git__calloc(1, sizeof(git_signature));
+
+ if (new == NULL)
return NULL;
+
+ new->name = git__strdup(sig->name);
+ new->email = git__strdup(sig->email);
+ new->when.time = sig->when.time;
+ new->when.offset = sig->when.offset;
+
return new;
}
diff --git a/tests-clar/commit/signature.c b/tests-clar/commit/signature.c
index 9364efb..aef72a8 100644
--- a/tests-clar/commit/signature.c
+++ b/tests-clar/commit/signature.c
@@ -54,8 +54,8 @@ void test_commit_signature__create_empties(void)
cl_git_fail(try_build_signature("", "emeric.fermas@gmail.com", 1234567890, 60));
cl_git_fail(try_build_signature(" ", "emeric.fermas@gmail.com", 1234567890, 60));
- cl_git_fail(try_build_signature("nulltoken", "", 1234567890, 60));
- cl_git_fail(try_build_signature("nulltoken", " ", 1234567890, 60));
+ cl_git_pass(try_build_signature("nulltoken", "", 1234567890, 60));
+ cl_git_pass(try_build_signature("nulltoken", " ", 1234567890, 60));
}
void test_commit_signature__create_one_char(void)