summaryrefslogtreecommitdiff
path: root/src/patch.h
blob: ecab570d5f4703828cf1cba7e432e25335546afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* 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.
*/
#ifndef INCLUDE_patch_h__
#define INCLUDE_patch_h__

#include "git2/patch.h"
#include "array.h"

/* cached information about a hunk in a patch */
typedef struct git_patch_hunk {
	git_diff_hunk hunk;
	size_t line_start;
	size_t line_count;
} git_patch_hunk;

struct git_patch {
	git_refcount rc;

	git_repository *repo; /* may be null */

	git_diff_options diff_opts;

	git_diff_delta *delta;
	git_diff_binary binary;
	git_array_t(git_patch_hunk) hunks;
	git_array_t(git_diff_line) lines;

	size_t header_size;
	size_t content_size;
	size_t context_size;

	const git_diff_file *(*newfile)(git_patch *patch);
	const git_diff_file *(*oldfile)(git_patch *patch);
	void (*free_fn)(git_patch *patch);
};

extern int git_patch__invoke_callbacks(
	git_patch *patch,
	git_diff_file_cb file_cb,
	git_diff_binary_cb binary_cb,
	git_diff_hunk_cb hunk_cb,
	git_diff_line_cb line_cb,
	void *payload);

extern int git_patch_line_stats(
	size_t *total_ctxt,
	size_t *total_adds,
	size_t *total_dels,
	const git_patch *patch);

extern void git_patch_free(git_patch *patch);

#endif