diff_patch.h 2.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * 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_diff_patch_h__
#define INCLUDE_diff_patch_h__

#include "common.h"
#include "diff.h"
#include "diff_file.h"
#include "array.h"
14
#include "git2/patch.h"
15

16 17 18 19 20 21 22 23 24 25 26
 /* cached information about a hunk in a diff */
typedef struct diff_patch_hunk {
	git_diff_hunk hunk;
	size_t line_start;
	size_t line_count;
} diff_patch_hunk;

enum {
	GIT_DIFF_PATCH_ALLOCATED = (1 << 0),
	GIT_DIFF_PATCH_INITIALIZED = (1 << 1),
	GIT_DIFF_PATCH_LOADED = (1 << 2),
27
	/* the two sides are different */
28
	GIT_DIFF_PATCH_DIFFABLE = (1 << 3),
29
	/* the difference between the two sides has been computed */
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	GIT_DIFF_PATCH_DIFFED = (1 << 4),
	GIT_DIFF_PATCH_FLATTENED = (1 << 5),
};

struct git_patch {
	git_refcount rc;
	git_diff *diff; /* for refcount purposes, maybe NULL for blob diffs */
	git_diff_options diff_opts;
	git_diff_delta *delta;
	size_t delta_index;
	git_diff_file_content ofile;
	git_diff_file_content nfile;
	uint32_t flags;
	git_diff_binary binary;
	git_array_t(diff_patch_hunk) hunks;
	git_array_t(git_diff_line)   lines;
	size_t content_size, context_size, header_size;
	git_pool flattened;
};

50
extern git_diff *git_patch__diff(git_patch *);
51

52
extern git_diff_driver *git_patch__driver(git_patch *);
53

54 55
extern void git_patch__old_data(char **, size_t *, git_patch *);
extern void git_patch__new_data(char **, size_t *, git_patch *);
56

57 58
extern int git_patch__invoke_callbacks(
	git_patch *patch,
59
	git_diff_file_cb file_cb,
60
	git_diff_binary_cb binary_cb,
61
	git_diff_hunk_cb hunk_cb,
62
	git_diff_line_cb line_cb,
63
	void *payload);
64 65 66 67 68

typedef struct git_diff_output git_diff_output;
struct git_diff_output {
	/* these callbacks are issued with the diff data */
	git_diff_file_cb file_cb;
69
	git_diff_binary_cb binary_cb;
70
	git_diff_hunk_cb hunk_cb;
71
	git_diff_line_cb data_cb;
72 73 74 75 76 77 78 79
	void *payload;

	/* this records the actual error in cases where it may be obscured */
	int error;

	/* this callback is used to do the diff and drive the other callbacks.
	 * see diff_xdiff.h for how to use this in practice for now.
	 */
80
	int (*diff_cb)(git_diff_output *output, git_patch *patch);
81 82 83
};

#endif