*/
#include "reflog.h"
+
#include "repository.h"
#include "filebuf.h"
#include "signature.h"
#include "refdb.h"
-#include <git2/sys/refdb_backend.h>
-
-git_reflog_entry *git_reflog_entry__alloc(void)
-{
- return git__calloc(1, sizeof(git_reflog_entry));
-}
+#include "git2/sys/refdb_backend.h"
+#include "git2/sys/reflog.h"
void git_reflog_entry__free(git_reflog_entry *entry)
{
int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_signature *committer, const char *msg)
{
- git_reflog_entry *entry;
const git_reflog_entry *previous;
- const char *newline;
+ git_reflog_entry *entry;
assert(reflog && new_oid && committer);
entry = git__calloc(1, sizeof(git_reflog_entry));
- GITERR_CHECK_ALLOC(entry);
+ GIT_ERROR_CHECK_ALLOC(entry);
if ((git_signature_dup(&entry->committer, committer)) < 0)
goto cleanup;
if (msg != NULL) {
- if ((entry->msg = git__strdup(msg)) == NULL)
- goto cleanup;
+ size_t i, msglen = strlen(msg);
- newline = strchr(msg, '\n');
-
- if (newline) {
- if (newline[1] != '\0') {
- giterr_set(GITERR_INVALID, "Reflog message cannot contain newline");
- goto cleanup;
- }
+ if ((entry->msg = git__strndup(msg, msglen)) == NULL)
+ goto cleanup;
- entry->msg[newline - msg] = '\0';
- }
+ /*
+ * Replace all newlines with spaces, except for
+ * the final trailing newline.
+ */
+ for (i = 0; i < msglen; i++)
+ if (entry->msg[i] == '\n')
+ entry->msg[i] = ' ';
}
previous = git_reflog_entry_byindex(reflog, 0);
entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx);
if (entry == NULL) {
- giterr_set(GITERR_REFERENCE, "No reflog entry at index "PRIuZ, idx);
+ git_error_set(GIT_ERROR_REFERENCE, "no reflog entry at index %"PRIuZ, idx);
return GIT_ENOTFOUND;
}