Commit 29be3a6d by Arthur Schreiber

Align git_signature_dup.

This changes git_signature_dup to actually honor oom conditions raised by
the call to git__strdup. It also aligns it with the error code return
pattern used everywhere else.
parent 76c00ead
......@@ -68,10 +68,11 @@ GIT_EXTERN(int) git_signature_default(git_signature **out, git_repository *repo)
*
* Call `git_signature_free()` to free the data.
*
* @param sig signature to duplicated
* @return a copy of sig, NULL on out of memory
* @param dest pointer where to store the copy
* @param entry signature to duplicate
* @return 0 or an error code
*/
GIT_EXTERN(git_signature *) git_signature_dup(const git_signature *sig);
GIT_EXTERN(int) git_signature_dup(git_signature **dest, const git_signature *sig);
/**
* Free an existing signature.
......
......@@ -76,8 +76,8 @@ static git_blame_hunk* dup_hunk(git_blame_hunk *hunk)
git_oid_cpy(&newhunk->orig_commit_id, &hunk->orig_commit_id);
git_oid_cpy(&newhunk->final_commit_id, &hunk->final_commit_id);
newhunk->boundary = hunk->boundary;
newhunk->final_signature = git_signature_dup(hunk->final_signature);
newhunk->orig_signature = git_signature_dup(hunk->orig_signature);
git_signature_dup(&newhunk->final_signature, hunk->final_signature);
git_signature_dup(&newhunk->orig_signature, hunk->orig_signature);
return newhunk;
}
......@@ -269,8 +269,8 @@ static git_blame_hunk* hunk_from_entry(git_blame__entry *e)
e->lno+1, e->num_lines, e->s_lno+1, e->suspect->path);
git_oid_cpy(&h->final_commit_id, git_commit_id(e->suspect->commit));
git_oid_cpy(&h->orig_commit_id, git_commit_id(e->suspect->commit));
h->final_signature = git_signature_dup(git_commit_author(e->suspect->commit));
h->orig_signature = git_signature_dup(git_commit_author(e->suspect->commit));
git_signature_dup(&h->final_signature, git_commit_author(e->suspect->commit));
git_signature_dup(&h->orig_signature, git_commit_author(e->suspect->commit));
h->boundary = e->is_boundary ? 1 : 0;
return h;
}
......
......@@ -82,7 +82,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign
entry = git__calloc(1, sizeof(git_reflog_entry));
GITERR_CHECK_ALLOC(entry);
if ((entry->committer = git_signature_dup(committer)) == NULL)
if ((git_signature_dup(&entry->committer, committer)) < 0)
goto cleanup;
if (msg != NULL) {
......
......@@ -82,23 +82,28 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
return 0;
}
git_signature *git_signature_dup(const git_signature *sig)
int git_signature_dup(git_signature **dest, const git_signature *source)
{
git_signature *new;
git_signature *signature;
if (sig == NULL)
return NULL;
if (source == NULL)
return 0;
signature = git__calloc(1, sizeof(git_signature));
GITERR_CHECK_ALLOC(signature);
signature->name = git__strdup(source->name);
GITERR_CHECK_ALLOC(signature->name);
new = git__calloc(1, sizeof(git_signature));
if (new == NULL)
return NULL;
signature->email = git__strdup(source->email);
GITERR_CHECK_ALLOC(signature->email);
new->name = git__strdup(sig->name);
new->email = git__strdup(sig->email);
new->when.time = sig->when.time;
new->when.offset = sig->when.offset;
signature->when.time = source->when.time;
signature->when.offset = source->when.offset;
return new;
*dest = signature;
return 0;
}
int git_signature_now(git_signature **sig_out, const char *name, const char *email)
......
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