]> git.proxmox.com Git - libgit2.git/blobdiff - src/reflog.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / src / reflog.c
index cebb87d8657b037ec42e870a2ef8c901ee460585..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 ((entry->committer = git_signature_dup(committer)) == NULL)
+       if ((git_signature_dup(&entry->committer, committer)) < 0)
                goto cleanup;
 
        if (msg != NULL) {
-               if ((entry->msg = git__strdup(msg)) == NULL)
-                       goto cleanup;
-
-               newline = strchr(msg, '\n');
+               size_t i, msglen = strlen(msg);
 
-               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);
@@ -148,7 +143,7 @@ size_t git_reflog_entrycount(git_reflog *reflog)
        return reflog->entries.length;
 }
 
-const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, size_t idx)
+const git_reflog_entry * git_reflog_entry_byindex(const git_reflog *reflog, size_t idx)
 {
        assert(reflog);
 
@@ -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;
        }
 
@@ -230,22 +225,3 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
 
        return 0;
 }
-
-int git_reflog_append_to(git_repository *repo, const char *name, const git_oid *id,
-                        const git_signature *committer, const char *msg)
-{
-       int error;
-       git_reflog *reflog;
-
-       if ((error = git_reflog_read(&reflog, repo, name)) < 0)
-               return error;
-
-       if ((error = git_reflog_append(reflog, id, committer, msg)) < 0)
-               goto cleanup;
-
-       error = git_reflog_write(reflog);
-
-cleanup:
-       git_reflog_free(reflog);
-       return error;
-}