]> git.proxmox.com Git - libgit2.git/blobdiff - src/reflog.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / src / reflog.c
index 22aa7d8edb0c17685885a422539470198987a1b9..34537aa1f83b6315c27136ca753284edc5bfc70f 100644 (file)
@@ -6,17 +6,14 @@
  */
 
 #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)
 {
@@ -73,32 +70,30 @@ int git_reflog_write(git_reflog *reflog)
 
 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);
@@ -193,7 +188,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
        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;
        }