Commit f0ab7372 by Vicent Marti

signature: Lenient when dupping, strict when creating

parent 86c6f74a
...@@ -66,10 +66,12 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema ...@@ -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->name = extract_trimmed(name, strlen(name));
p->email = extract_trimmed(email, strlen(email)); p->email = extract_trimmed(email, strlen(email));
if (p->name == NULL || p->email == NULL || if (p->name == NULL || p->email == NULL)
p->name[0] == '\0' || p->email[0] == '\0') { return -1; /* oom */
if (p->name[0] == '\0') {
git_signature_free(p); git_signature_free(p);
return signature_error("Empty name or email"); return signature_error("Signature cannot have an empty name");
} }
p->when.time = time; p->when.time = time;
...@@ -81,9 +83,16 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema ...@@ -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 *git_signature_dup(const git_signature *sig)
{ {
git_signature *new; git_signature *new = git__calloc(1, sizeof(git_signature));
if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < 0)
if (new == NULL)
return 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; return new;
} }
......
...@@ -54,8 +54,8 @@ void test_commit_signature__create_empties(void) ...@@ -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(" ", "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_pass(try_build_signature("nulltoken", "", 1234567890, 60));
cl_git_fail(try_build_signature("nulltoken", " ", 1234567890, 60)); cl_git_pass(try_build_signature("nulltoken", " ", 1234567890, 60));
} }
void test_commit_signature__create_one_char(void) void test_commit_signature__create_one_char(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment