#include "notes.h"
-#include "git2.h"
+#include "buf.h"
#include "refs.h"
#include "config.h"
#include "iterator.h"
/* TODO: should we apply filters? */
/* create note object */
- if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
+ if ((error = git_blob_create_from_buffer(&oid, repo, note, strlen(note))) < 0)
goto cleanup;
if ((error = manipulate_note_in_tree_r(
git_blob *blob)
{
git_note *note = NULL;
- git_off_t blobsize;
+ git_object_size_t blobsize;
note = git__malloc(sizeof(git_note));
GIT_ERROR_CHECK_ALLOC(note);
return error;
}
-static int note_get_default_ref(char **out, git_repository *repo)
+static int note_get_default_ref(git_str *out, git_repository *repo)
{
git_config *cfg;
- int ret = git_repository_config__weakptr(&cfg, repo);
+ int error;
+
+ if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
+ return error;
- *out = (ret != 0) ? NULL : git_config__get_string_force(
- cfg, "core.notesref", GIT_NOTES_DEFAULT_REF);
+ error = git_config__get_string_buf(out, cfg, "core.notesref");
- return ret;
+ if (error == GIT_ENOTFOUND)
+ error = git_str_puts(out, GIT_NOTES_DEFAULT_REF);
+
+ return error;
}
-static int normalize_namespace(char **out, git_repository *repo, const char *notes_ref)
+static int normalize_namespace(git_str *out, git_repository *repo, const char *notes_ref)
{
- if (notes_ref) {
- *out = git__strdup(notes_ref);
- GIT_ERROR_CHECK_ALLOC(*out);
- return 0;
- }
+ if (notes_ref)
+ return git_str_puts(out, notes_ref);
return note_get_default_ref(out, repo);
}
static int retrieve_note_commit(
git_commit **commit_out,
- char **notes_ref_out,
+ git_str *notes_ref_out,
git_repository *repo,
const char *notes_ref)
{
if ((error = normalize_namespace(notes_ref_out, repo, notes_ref)) < 0)
return error;
- if ((error = git_reference_name_to_id(&oid, repo, *notes_ref_out)) < 0)
+ if ((error = git_reference_name_to_id(&oid, repo, notes_ref_out->ptr)) < 0)
return error;
if (git_commit_lookup(commit_out, repo, &oid) < 0)
const char *notes_ref_in, const git_oid *oid)
{
int error;
- char *notes_ref = NULL;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *commit = NULL;
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in);
error = git_note_commit_read(out, repo, commit, oid);
cleanup:
- git__free(notes_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(commit);
return error;
}
int allow_note_overwrite)
{
int error;
- char *notes_ref = NULL;
+ git_str notes_ref = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_reference *ref = NULL;
git_oid notes_blob_oid, notes_commit_oid;
if (error < 0)
goto cleanup;
- error = git_reference_create(&ref, repo, notes_ref,
+ error = git_reference_create(&ref, repo, notes_ref.ptr,
¬es_commit_oid, 1, NULL);
if (out != NULL)
git_oid_cpy(out, ¬es_blob_oid);
cleanup:
- git__free(notes_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(existing_notes_commit);
git_reference_free(ref);
return error;
const git_oid *oid)
{
int error;
- char *notes_ref_target = NULL;
+ git_str notes_ref_target = GIT_STR_INIT;
git_commit *existing_notes_commit = NULL;
git_oid new_notes_commit;
git_reference *notes_ref = NULL;
if (error < 0)
goto cleanup;
- error = git_reference_create(¬es_ref, repo, notes_ref_target,
+ error = git_reference_create(¬es_ref, repo, notes_ref_target.ptr,
&new_notes_commit, 1, NULL);
cleanup:
- git__free(notes_ref_target);
+ git_str_dispose(¬es_ref_target);
git_reference_free(notes_ref);
git_commit_free(existing_notes_commit);
return error;
int git_note_default_ref(git_buf *out, git_repository *repo)
{
- char *default_ref;
- int error;
-
- assert(out && repo);
-
- git_buf_sanitize(out);
-
- if ((error = note_get_default_ref(&default_ref, repo)) < 0)
- return error;
-
- git_buf_attach(out, default_ref, strlen(default_ref));
- return 0;
+ GIT_BUF_WRAP_PRIVATE(out, note_get_default_ref, repo);
}
const git_signature *git_note_committer(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->committer;
}
const git_signature *git_note_author(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->author;
}
-const char * git_note_message(const git_note *note)
+const char *git_note_message(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return note->message;
}
-const git_oid * git_note_id(const git_note *note)
+const git_oid *git_note_id(const git_note *note)
{
- assert(note);
+ GIT_ASSERT_ARG_WITH_RETVAL(note, NULL);
return ¬e->id;
}
}
static int process_entry_path(
- const char* entry_path,
+ const char *entry_path,
git_oid *annotated_object_id)
{
int error = 0;
size_t i = 0, j = 0, len;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- if ((error = git_buf_puts(&buf, entry_path)) < 0)
+ if ((error = git_str_puts(&buf, entry_path)) < 0)
goto cleanup;
- len = git_buf_len(&buf);
+ len = git_str_len(&buf);
while (i < len) {
if (buf.ptr[i] == '/') {
error = git_oid_fromstr(annotated_object_id, buf.ptr);
cleanup:
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
return error;
}
{
int error;
git_commit *commit = NULL;
- char *notes_ref;
+ git_str notes_ref = GIT_STR_INIT;
error = retrieve_note_commit(&commit, ¬es_ref, repo, notes_ref_in);
if (error < 0)
error = git_note_commit_iterator_new(it, commit);
cleanup:
- git__free(notes_ref);
+ git_str_dispose(¬es_ref);
git_commit_free(commit);
return error;
}
int git_note_next(
- git_oid* note_id,
- git_oid* annotated_id,
+ git_oid *note_id,
+ git_oid *annotated_id,
git_note_iterator *it)
{
int error;
git_oid_cpy(note_id, &item->id);
- if (!(error = process_entry_path(item->path, annotated_id)))
- git_iterator_advance(NULL, it);
+ if ((error = process_entry_path(item->path, annotated_id)) < 0)
+ return error;
- return error;
+ if ((error = git_iterator_advance(NULL, it)) < 0 && error != GIT_ITEROVER)
+ return error;
+
+ return 0;
}