File: diff.h

package info (click to toggle)
libgit2 1.9.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 60,804 kB
  • sloc: ansic: 203,436; javascript: 2,458; sh: 1,763; python: 384; perl: 99; php: 65; makefile: 33
file content (114 lines) | stat: -rw-r--r-- 3,692 bytes parent folder | download | duplicates (2)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * 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_sys_git_diff_h__
#define INCLUDE_sys_git_diff_h__

#include "git2/common.h"
#include "git2/types.h"
#include "git2/oid.h"
#include "git2/diff.h"
#include "git2/status.h"

/**
 * @file git2/sys/diff.h
 * @brief Low-level diff utilities
 * @ingroup Git
 * @{
 */
GIT_BEGIN_DECL

/**
 * Diff print callback that writes to a git_buf.
 *
 * This function is provided not for you to call it directly, but instead
 * so you can use it as a function pointer to the `git_diff_print` or
 * `git_patch_print` APIs.  When using those APIs, you specify a callback
 * to actually handle the diff and/or patch data.
 *
 * Use this callback to easily write that data to a `git_buf` buffer.  You
 * must pass a `git_buf *` value as the payload to the `git_diff_print`
 * and/or `git_patch_print` function.  The data will be appended to the
 * buffer (after any existing content).
 *
 * @param delta the delta being processed
 * @param hunk the hunk being processed
 * @param line the line being processed
 * @param payload the payload provided by the diff generator
 * @return 0 on success or an error code
 */
GIT_EXTERN(int) git_diff_print_callback__to_buf(
	const git_diff_delta *delta,
	const git_diff_hunk *hunk,
	const git_diff_line *line,
	void *payload); /**< payload must be a `git_buf *` */

/**
 * Diff print callback that writes to stdio FILE handle.
 *
 * This function is provided not for you to call it directly, but instead
 * so you can use it as a function pointer to the `git_diff_print` or
 * `git_patch_print` APIs.  When using those APIs, you specify a callback
 * to actually handle the diff and/or patch data.
 *
 * Use this callback to easily write that data to a stdio FILE handle.  You
 * must pass a `FILE *` value (such as `stdout` or `stderr` or the return
 * value from `fopen()`) as the payload to the `git_diff_print`
 * and/or `git_patch_print` function.  If you pass NULL, this will write
 * data to `stdout`.
 *
 * @param delta the delta being processed
 * @param hunk the hunk being processed
 * @param line the line being processed
 * @param payload the payload provided by the diff generator
 * @return 0 on success or an error code
 */
GIT_EXTERN(int) git_diff_print_callback__to_file_handle(
	const git_diff_delta *delta,
	const git_diff_hunk *hunk,
	const git_diff_line *line,
	void *payload); /**< payload must be a `FILE *` */


/**
 * Performance data from diffing
 */
typedef struct {
	unsigned int version;
	size_t stat_calls; /**< Number of stat() calls performed */
	size_t oid_calculations; /**< Number of ID calculations */
} git_diff_perfdata;

/** Current version for the `git_diff_perfdata_options` structure */
#define GIT_DIFF_PERFDATA_VERSION 1

/** Static constructor for `git_diff_perfdata_options` */
#define GIT_DIFF_PERFDATA_INIT {GIT_DIFF_PERFDATA_VERSION,0,0}

/**
 * Get performance data for a diff object.
 *
 * @param out Structure to be filled with diff performance data
 * @param diff Diff to read performance data from
 * @return 0 for success, <0 for error
 */
GIT_EXTERN(int) git_diff_get_perfdata(
	git_diff_perfdata *out, const git_diff *diff);

/**
 * Get performance data for diffs from a git_status_list
 *
 * @param out Structure to be filled with diff performance data
 * @param status Diff to read performance data from
 * @return 0 for success, <0 for error
 */
GIT_EXTERN(int) git_status_list_get_perfdata(
	git_diff_perfdata *out, const git_status_list *status);

/** @} */
GIT_END_DECL

#endif