]> git.proxmox.com Git - libgit2.git/blob - src/patch.h
Merge pull request #3223 from ethomson/apply
[libgit2.git] / src / patch.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7 #ifndef INCLUDE_patch_h__
8 #define INCLUDE_patch_h__
9
10 #include "git2/patch.h"
11 #include "array.h"
12
13 /* cached information about a hunk in a patch */
14 typedef struct git_patch_hunk {
15 git_diff_hunk hunk;
16 size_t line_start;
17 size_t line_count;
18 } git_patch_hunk;
19
20 struct git_patch {
21 git_refcount rc;
22
23 git_repository *repo; /* may be null */
24
25 git_diff_options diff_opts;
26
27 git_diff_delta *delta;
28 git_diff_binary binary;
29 git_array_t(git_patch_hunk) hunks;
30 git_array_t(git_diff_line) lines;
31
32 size_t header_size;
33 size_t content_size;
34 size_t context_size;
35
36 void (*free_fn)(git_patch *patch);
37 };
38
39 extern int git_patch__invoke_callbacks(
40 git_patch *patch,
41 git_diff_file_cb file_cb,
42 git_diff_binary_cb binary_cb,
43 git_diff_hunk_cb hunk_cb,
44 git_diff_line_cb line_cb,
45 void *payload);
46
47 extern int git_patch_line_stats(
48 size_t *total_ctxt,
49 size_t *total_adds,
50 size_t *total_dels,
51 const git_patch *patch);
52
53 /** Options for parsing patch files. */
54 typedef struct {
55 /**
56 * The length of the prefix (in path segments) for the filenames.
57 * This prefix will be removed when looking for files. The default is 1.
58 */
59 uint32_t prefix_len;
60 } git_patch_options;
61
62 #define GIT_PATCH_OPTIONS_INIT { 1 }
63
64 extern void git_patch_free(git_patch *patch);
65
66 #endif