]> git.proxmox.com Git - libgit2.git/blobdiff - src/patch.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / patch.c
index 9b7c9c64c44affbf7c6137b8f509e34cb045a51b..a30546f3ce6aa74431c7070fcb256d02556259b7 100644 (file)
@@ -1,7 +1,14 @@
-#include "git2/patch.h"
-#include "diff.h"
+/*
+* Copyright (C) the libgit2 contributors. All rights reserved.
+*
+* This file is part of libgit2, distributed under the GNU GPL v2 with
+* a Linking Exception. For full terms see the included COPYING file.
+*/
+
 #include "patch.h"
 
+#include "git2/patch.h"
+#include "diff.h"
 
 int git_patch__invoke_callbacks(
        git_patch *patch,
@@ -58,7 +65,7 @@ size_t git_patch_size(
 {
        size_t out;
 
-       assert(patch);
+       GIT_ASSERT_ARG(patch);
 
        out = patch->content_size;
 
@@ -69,15 +76,15 @@ size_t git_patch_size(
                out += patch->header_size;
 
        if (include_file_headers) {
-               git_buf file_header = GIT_BUF_INIT;
+               git_str file_header = GIT_STR_INIT;
 
                if (git_diff_delta__format_file_header(
-                       &file_header, patch->delta, NULL, NULL, 0) < 0)
-                       giterr_clear();
+                       &file_header, patch->delta, NULL, NULL, 0, true) < 0)
+                       git_error_clear();
                else
-                       out += git_buf_len(&file_header);
+                       out += git_str_len(&file_header);
 
-               git_buf_free(&file_header);
+               git_str_dispose(&file_header);
        }
 
        return out;
@@ -122,19 +129,19 @@ int git_patch_line_stats(
 
 const git_diff_delta *git_patch_get_delta(const git_patch *patch)
 {
-       assert(patch);
+       GIT_ASSERT_ARG_WITH_RETVAL(patch, NULL);
        return patch->delta;
 }
 
 size_t git_patch_num_hunks(const git_patch *patch)
 {
-       assert(patch);
+       GIT_ASSERT_ARG(patch);
        return git_array_size(patch->hunks);
 }
 
 static int patch_error_outofrange(const char *thing)
 {
-       giterr_set(GITERR_INVALID, "patch %s index out of range", thing);
+       git_error_set(GIT_ERROR_INVALID, "patch %s index out of range", thing);
        return GIT_ENOTFOUND;
 }
 
@@ -145,7 +152,7 @@ int git_patch_get_hunk(
        size_t hunk_idx)
 {
        git_patch_hunk *hunk;
-       assert(patch);
+       GIT_ASSERT_ARG(patch);
 
        hunk = git_array_get(patch->hunks, hunk_idx);
 
@@ -163,7 +170,7 @@ int git_patch_get_hunk(
 int git_patch_num_lines_in_hunk(const git_patch *patch, size_t hunk_idx)
 {
        git_patch_hunk *hunk;
-       assert(patch);
+       GIT_ASSERT_ARG(patch);
 
        if (!(hunk = git_array_get(patch->hunks, hunk_idx)))
                return patch_error_outofrange("hunk");
@@ -179,7 +186,7 @@ int git_patch_get_line_in_hunk(
        git_patch_hunk *hunk;
        git_diff_line *line;
 
-       assert(patch);
+       GIT_ASSERT_ARG(patch);
 
        if (!(hunk = git_array_get(patch->hunks, hunk_idx))) {
                if (out) *out = NULL;
@@ -197,9 +204,16 @@ int git_patch_get_line_in_hunk(
        return 0;
 }
 
+git_repository *git_patch_owner(const git_patch *patch)
+{
+       return patch->repo;
+}
+
 int git_patch_from_diff(git_patch **out, git_diff *diff, size_t idx)
 {
-       assert(out && diff && diff->patch_fn);
+       GIT_ASSERT_ARG(out);
+       GIT_ASSERT_ARG(diff);
+       GIT_ASSERT_ARG(diff->patch_fn);
        return diff->patch_fn(out, diff, idx);
 }