Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../include/git2
File: patch.h
/*
[0] Fix | Delete
* Copyright (C) the libgit2 contributors. All rights reserved.
[1] Fix | Delete
*
[2] Fix | Delete
* This file is part of libgit2, distributed under the GNU GPL v2 with
[3] Fix | Delete
* a Linking Exception. For full terms see the included COPYING file.
[4] Fix | Delete
*/
[5] Fix | Delete
#ifndef INCLUDE_git_patch_h__
[6] Fix | Delete
#define INCLUDE_git_patch_h__
[7] Fix | Delete
[8] Fix | Delete
#include "common.h"
[9] Fix | Delete
#include "types.h"
[10] Fix | Delete
#include "oid.h"
[11] Fix | Delete
#include "diff.h"
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* @file git2/patch.h
[15] Fix | Delete
* @brief Patch handling routines.
[16] Fix | Delete
* @ingroup Git
[17] Fix | Delete
* @{
[18] Fix | Delete
*/
[19] Fix | Delete
GIT_BEGIN_DECL
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* The diff patch is used to store all the text diffs for a delta.
[23] Fix | Delete
*
[24] Fix | Delete
* You can easily loop over the content of patches and get information about
[25] Fix | Delete
* them.
[26] Fix | Delete
*/
[27] Fix | Delete
typedef struct git_patch git_patch;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Return a patch for an entry in the diff list.
[31] Fix | Delete
*
[32] Fix | Delete
* The `git_patch` is a newly created object contains the text diffs
[33] Fix | Delete
* for the delta. You have to call `git_patch_free()` when you are
[34] Fix | Delete
* done with it. You can use the patch object to loop over all the hunks
[35] Fix | Delete
* and lines in the diff of the one delta.
[36] Fix | Delete
*
[37] Fix | Delete
* For an unchanged file or a binary file, no `git_patch` will be
[38] Fix | Delete
* created, the output will be set to NULL, and the `binary` flag will be
[39] Fix | Delete
* set true in the `git_diff_delta` structure.
[40] Fix | Delete
*
[41] Fix | Delete
* It is okay to pass NULL for either of the output parameters; if you pass
[42] Fix | Delete
* NULL for the `git_patch`, then the text diff will not be calculated.
[43] Fix | Delete
*
[44] Fix | Delete
* @param out Output parameter for the delta patch object
[45] Fix | Delete
* @param diff Diff list object
[46] Fix | Delete
* @param idx Index into diff list
[47] Fix | Delete
* @return 0 on success, other value < 0 on error
[48] Fix | Delete
*/
[49] Fix | Delete
GIT_EXTERN(int) git_patch_from_diff(
[50] Fix | Delete
git_patch **out, git_diff *diff, size_t idx);
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Directly generate a patch from the difference between two blobs.
[54] Fix | Delete
*
[55] Fix | Delete
* This is just like `git_diff_blobs()` except it generates a patch object
[56] Fix | Delete
* for the difference instead of directly making callbacks. You can use the
[57] Fix | Delete
* standard `git_patch` accessor functions to read the patch data, and
[58] Fix | Delete
* you must call `git_patch_free()` on the patch when done.
[59] Fix | Delete
*
[60] Fix | Delete
* @param out The generated patch; NULL on error
[61] Fix | Delete
* @param old_blob Blob for old side of diff, or NULL for empty blob
[62] Fix | Delete
* @param old_as_path Treat old blob as if it had this filename; can be NULL
[63] Fix | Delete
* @param new_blob Blob for new side of diff, or NULL for empty blob
[64] Fix | Delete
* @param new_as_path Treat new blob as if it had this filename; can be NULL
[65] Fix | Delete
* @param opts Options for diff, or NULL for default options
[66] Fix | Delete
* @return 0 on success or error code < 0
[67] Fix | Delete
*/
[68] Fix | Delete
GIT_EXTERN(int) git_patch_from_blobs(
[69] Fix | Delete
git_patch **out,
[70] Fix | Delete
const git_blob *old_blob,
[71] Fix | Delete
const char *old_as_path,
[72] Fix | Delete
const git_blob *new_blob,
[73] Fix | Delete
const char *new_as_path,
[74] Fix | Delete
const git_diff_options *opts);
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Directly generate a patch from the difference between a blob and a buffer.
[78] Fix | Delete
*
[79] Fix | Delete
* This is just like `git_diff_blob_to_buffer()` except it generates a patch
[80] Fix | Delete
* object for the difference instead of directly making callbacks. You can
[81] Fix | Delete
* use the standard `git_patch` accessor functions to read the patch
[82] Fix | Delete
* data, and you must call `git_patch_free()` on the patch when done.
[83] Fix | Delete
*
[84] Fix | Delete
* @param out The generated patch; NULL on error
[85] Fix | Delete
* @param old_blob Blob for old side of diff, or NULL for empty blob
[86] Fix | Delete
* @param old_as_path Treat old blob as if it had this filename; can be NULL
[87] Fix | Delete
* @param buffer Raw data for new side of diff, or NULL for empty
[88] Fix | Delete
* @param buffer_len Length of raw data for new side of diff
[89] Fix | Delete
* @param buffer_as_path Treat buffer as if it had this filename; can be NULL
[90] Fix | Delete
* @param opts Options for diff, or NULL for default options
[91] Fix | Delete
* @return 0 on success or error code < 0
[92] Fix | Delete
*/
[93] Fix | Delete
GIT_EXTERN(int) git_patch_from_blob_and_buffer(
[94] Fix | Delete
git_patch **out,
[95] Fix | Delete
const git_blob *old_blob,
[96] Fix | Delete
const char *old_as_path,
[97] Fix | Delete
const void *buffer,
[98] Fix | Delete
size_t buffer_len,
[99] Fix | Delete
const char *buffer_as_path,
[100] Fix | Delete
const git_diff_options *opts);
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Directly generate a patch from the difference between two buffers.
[104] Fix | Delete
*
[105] Fix | Delete
* This is just like `git_diff_buffers()` except it generates a patch
[106] Fix | Delete
* object for the difference instead of directly making callbacks. You can
[107] Fix | Delete
* use the standard `git_patch` accessor functions to read the patch
[108] Fix | Delete
* data, and you must call `git_patch_free()` on the patch when done.
[109] Fix | Delete
*
[110] Fix | Delete
* @param out The generated patch; NULL on error
[111] Fix | Delete
* @param old_buffer Raw data for old side of diff, or NULL for empty
[112] Fix | Delete
* @param old_len Length of the raw data for old side of the diff
[113] Fix | Delete
* @param old_as_path Treat old buffer as if it had this filename; can be NULL
[114] Fix | Delete
* @param new_buffer Raw data for new side of diff, or NULL for empty
[115] Fix | Delete
* @param new_len Length of raw data for new side of diff
[116] Fix | Delete
* @param new_as_path Treat buffer as if it had this filename; can be NULL
[117] Fix | Delete
* @param opts Options for diff, or NULL for default options
[118] Fix | Delete
* @return 0 on success or error code < 0
[119] Fix | Delete
*/
[120] Fix | Delete
GIT_EXTERN(int) git_patch_from_buffers(
[121] Fix | Delete
git_patch **out,
[122] Fix | Delete
const void *old_buffer,
[123] Fix | Delete
size_t old_len,
[124] Fix | Delete
const char *old_as_path,
[125] Fix | Delete
const void *new_buffer,
[126] Fix | Delete
size_t new_len,
[127] Fix | Delete
const char *new_as_path,
[128] Fix | Delete
const git_diff_options *opts);
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Free a git_patch object.
[132] Fix | Delete
*/
[133] Fix | Delete
GIT_EXTERN(void) git_patch_free(git_patch *patch);
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* Get the delta associated with a patch. This delta points to internal
[137] Fix | Delete
* data and you do not have to release it when you are done with it.
[138] Fix | Delete
*/
[139] Fix | Delete
GIT_EXTERN(const git_diff_delta *) git_patch_get_delta(const git_patch *patch);
[140] Fix | Delete
[141] Fix | Delete
/**
[142] Fix | Delete
* Get the number of hunks in a patch
[143] Fix | Delete
*/
[144] Fix | Delete
GIT_EXTERN(size_t) git_patch_num_hunks(const git_patch *patch);
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Get line counts of each type in a patch.
[148] Fix | Delete
*
[149] Fix | Delete
* This helps imitate a diff --numstat type of output. For that purpose,
[150] Fix | Delete
* you only need the `total_additions` and `total_deletions` values, but we
[151] Fix | Delete
* include the `total_context` line count in case you want the total number
[152] Fix | Delete
* of lines of diff output that will be generated.
[153] Fix | Delete
*
[154] Fix | Delete
* All outputs are optional. Pass NULL if you don't need a particular count.
[155] Fix | Delete
*
[156] Fix | Delete
* @param total_context Count of context lines in output, can be NULL.
[157] Fix | Delete
* @param total_additions Count of addition lines in output, can be NULL.
[158] Fix | Delete
* @param total_deletions Count of deletion lines in output, can be NULL.
[159] Fix | Delete
* @param patch The git_patch object
[160] Fix | Delete
* @return 0 on success, <0 on error
[161] Fix | Delete
*/
[162] Fix | Delete
GIT_EXTERN(int) git_patch_line_stats(
[163] Fix | Delete
size_t *total_context,
[164] Fix | Delete
size_t *total_additions,
[165] Fix | Delete
size_t *total_deletions,
[166] Fix | Delete
const git_patch *patch);
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Get the information about a hunk in a patch
[170] Fix | Delete
*
[171] Fix | Delete
* Given a patch and a hunk index into the patch, this returns detailed
[172] Fix | Delete
* information about that hunk. Any of the output pointers can be passed
[173] Fix | Delete
* as NULL if you don't care about that particular piece of information.
[174] Fix | Delete
*
[175] Fix | Delete
* @param out Output pointer to git_diff_hunk of hunk
[176] Fix | Delete
* @param lines_in_hunk Output count of total lines in this hunk
[177] Fix | Delete
* @param patch Input pointer to patch object
[178] Fix | Delete
* @param hunk_idx Input index of hunk to get information about
[179] Fix | Delete
* @return 0 on success, GIT_ENOTFOUND if hunk_idx out of range, <0 on error
[180] Fix | Delete
*/
[181] Fix | Delete
GIT_EXTERN(int) git_patch_get_hunk(
[182] Fix | Delete
const git_diff_hunk **out,
[183] Fix | Delete
size_t *lines_in_hunk,
[184] Fix | Delete
git_patch *patch,
[185] Fix | Delete
size_t hunk_idx);
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Get the number of lines in a hunk.
[189] Fix | Delete
*
[190] Fix | Delete
* @param patch The git_patch object
[191] Fix | Delete
* @param hunk_idx Index of the hunk
[192] Fix | Delete
* @return Number of lines in hunk or GIT_ENOTFOUND if invalid hunk index
[193] Fix | Delete
*/
[194] Fix | Delete
GIT_EXTERN(int) git_patch_num_lines_in_hunk(
[195] Fix | Delete
const git_patch *patch,
[196] Fix | Delete
size_t hunk_idx);
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Get data about a line in a hunk of a patch.
[200] Fix | Delete
*
[201] Fix | Delete
* Given a patch, a hunk index, and a line index in the hunk, this
[202] Fix | Delete
* will return a lot of details about that line. If you pass a hunk
[203] Fix | Delete
* index larger than the number of hunks or a line index larger than
[204] Fix | Delete
* the number of lines in the hunk, this will return -1.
[205] Fix | Delete
*
[206] Fix | Delete
* @param out The git_diff_line data for this line
[207] Fix | Delete
* @param patch The patch to look in
[208] Fix | Delete
* @param hunk_idx The index of the hunk
[209] Fix | Delete
* @param line_of_hunk The index of the line in the hunk
[210] Fix | Delete
* @return 0 on success, <0 on failure
[211] Fix | Delete
*/
[212] Fix | Delete
GIT_EXTERN(int) git_patch_get_line_in_hunk(
[213] Fix | Delete
const git_diff_line **out,
[214] Fix | Delete
git_patch *patch,
[215] Fix | Delete
size_t hunk_idx,
[216] Fix | Delete
size_t line_of_hunk);
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Look up size of patch diff data in bytes
[220] Fix | Delete
*
[221] Fix | Delete
* This returns the raw size of the patch data. This only includes the
[222] Fix | Delete
* actual data from the lines of the diff, not the file or hunk headers.
[223] Fix | Delete
*
[224] Fix | Delete
* If you pass `include_context` as true (non-zero), this will be the size
[225] Fix | Delete
* of all of the diff output; if you pass it as false (zero), this will
[226] Fix | Delete
* only include the actual changed lines (as if `context_lines` was 0).
[227] Fix | Delete
*
[228] Fix | Delete
* @param patch A git_patch representing changes to one file
[229] Fix | Delete
* @param include_context Include context lines in size if non-zero
[230] Fix | Delete
* @param include_hunk_headers Include hunk header lines if non-zero
[231] Fix | Delete
* @param include_file_headers Include file header lines if non-zero
[232] Fix | Delete
* @return The number of bytes of data
[233] Fix | Delete
*/
[234] Fix | Delete
GIT_EXTERN(size_t) git_patch_size(
[235] Fix | Delete
git_patch *patch,
[236] Fix | Delete
int include_context,
[237] Fix | Delete
int include_hunk_headers,
[238] Fix | Delete
int include_file_headers);
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Serialize the patch to text via callback.
[242] Fix | Delete
*
[243] Fix | Delete
* Returning a non-zero value from the callback will terminate the iteration
[244] Fix | Delete
* and return that value to the caller.
[245] Fix | Delete
*
[246] Fix | Delete
* @param patch A git_patch representing changes to one file
[247] Fix | Delete
* @param print_cb Callback function to output lines of the patch. Will be
[248] Fix | Delete
* called for file headers, hunk headers, and diff lines.
[249] Fix | Delete
* @param payload Reference pointer that will be passed to your callbacks.
[250] Fix | Delete
* @return 0 on success, non-zero callback return value, or error code
[251] Fix | Delete
*/
[252] Fix | Delete
GIT_EXTERN(int) git_patch_print(
[253] Fix | Delete
git_patch *patch,
[254] Fix | Delete
git_diff_line_cb print_cb,
[255] Fix | Delete
void *payload);
[256] Fix | Delete
[257] Fix | Delete
/**
[258] Fix | Delete
* Get the content of a patch as a single diff text.
[259] Fix | Delete
*
[260] Fix | Delete
* @param out The git_buf to be filled in
[261] Fix | Delete
* @param patch A git_patch representing changes to one file
[262] Fix | Delete
* @return 0 on success, <0 on failure.
[263] Fix | Delete
*/
[264] Fix | Delete
GIT_EXTERN(int) git_patch_to_buf(
[265] Fix | Delete
git_buf *out,
[266] Fix | Delete
git_patch *patch);
[267] Fix | Delete
[268] Fix | Delete
GIT_END_DECL
[269] Fix | Delete
[270] Fix | Delete
/**@}*/
[271] Fix | Delete
[272] Fix | Delete
#endif
[273] Fix | Delete
[274] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function