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_sys_git_diff_h__ 8 #define INCLUDE_sys_git_diff_h__ 9 10 #include "git2/common.h" 11 #include "git2/types.h" 12 #include "git2/oid.h" 13 #include "git2/diff.h" 14 #include "git2/status.h" 15 16 /** 17 * @file git2/sys/diff.h 18 * @brief Low-level Git diff utilities 19 * @ingroup Git 20 * @{ 21 */ 22 GIT_BEGIN_DECL 23 24 /** 25 * Diff print callback that writes to a git_buf. 26 * 27 * This function is provided not for you to call it directly, but instead 28 * so you can use it as a function pointer to the `git_diff_print` or 29 * `git_patch_print` APIs. When using those APIs, you specify a callback 30 * to actually handle the diff and/or patch data. 31 * 32 * Use this callback to easily write that data to a `git_buf` buffer. You 33 * must pass a `git_buf *` value as the payload to the `git_diff_print` 34 * and/or `git_patch_print` function. The data will be appended to the 35 * buffer (after any existing content). 36 */ 37 GIT_EXTERN(int) git_diff_print_callback__to_buf( 38 const git_diff_delta *delta, 39 const git_diff_hunk *hunk, 40 const git_diff_line *line, 41 void *payload); /**< payload must be a `git_buf *` */ 42 43 /** 44 * Diff print callback that writes to stdio FILE handle. 45 * 46 * This function is provided not for you to call it directly, but instead 47 * so you can use it as a function pointer to the `git_diff_print` or 48 * `git_patch_print` APIs. When using those APIs, you specify a callback 49 * to actually handle the diff and/or patch data. 50 * 51 * Use this callback to easily write that data to a stdio FILE handle. You 52 * must pass a `FILE *` value (such as `stdout` or `stderr` or the return 53 * value from `fopen()`) as the payload to the `git_diff_print` 54 * and/or `git_patch_print` function. If you pass NULL, this will write 55 * data to `stdout`. 56 */ 57 GIT_EXTERN(int) git_diff_print_callback__to_file_handle( 58 const git_diff_delta *delta, 59 const git_diff_hunk *hunk, 60 const git_diff_line *line, 61 void *payload); /**< payload must be a `FILE *` */ 62 63 64 /** 65 * Performance data from diffing 66 */ 67 typedef struct { 68 unsigned int version; 69 size_t stat_calls; /**< Number of stat() calls performed */ 70 size_t oid_calculations; /**< Number of ID calculations */ 71 } git_diff_perfdata; 72 73 #define GIT_DIFF_PERFDATA_VERSION 1 74 #define GIT_DIFF_PERFDATA_INIT {GIT_DIFF_PERFDATA_VERSION,0,0} 75 76 /** 77 * Get performance data for a diff object. 78 * 79 * @param out Structure to be filled with diff performance data 80 * @param diff Diff to read performance data from 81 * @return 0 for success, <0 for error 82 */ 83 GIT_EXTERN(int) git_diff_get_perfdata( 84 git_diff_perfdata *out, const git_diff *diff); 85 86 /** 87 * Get performance data for diffs from a git_status_list 88 */ 89 GIT_EXTERN(int) git_status_list_get_perfdata( 90 git_diff_perfdata *out, const git_status_list *status); 91 92 /** @} */ 93 GIT_END_DECL 94 #endif 95