2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_git_diff_h__
8 #define INCLUDE_git_diff_h__
18 * @brief Git tree and file differencing routines.
25 * Flags for diff options. A combination of these flags can be passed
26 * in via the `flags` value in the `git_diff_options`.
29 /** Normal diff, the default */
33 * Options controlling which files will be in the diff
36 /** Reverse the sides of the diff */
37 GIT_DIFF_REVERSE
= (1u << 0),
39 /** Include ignored files in the diff */
40 GIT_DIFF_INCLUDE_IGNORED
= (1u << 1),
42 /** Even with GIT_DIFF_INCLUDE_IGNORED, an entire ignored directory
43 * will be marked with only a single entry in the diff; this flag
44 * adds all files under the directory as IGNORED entries, too.
46 GIT_DIFF_RECURSE_IGNORED_DIRS
= (1u << 2),
48 /** Include untracked files in the diff */
49 GIT_DIFF_INCLUDE_UNTRACKED
= (1u << 3),
51 /** Even with GIT_DIFF_INCLUDE_UNTRACKED, an entire untracked
52 * directory will be marked with only a single entry in the diff
53 * (a la what core Git does in `git status`); this flag adds *all*
54 * files under untracked directories as UNTRACKED entries, too.
56 GIT_DIFF_RECURSE_UNTRACKED_DIRS
= (1u << 4),
58 /** Include unmodified files in the diff */
59 GIT_DIFF_INCLUDE_UNMODIFIED
= (1u << 5),
61 /** Normally, a type change between files will be converted into a
62 * DELETED record for the old and an ADDED record for the new; this
63 * options enabled the generation of TYPECHANGE delta records.
65 GIT_DIFF_INCLUDE_TYPECHANGE
= (1u << 6),
67 /** Even with GIT_DIFF_INCLUDE_TYPECHANGE, blob->tree changes still
68 * generally show as a DELETED blob. This flag tries to correctly
69 * label blob->tree transitions as TYPECHANGE records with new_file's
70 * mode set to tree. Note: the tree SHA will not be available.
72 GIT_DIFF_INCLUDE_TYPECHANGE_TREES
= (1u << 7),
74 /** Ignore file mode changes */
75 GIT_DIFF_IGNORE_FILEMODE
= (1u << 8),
77 /** Treat all submodules as unmodified */
78 GIT_DIFF_IGNORE_SUBMODULES
= (1u << 9),
80 /** Use case insensitive filename comparisons */
81 GIT_DIFF_IGNORE_CASE
= (1u << 10),
83 /** May be combined with `GIT_DIFF_IGNORE_CASE` to specify that a file
84 * that has changed case will be returned as an add/delete pair.
86 GIT_DIFF_INCLUDE_CASECHANGE
= (1u << 11),
88 /** If the pathspec is set in the diff options, this flags indicates
89 * that the paths will be treated as literal paths instead of
90 * fnmatch patterns. Each path in the list must either be a full
91 * path to a file or a directory. (A trailing slash indicates that
92 * the path will _only_ match a directory). If a directory is
93 * specified, all children will be included.
95 GIT_DIFF_DISABLE_PATHSPEC_MATCH
= (1u << 12),
97 /** Disable updating of the `binary` flag in delta records. This is
98 * useful when iterating over a diff if you don't need hunk and data
99 * callbacks and want to avoid having to load file completely.
101 GIT_DIFF_SKIP_BINARY_CHECK
= (1u << 13),
103 /** When diff finds an untracked directory, to match the behavior of
104 * core Git, it scans the contents for IGNORED and UNTRACKED files.
105 * If *all* contents are IGNORED, then the directory is IGNORED; if
106 * any contents are not IGNORED, then the directory is UNTRACKED.
107 * This is extra work that may not matter in many cases. This flag
108 * turns off that scan and immediately labels an untracked directory
109 * as UNTRACKED (changing the behavior to not match core Git).
111 GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS
= (1u << 14),
113 /** When diff finds a file in the working directory with stat
114 * information different from the index, but the OID ends up being the
115 * same, write the correct stat information into the index. Note:
116 * without this flag, diff will always leave the index untouched.
118 GIT_DIFF_UPDATE_INDEX
= (1u << 15),
120 /** Include unreadable files in the diff */
121 GIT_DIFF_INCLUDE_UNREADABLE
= (1u << 16),
123 /** Include unreadable files in the diff */
124 GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED
= (1u << 17),
127 * Options controlling how output will be generated
130 /** Use a heuristic that takes indentation and whitespace into account
131 * which generally can produce better diffs when dealing with ambiguous
134 GIT_DIFF_INDENT_HEURISTIC
= (1u << 18),
136 /** Ignore blank lines */
137 GIT_DIFF_IGNORE_BLANK_LINES
= (1u << 19),
139 /** Treat all files as text, disabling binary attributes & detection */
140 GIT_DIFF_FORCE_TEXT
= (1u << 20),
141 /** Treat all files as binary, disabling text diffs */
142 GIT_DIFF_FORCE_BINARY
= (1u << 21),
144 /** Ignore all whitespace */
145 GIT_DIFF_IGNORE_WHITESPACE
= (1u << 22),
146 /** Ignore changes in amount of whitespace */
147 GIT_DIFF_IGNORE_WHITESPACE_CHANGE
= (1u << 23),
148 /** Ignore whitespace at end of line */
149 GIT_DIFF_IGNORE_WHITESPACE_EOL
= (1u << 24),
151 /** When generating patch text, include the content of untracked
152 * files. This automatically turns on GIT_DIFF_INCLUDE_UNTRACKED but
153 * it does not turn on GIT_DIFF_RECURSE_UNTRACKED_DIRS. Add that
154 * flag if you want the content of every single UNTRACKED file.
156 GIT_DIFF_SHOW_UNTRACKED_CONTENT
= (1u << 25),
158 /** When generating output, include the names of unmodified files if
159 * they are included in the git_diff. Normally these are skipped in
160 * the formats that list files (e.g. name-only, name-status, raw).
161 * Even with this, these will not be included in patch format.
163 GIT_DIFF_SHOW_UNMODIFIED
= (1u << 26),
165 /** Use the "patience diff" algorithm */
166 GIT_DIFF_PATIENCE
= (1u << 28),
167 /** Take extra time to find minimal diff */
168 GIT_DIFF_MINIMAL
= (1u << 29),
170 /** Include the necessary deflate / delta information so that `git-apply`
171 * can apply given diff information to binary files.
173 GIT_DIFF_SHOW_BINARY
= (1u << 30),
177 * The diff object that contains all individual file deltas.
179 * A `diff` represents the cumulative list of differences between two
180 * snapshots of a repository (possibly filtered by a set of file name
183 * Calculating diffs is generally done in two phases: building a list of
184 * diffs then traversing it. This makes is easier to share logic across
185 * the various types of diffs (tree vs tree, workdir vs index, etc.), and
186 * also allows you to insert optional diff post-processing phases,
187 * such as rename detection, in between the steps. When you are done with
188 * a diff object, it must be freed.
190 * This is an opaque structure which will be allocated by one of the diff
191 * generator functions below (such as `git_diff_tree_to_tree`). You are
192 * responsible for releasing the object memory when done, using the
193 * `git_diff_free()` function.
196 typedef struct git_diff git_diff
;
199 * Flags for the delta object and the file objects on each side.
201 * These flags are used for both the `flags` value of the `git_diff_delta`
202 * and the flags for the `git_diff_file` objects representing the old and
203 * new sides of the delta. Values outside of this public range should be
204 * considered reserved for internal or future use.
207 GIT_DIFF_FLAG_BINARY
= (1u << 0), /**< file(s) treated as binary data */
208 GIT_DIFF_FLAG_NOT_BINARY
= (1u << 1), /**< file(s) treated as text data */
209 GIT_DIFF_FLAG_VALID_ID
= (1u << 2), /**< `id` value is known correct */
210 GIT_DIFF_FLAG_EXISTS
= (1u << 3), /**< file exists at this side of the delta */
214 * What type of change is described by a git_diff_delta?
216 * `GIT_DELTA_RENAMED` and `GIT_DELTA_COPIED` will only show up if you run
217 * `git_diff_find_similar()` on the diff object.
219 * `GIT_DELTA_TYPECHANGE` only shows up given `GIT_DIFF_INCLUDE_TYPECHANGE`
220 * in the option flags (otherwise type changes will be split into ADDED /
224 GIT_DELTA_UNMODIFIED
= 0, /**< no changes */
225 GIT_DELTA_ADDED
= 1, /**< entry does not exist in old version */
226 GIT_DELTA_DELETED
= 2, /**< entry does not exist in new version */
227 GIT_DELTA_MODIFIED
= 3, /**< entry content changed between old and new */
228 GIT_DELTA_RENAMED
= 4, /**< entry was renamed between old and new */
229 GIT_DELTA_COPIED
= 5, /**< entry was copied from another old entry */
230 GIT_DELTA_IGNORED
= 6, /**< entry is ignored item in workdir */
231 GIT_DELTA_UNTRACKED
= 7, /**< entry is untracked item in workdir */
232 GIT_DELTA_TYPECHANGE
= 8, /**< type of entry changed between old and new */
233 GIT_DELTA_UNREADABLE
= 9, /**< entry is unreadable */
234 GIT_DELTA_CONFLICTED
= 10, /**< entry in the index is conflicted */
238 * Description of one side of a delta.
240 * Although this is called a "file", it could represent a file, a symbolic
241 * link, a submodule commit id, or even a tree (although that only if you
242 * are tracking type changes or ignored/untracked directories).
246 * The `git_oid` of the item. If the entry represents an
247 * absent side of a diff (e.g. the `old_file` of a `GIT_DELTA_ADDED` delta),
248 * then the oid will be zeroes.
253 * The NUL-terminated path to the entry relative to the working
254 * directory of the repository.
259 * The size of the entry in bytes.
261 git_object_size_t size
;
264 * A combination of the `git_diff_flag_t` types
269 * Roughly, the stat() `st_mode` value for the item. This will
270 * be restricted to one of the `git_filemode_t` values.
275 * Represents the known length of the `id` field, when
276 * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this
277 * delta was created from reading a patch file, in which case it may be
278 * abbreviated to something reasonable, like 7 characters.
284 * Description of changes to one entry.
286 * A `delta` is a file pair with an old and new revision. The old version
287 * may be absent if the file was just created and the new version may be
288 * absent if the file was deleted. A diff is mostly just a list of deltas.
290 * When iterating over a diff, this will be passed to most callbacks and
291 * you can use the contents to understand exactly what has changed.
293 * The `old_file` represents the "from" side of the diff and the `new_file`
294 * represents to "to" side of the diff. What those means depend on the
295 * function that was used to generate the diff and will be documented below.
296 * You can also use the `GIT_DIFF_REVERSE` flag to flip it around.
298 * Although the two sides of the delta are named "old_file" and "new_file",
299 * they actually may correspond to entries that represent a file, a symbolic
300 * link, a submodule commit id, or even a tree (if you are tracking type
301 * changes or ignored/untracked directories).
303 * Under some circumstances, in the name of efficiency, not all fields will
304 * be filled in, but we generally try to fill in as much as possible. One
305 * example is that the "flags" field may not have either the `BINARY` or the
306 * `NOT_BINARY` flag set to avoid examining file contents if you do not pass
307 * in hunk and/or line callbacks to the diff foreach iteration function. It
308 * will just use the git attributes for those files.
310 * The similarity score is zero unless you call `git_diff_find_similar()`
311 * which does a similarity analysis of files in the diff. Use that
312 * function to do rename and copy detection, and to split heavily modified
313 * files in add/delete pairs. After that call, deltas with a status of
314 * GIT_DELTA_RENAMED or GIT_DELTA_COPIED will have a similarity score
315 * between 0 and 100 indicating how similar the old and new sides are.
317 * If you ask `git_diff_find_similar` to find heavily modified files to
318 * break, but to not *actually* break the records, then GIT_DELTA_MODIFIED
319 * records may have a non-zero similarity score if the self-similarity is
320 * below the split threshold. To display this value like core Git, invert
321 * the score (a la `printf("M%03d", 100 - delta->similarity)`).
325 uint32_t flags
; /**< git_diff_flag_t values */
326 uint16_t similarity
; /**< for RENAMED and COPIED, value 0-100 */
327 uint16_t nfiles
; /**< number of files in this delta */
328 git_diff_file old_file
;
329 git_diff_file new_file
;
333 * Diff notification callback function.
335 * The callback will be called for each file, just before the `git_diff_delta`
336 * gets inserted into the diff.
339 * - returns < 0, the diff process will be aborted.
340 * - returns > 0, the delta will not be inserted into the diff, but the
341 * diff process continues.
342 * - returns 0, the delta is inserted into the diff, and the diff process
345 typedef int GIT_CALLBACK(git_diff_notify_cb
)(
346 const git_diff
*diff_so_far
,
347 const git_diff_delta
*delta_to_add
,
348 const char *matched_pathspec
,
352 * Diff progress callback.
354 * Called before each file comparison.
356 * @param diff_so_far The diff being generated.
357 * @param old_path The path to the old file or NULL.
358 * @param new_path The path to the new file or NULL.
359 * @return Non-zero to abort the diff.
361 typedef int GIT_CALLBACK(git_diff_progress_cb
)(
362 const git_diff
*diff_so_far
,
363 const char *old_path
,
364 const char *new_path
,
368 * Structure describing options about how the diff should be executed.
370 * Setting all values of the structure to zero will yield the default
371 * values. Similarly, passing NULL for the options structure will
372 * give the defaults. The default values are marked below.
376 unsigned int version
; /**< version for the struct */
379 * A combination of `git_diff_option_t` values above.
380 * Defaults to GIT_DIFF_NORMAL
384 /* options controlling which files are in the diff */
386 /** Overrides the submodule ignore setting for all submodules in the diff. */
387 git_submodule_ignore_t ignore_submodules
;
390 * An array of paths / fnmatch patterns to constrain diff.
391 * All paths are included by default.
393 git_strarray pathspec
;
396 * An optional callback function, notifying the consumer of changes to
397 * the diff as new deltas are added.
399 git_diff_notify_cb notify_cb
;
402 * An optional callback function, notifying the consumer of which files
403 * are being examined as the diff is generated.
405 git_diff_progress_cb progress_cb
;
407 /** The payload to pass to the callback functions. */
410 /* options controlling how to diff text is generated */
413 * The number of unchanged lines that define the boundary of a hunk
414 * (and to display before and after). Defaults to 3.
416 uint32_t context_lines
;
418 * The maximum number of unchanged lines between hunk boundaries before
419 * the hunks will be merged into one. Defaults to 0.
421 uint32_t interhunk_lines
;
424 * The abbreviation length to use when formatting object ids.
425 * Defaults to the value of 'core.abbrev' from the config, or 7 if unset.
430 * A size (in bytes) above which a blob will be marked as binary
431 * automatically; pass a negative value to disable.
437 * The virtual "directory" prefix for old file names in hunk headers.
440 const char *old_prefix
;
443 * The virtual "directory" prefix for new file names in hunk headers.
446 const char *new_prefix
;
449 /* The current version of the diff options structure */
450 #define GIT_DIFF_OPTIONS_VERSION 1
452 /* Stack initializer for diff options. Alternatively use
453 * `git_diff_options_init` programmatic initialization.
455 #define GIT_DIFF_OPTIONS_INIT \
456 {GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3}
459 * Initialize git_diff_options structure
461 * Initializes a `git_diff_options` with default values. Equivalent to creating
462 * an instance with GIT_DIFF_OPTIONS_INIT.
464 * @param opts The `git_diff_options` struct to initialize.
465 * @param version The struct version; pass `GIT_DIFF_OPTIONS_VERSION`.
466 * @return Zero on success; -1 on failure.
468 GIT_EXTERN(int) git_diff_options_init(
469 git_diff_options
*opts
,
470 unsigned int version
);
473 * When iterating over a diff, callback that will be made per file.
475 * @param delta A pointer to the delta data for the file
476 * @param progress Goes from 0 to 1 over the diff
477 * @param payload User-specified pointer from foreach function
479 typedef int GIT_CALLBACK(git_diff_file_cb
)(
480 const git_diff_delta
*delta
,
484 #define GIT_DIFF_HUNK_HEADER_SIZE 128
487 * When producing a binary diff, the binary data returned will be
488 * either the deflated full ("literal") contents of the file, or
489 * the deflated binary delta between the two sides (whichever is
493 /** There is no binary delta. */
494 GIT_DIFF_BINARY_NONE
,
496 /** The binary data is the literal contents of the file. */
497 GIT_DIFF_BINARY_LITERAL
,
499 /** The binary data is the delta from one side to the other. */
500 GIT_DIFF_BINARY_DELTA
,
503 /** The contents of one of the files in a binary diff. */
505 /** The type of binary data for this file. */
506 git_diff_binary_t type
;
508 /** The binary data, deflated. */
511 /** The length of the binary data. */
514 /** The length of the binary data after inflation. */
516 } git_diff_binary_file
;
519 * Structure describing the binary contents of a diff.
521 * A `binary` file / delta is a file (or pair) for which no text diffs
522 * should be generated. A diff can contain delta entries that are
523 * binary, but no diff content will be output for those files. There is
524 * a base heuristic for binary detection and you can further tune the
525 * behavior with git attributes or diff flags and option settings.
529 * Whether there is data in this binary structure or not.
531 * If this is `1`, then this was produced and included binary content.
532 * If this is `0` then this was generated knowing only that a binary
533 * file changed but without providing the data, probably from a patch
534 * that said `Binary files a/file.txt and b/file.txt differ`.
536 unsigned int contains_data
;
537 git_diff_binary_file old_file
; /**< The contents of the old file. */
538 git_diff_binary_file new_file
; /**< The contents of the new file. */
542 * When iterating over a diff, callback that will be made for
543 * binary content within the diff.
545 typedef int GIT_CALLBACK(git_diff_binary_cb
)(
546 const git_diff_delta
*delta
,
547 const git_diff_binary
*binary
,
551 * Structure describing a hunk of a diff.
553 * A `hunk` is a span of modified lines in a delta along with some stable
554 * surrounding context. You can configure the amount of context and other
555 * properties of how hunks are generated. Each hunk also comes with a
556 * header that described where it starts and ends in both the old and new
557 * versions in the delta.
560 int old_start
; /**< Starting line number in old_file */
561 int old_lines
; /**< Number of lines in old_file */
562 int new_start
; /**< Starting line number in new_file */
563 int new_lines
; /**< Number of lines in new_file */
564 size_t header_len
; /**< Number of bytes in header text */
565 char header
[GIT_DIFF_HUNK_HEADER_SIZE
]; /**< Header text, NUL-byte terminated */
569 * When iterating over a diff, callback that will be made per hunk.
571 typedef int GIT_CALLBACK(git_diff_hunk_cb
)(
572 const git_diff_delta
*delta
,
573 const git_diff_hunk
*hunk
,
577 * Line origin constants.
579 * These values describe where a line came from and will be passed to
580 * the git_diff_line_cb when iterating over a diff. There are some
581 * special origin constants at the end that are used for the text
582 * output callbacks to demarcate lines that are actually part of
583 * the file or hunk headers.
586 /* These values will be sent to `git_diff_line_cb` along with the line */
587 GIT_DIFF_LINE_CONTEXT
= ' ',
588 GIT_DIFF_LINE_ADDITION
= '+',
589 GIT_DIFF_LINE_DELETION
= '-',
591 GIT_DIFF_LINE_CONTEXT_EOFNL
= '=', /**< Both files have no LF at end */
592 GIT_DIFF_LINE_ADD_EOFNL
= '>', /**< Old has no LF at end, new does */
593 GIT_DIFF_LINE_DEL_EOFNL
= '<', /**< Old has LF at end, new does not */
595 /* The following values will only be sent to a `git_diff_line_cb` when
596 * the content of a diff is being formatted through `git_diff_print`.
598 GIT_DIFF_LINE_FILE_HDR
= 'F',
599 GIT_DIFF_LINE_HUNK_HDR
= 'H',
600 GIT_DIFF_LINE_BINARY
= 'B' /**< For "Binary files x and y differ" */
604 * Structure describing a line (or data span) of a diff.
606 * A `line` is a range of characters inside a hunk. It could be a context
607 * line (i.e. in both old and new versions), an added line (i.e. only in
608 * the new version), or a removed line (i.e. only in the old version).
609 * Unfortunately, we don't know anything about the encoding of data in the
610 * file being diffed, so we cannot tell you much about the line content.
611 * Line data will not be NUL-byte terminated, however, because it will be
612 * just a span of bytes inside the larger file.
615 char origin
; /**< A git_diff_line_t value */
616 int old_lineno
; /**< Line number in old file or -1 for added line */
617 int new_lineno
; /**< Line number in new file or -1 for deleted line */
618 int num_lines
; /**< Number of newline characters in content */
619 size_t content_len
; /**< Number of bytes of data */
620 git_off_t content_offset
; /**< Offset in the original file to the content */
621 const char *content
; /**< Pointer to diff text, not NUL-byte terminated */
625 * When iterating over a diff, callback that will be made per text diff
626 * line. In this context, the provided range will be NULL.
628 * When printing a diff, callback that will be made to output each line
629 * of text. This uses some extra GIT_DIFF_LINE_... constants for output
630 * of lines of file and hunk headers.
632 typedef int GIT_CALLBACK(git_diff_line_cb
)(
633 const git_diff_delta
*delta
, /**< delta that contains this data */
634 const git_diff_hunk
*hunk
, /**< hunk containing this data */
635 const git_diff_line
*line
, /**< line data */
636 void *payload
); /**< user reference data */
639 * Flags to control the behavior of diff rename/copy detection.
642 /** Obey `diff.renames`. Overridden by any other GIT_DIFF_FIND_... flag. */
643 GIT_DIFF_FIND_BY_CONFIG
= 0,
645 /** Look for renames? (`--find-renames`) */
646 GIT_DIFF_FIND_RENAMES
= (1u << 0),
648 /** Consider old side of MODIFIED for renames? (`--break-rewrites=N`) */
649 GIT_DIFF_FIND_RENAMES_FROM_REWRITES
= (1u << 1),
651 /** Look for copies? (a la `--find-copies`). */
652 GIT_DIFF_FIND_COPIES
= (1u << 2),
654 /** Consider UNMODIFIED as copy sources? (`--find-copies-harder`).
656 * For this to work correctly, use GIT_DIFF_INCLUDE_UNMODIFIED when
657 * the initial `git_diff` is being generated.
659 GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED
= (1u << 3),
661 /** Mark significant rewrites for split (`--break-rewrites=/M`) */
662 GIT_DIFF_FIND_REWRITES
= (1u << 4),
663 /** Actually split large rewrites into delete/add pairs */
664 GIT_DIFF_BREAK_REWRITES
= (1u << 5),
665 /** Mark rewrites for split and break into delete/add pairs */
666 GIT_DIFF_FIND_AND_BREAK_REWRITES
=
667 (GIT_DIFF_FIND_REWRITES
| GIT_DIFF_BREAK_REWRITES
),
669 /** Find renames/copies for UNTRACKED items in working directory.
671 * For this to work correctly, use GIT_DIFF_INCLUDE_UNTRACKED when the
672 * initial `git_diff` is being generated (and obviously the diff must
673 * be against the working directory for this to make sense).
675 GIT_DIFF_FIND_FOR_UNTRACKED
= (1u << 6),
677 /** Turn on all finding features. */
678 GIT_DIFF_FIND_ALL
= (0x0ff),
680 /** Measure similarity ignoring leading whitespace (default) */
681 GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE
= 0,
682 /** Measure similarity ignoring all whitespace */
683 GIT_DIFF_FIND_IGNORE_WHITESPACE
= (1u << 12),
684 /** Measure similarity including all data */
685 GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE
= (1u << 13),
686 /** Measure similarity only by comparing SHAs (fast and cheap) */
687 GIT_DIFF_FIND_EXACT_MATCH_ONLY
= (1u << 14),
689 /** Do not break rewrites unless they contribute to a rename.
691 * Normally, GIT_DIFF_FIND_AND_BREAK_REWRITES will measure the self-
692 * similarity of modified files and split the ones that have changed a
693 * lot into a DELETE / ADD pair. Then the sides of that pair will be
694 * considered candidates for rename and copy detection.
696 * If you add this flag in and the split pair is *not* used for an
697 * actual rename or copy, then the modified record will be restored to
698 * a regular MODIFIED record instead of being split.
700 GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY
= (1u << 15),
702 /** Remove any UNMODIFIED deltas after find_similar is done.
704 * Using GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED to emulate the
705 * --find-copies-harder behavior requires building a diff with the
706 * GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED
707 * records in the final result, pass this flag to have them removed.
709 GIT_DIFF_FIND_REMOVE_UNMODIFIED
= (1u << 16),
713 * Pluggable similarity metric
716 int GIT_CALLBACK(file_signature
)(
717 void **out
, const git_diff_file
*file
,
718 const char *fullpath
, void *payload
);
719 int GIT_CALLBACK(buffer_signature
)(
720 void **out
, const git_diff_file
*file
,
721 const char *buf
, size_t buflen
, void *payload
);
722 void GIT_CALLBACK(free_signature
)(void *sig
, void *payload
);
723 int GIT_CALLBACK(similarity
)(int *score
, void *siga
, void *sigb
, void *payload
);
725 } git_diff_similarity_metric
;
728 * Control behavior of rename and copy detection
730 * These options mostly mimic parameters that can be passed to git-diff.
733 unsigned int version
;
736 * Combination of git_diff_find_t values (default GIT_DIFF_FIND_BY_CONFIG).
737 * NOTE: if you don't explicitly set this, `diff.renames` could be set
738 * to false, resulting in `git_diff_find_similar` doing nothing.
743 * Threshold above which similar files will be considered renames.
744 * This is equivalent to the -M option. Defaults to 50.
746 uint16_t rename_threshold
;
749 * Threshold below which similar files will be eligible to be a rename source.
750 * This is equivalent to the first part of the -B option. Defaults to 50.
752 uint16_t rename_from_rewrite_threshold
;
755 * Threshold above which similar files will be considered copies.
756 * This is equivalent to the -C option. Defaults to 50.
758 uint16_t copy_threshold
;
761 * Treshold below which similar files will be split into a delete/add pair.
762 * This is equivalent to the last part of the -B option. Defaults to 60.
764 uint16_t break_rewrite_threshold
;
767 * Maximum number of matches to consider for a particular file.
769 * This is a little different from the `-l` option from Git because we
770 * will still process up to this many matches before abandoning the search.
776 * The `metric` option allows you to plug in a custom similarity metric.
778 * Set it to NULL to use the default internal metric.
780 * The default metric is based on sampling hashes of ranges of data in
781 * the file, which is a pretty good similarity approximation that should
782 * work fairly well for both text and binary data while still being
783 * pretty fast with a fixed memory overhead.
785 git_diff_similarity_metric
*metric
;
786 } git_diff_find_options
;
788 #define GIT_DIFF_FIND_OPTIONS_VERSION 1
789 #define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION}
792 * Initialize git_diff_find_options structure
794 * Initializes a `git_diff_find_options` with default values. Equivalent to creating
795 * an instance with GIT_DIFF_FIND_OPTIONS_INIT.
797 * @param opts The `git_diff_find_options` struct to initialize.
798 * @param version The struct version; pass `GIT_DIFF_FIND_OPTIONS_VERSION`.
799 * @return Zero on success; -1 on failure.
801 GIT_EXTERN(int) git_diff_find_options_init(
802 git_diff_find_options
*opts
,
803 unsigned int version
);
805 /** @name Diff Generator Functions
807 * These are the functions you would use to create (or destroy) a
808 * git_diff from various objects in a repository.
815 * @param diff The previously created diff; cannot be used after free.
817 GIT_EXTERN(void) git_diff_free(git_diff
*diff
);
820 * Create a diff with the difference between two tree objects.
822 * This is equivalent to `git diff <old-tree> <new-tree>`
824 * The first tree will be used for the "old_file" side of the delta and the
825 * second tree will be used for the "new_file" side of the delta. You can
826 * pass NULL to indicate an empty tree, although it is an error to pass
827 * NULL for both the `old_tree` and `new_tree`.
829 * @param diff Output pointer to a git_diff pointer to be allocated.
830 * @param repo The repository containing the trees.
831 * @param old_tree A git_tree object to diff from, or NULL for empty tree.
832 * @param new_tree A git_tree object to diff to, or NULL for empty tree.
833 * @param opts Structure with options to influence diff or NULL for defaults.
835 GIT_EXTERN(int) git_diff_tree_to_tree(
837 git_repository
*repo
,
840 const git_diff_options
*opts
);
843 * Create a diff between a tree and repository index.
845 * This is equivalent to `git diff --cached <treeish>` or if you pass
846 * the HEAD tree, then like `git diff --cached`.
848 * The tree you pass will be used for the "old_file" side of the delta, and
849 * the index will be used for the "new_file" side of the delta.
851 * If you pass NULL for the index, then the existing index of the `repo`
852 * will be used. In this case, the index will be refreshed from disk
853 * (if it has changed) before the diff is generated.
855 * @param diff Output pointer to a git_diff pointer to be allocated.
856 * @param repo The repository containing the tree and index.
857 * @param old_tree A git_tree object to diff from, or NULL for empty tree.
858 * @param index The index to diff with; repo index used if NULL.
859 * @param opts Structure with options to influence diff or NULL for defaults.
861 GIT_EXTERN(int) git_diff_tree_to_index(
863 git_repository
*repo
,
866 const git_diff_options
*opts
);
869 * Create a diff between the repository index and the workdir directory.
871 * This matches the `git diff` command. See the note below on
872 * `git_diff_tree_to_workdir` for a discussion of the difference between
873 * `git diff` and `git diff HEAD` and how to emulate a `git diff <treeish>`
876 * The index will be used for the "old_file" side of the delta, and the
877 * working directory will be used for the "new_file" side of the delta.
879 * If you pass NULL for the index, then the existing index of the `repo`
880 * will be used. In this case, the index will be refreshed from disk
881 * (if it has changed) before the diff is generated.
883 * @param diff Output pointer to a git_diff pointer to be allocated.
884 * @param repo The repository.
885 * @param index The index to diff from; repo index used if NULL.
886 * @param opts Structure with options to influence diff or NULL for defaults.
888 GIT_EXTERN(int) git_diff_index_to_workdir(
890 git_repository
*repo
,
892 const git_diff_options
*opts
);
895 * Create a diff between a tree and the working directory.
897 * The tree you provide will be used for the "old_file" side of the delta,
898 * and the working directory will be used for the "new_file" side.
900 * This is not the same as `git diff <treeish>` or `git diff-index
901 * <treeish>`. Those commands use information from the index, whereas this
902 * function strictly returns the differences between the tree and the files
903 * in the working directory, regardless of the state of the index. Use
904 * `git_diff_tree_to_workdir_with_index` to emulate those commands.
906 * To see difference between this and `git_diff_tree_to_workdir_with_index`,
907 * consider the example of a staged file deletion where the file has then
908 * been put back into the working dir and further modified. The
909 * tree-to-workdir diff for that file is 'modified', but `git diff` would
910 * show status 'deleted' since there is a staged delete.
912 * @param diff A pointer to a git_diff pointer that will be allocated.
913 * @param repo The repository containing the tree.
914 * @param old_tree A git_tree object to diff from, or NULL for empty tree.
915 * @param opts Structure with options to influence diff or NULL for defaults.
917 GIT_EXTERN(int) git_diff_tree_to_workdir(
919 git_repository
*repo
,
921 const git_diff_options
*opts
);
924 * Create a diff between a tree and the working directory using index data
925 * to account for staged deletes, tracked files, etc.
927 * This emulates `git diff <tree>` by diffing the tree to the index and
928 * the index to the working directory and blending the results into a
929 * single diff that includes staged deleted, etc.
931 * @param diff A pointer to a git_diff pointer that will be allocated.
932 * @param repo The repository containing the tree.
933 * @param old_tree A git_tree object to diff from, or NULL for empty tree.
934 * @param opts Structure with options to influence diff or NULL for defaults.
936 GIT_EXTERN(int) git_diff_tree_to_workdir_with_index(
938 git_repository
*repo
,
940 const git_diff_options
*opts
);
943 * Create a diff with the difference between two index objects.
945 * The first index will be used for the "old_file" side of the delta and the
946 * second index will be used for the "new_file" side of the delta.
948 * @param diff Output pointer to a git_diff pointer to be allocated.
949 * @param repo The repository containing the indexes.
950 * @param old_index A git_index object to diff from.
951 * @param new_index A git_index object to diff to.
952 * @param opts Structure with options to influence diff or NULL for defaults.
954 GIT_EXTERN(int) git_diff_index_to_index(
956 git_repository
*repo
,
957 git_index
*old_index
,
958 git_index
*new_index
,
959 const git_diff_options
*opts
);
962 * Merge one diff into another.
964 * This merges items from the "from" list into the "onto" list. The
965 * resulting diff will have all items that appear in either list.
966 * If an item appears in both lists, then it will be "merged" to appear
967 * as if the old version was from the "onto" list and the new version
968 * is from the "from" list (with the exception that if the item has a
969 * pending DELETE in the middle, then it will show as deleted).
971 * @param onto Diff to merge into.
972 * @param from Diff to merge.
974 GIT_EXTERN(int) git_diff_merge(
976 const git_diff
*from
);
979 * Transform a diff marking file renames, copies, etc.
981 * This modifies a diff in place, replacing old entries that look
982 * like renames or copies with new entries reflecting those changes.
983 * This also will, if requested, break modified files into add/remove
984 * pairs if the amount of change is above a threshold.
986 * @param diff diff to run detection algorithms on
987 * @param options Control how detection should be run, NULL for defaults
988 * @return 0 on success, -1 on failure
990 GIT_EXTERN(int) git_diff_find_similar(
992 const git_diff_find_options
*options
);
997 /** @name Diff Processor Functions
999 * These are the functions you apply to a diff to process it
1000 * or read it in some way.
1005 * Query how many diff records are there in a diff.
1007 * @param diff A git_diff generated by one of the above functions
1008 * @return Count of number of deltas in the list
1010 GIT_EXTERN(size_t) git_diff_num_deltas(const git_diff
*diff
);
1013 * Query how many diff deltas are there in a diff filtered by type.
1015 * This works just like `git_diff_num_deltas()` with an extra parameter
1016 * that is a `git_delta_t` and returns just the count of how many deltas
1017 * match that particular type.
1019 * @param diff A git_diff generated by one of the above functions
1020 * @param type A git_delta_t value to filter the count
1021 * @return Count of number of deltas matching delta_t type
1023 GIT_EXTERN(size_t) git_diff_num_deltas_of_type(
1024 const git_diff
*diff
, git_delta_t type
);
1027 * Return the diff delta for an entry in the diff list.
1029 * The `git_diff_delta` pointer points to internal data and you do not
1030 * have to release it when you are done with it. It will go away when
1031 * the * `git_diff` (or any associated `git_patch`) goes away.
1033 * Note that the flags on the delta related to whether it has binary
1034 * content or not may not be set if there are no attributes set for the
1035 * file and there has been no reason to load the file data at this point.
1036 * For now, if you need those flags to be up to date, your only option is
1037 * to either use `git_diff_foreach` or create a `git_patch`.
1039 * @param diff Diff list object
1040 * @param idx Index into diff list
1041 * @return Pointer to git_diff_delta (or NULL if `idx` out of range)
1043 GIT_EXTERN(const git_diff_delta
*) git_diff_get_delta(
1044 const git_diff
*diff
, size_t idx
);
1047 * Check if deltas are sorted case sensitively or insensitively.
1049 * @param diff diff to check
1050 * @return 0 if case sensitive, 1 if case is ignored
1052 GIT_EXTERN(int) git_diff_is_sorted_icase(const git_diff
*diff
);
1055 * Loop over all deltas in a diff issuing callbacks.
1057 * This will iterate through all of the files described in a diff. You
1058 * should provide a file callback to learn about each file.
1060 * The "hunk" and "line" callbacks are optional, and the text diff of the
1061 * files will only be calculated if they are not NULL. Of course, these
1062 * callbacks will not be invoked for binary files on the diff or for
1063 * files whose only changed is a file mode change.
1065 * Returning a non-zero value from any of the callbacks will terminate
1066 * the iteration and return the value to the user.
1068 * @param diff A git_diff generated by one of the above functions.
1069 * @param file_cb Callback function to make per file in the diff.
1070 * @param binary_cb Optional callback to make for binary files.
1071 * @param hunk_cb Optional callback to make per hunk of text diff. This
1072 * callback is called to describe a range of lines in the
1073 * diff. It will not be issued for binary files.
1074 * @param line_cb Optional callback to make per line of diff text. This
1075 * same callback will be made for context lines, added, and
1076 * removed lines, and even for a deleted trailing newline.
1077 * @param payload Reference pointer that will be passed to your callbacks.
1078 * @return 0 on success, non-zero callback return value, or error code
1080 GIT_EXTERN(int) git_diff_foreach(
1082 git_diff_file_cb file_cb
,
1083 git_diff_binary_cb binary_cb
,
1084 git_diff_hunk_cb hunk_cb
,
1085 git_diff_line_cb line_cb
,
1089 * Look up the single character abbreviation for a delta status code.
1091 * When you run `git diff --name-status` it uses single letter codes in
1092 * the output such as 'A' for added, 'D' for deleted, 'M' for modified,
1093 * etc. This function converts a git_delta_t value into these letters for
1094 * your own purposes. GIT_DELTA_UNTRACKED will return a space (i.e. ' ').
1096 * @param status The git_delta_t value to look up
1097 * @return The single character label for that code
1099 GIT_EXTERN(char) git_diff_status_char(git_delta_t status
);
1102 * Possible output formats for diff data
1105 GIT_DIFF_FORMAT_PATCH
= 1u, /**< full git diff */
1106 GIT_DIFF_FORMAT_PATCH_HEADER
= 2u, /**< just the file headers of patch */
1107 GIT_DIFF_FORMAT_RAW
= 3u, /**< like git diff --raw */
1108 GIT_DIFF_FORMAT_NAME_ONLY
= 4u, /**< like git diff --name-only */
1109 GIT_DIFF_FORMAT_NAME_STATUS
= 5u, /**< like git diff --name-status */
1110 GIT_DIFF_FORMAT_PATCH_ID
= 6u, /**< git diff as used by git patch-id */
1111 } git_diff_format_t
;
1114 * Iterate over a diff generating formatted text output.
1116 * Returning a non-zero value from the callbacks will terminate the
1117 * iteration and return the non-zero value to the caller.
1119 * @param diff A git_diff generated by one of the above functions.
1120 * @param format A git_diff_format_t value to pick the text format.
1121 * @param print_cb Callback to make per line of diff text.
1122 * @param payload Reference pointer that will be passed to your callback.
1123 * @return 0 on success, non-zero callback return value, or error code
1125 GIT_EXTERN(int) git_diff_print(
1127 git_diff_format_t format
,
1128 git_diff_line_cb print_cb
,
1132 * Produce the complete formatted text output from a diff into a
1135 * @param out A pointer to a user-allocated git_buf that will
1136 * contain the diff text
1137 * @param diff A git_diff generated by one of the above functions.
1138 * @param format A git_diff_format_t value to pick the text format.
1139 * @return 0 on success or error code
1141 GIT_EXTERN(int) git_diff_to_buf(
1144 git_diff_format_t format
);
1154 * Directly run a diff on two blobs.
1156 * Compared to a file, a blob lacks some contextual information. As such,
1157 * the `git_diff_file` given to the callback will have some fake data; i.e.
1158 * `mode` will be 0 and `path` will be NULL.
1160 * NULL is allowed for either `old_blob` or `new_blob` and will be treated
1161 * as an empty blob, with the `oid` set to NULL in the `git_diff_file` data.
1162 * Passing NULL for both blobs is a noop; no callbacks will be made at all.
1164 * We do run a binary content check on the blob content and if either blob
1165 * looks like binary data, the `git_diff_delta` binary attribute will be set
1166 * to 1 and no call to the hunk_cb nor line_cb will be made (unless you pass
1167 * `GIT_DIFF_FORCE_TEXT` of course).
1169 * @param old_blob Blob for old side of diff, or NULL for empty blob
1170 * @param old_as_path Treat old blob as if it had this filename; can be NULL
1171 * @param new_blob Blob for new side of diff, or NULL for empty blob
1172 * @param new_as_path Treat new blob as if it had this filename; can be NULL
1173 * @param options Options for diff, or NULL for default options
1174 * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1175 * @param binary_cb Callback for binary files; can be NULL
1176 * @param hunk_cb Callback for each hunk in diff; can be NULL
1177 * @param line_cb Callback for each line in diff; can be NULL
1178 * @param payload Payload passed to each callback function
1179 * @return 0 on success, non-zero callback return value, or error code
1181 GIT_EXTERN(int) git_diff_blobs(
1182 const git_blob
*old_blob
,
1183 const char *old_as_path
,
1184 const git_blob
*new_blob
,
1185 const char *new_as_path
,
1186 const git_diff_options
*options
,
1187 git_diff_file_cb file_cb
,
1188 git_diff_binary_cb binary_cb
,
1189 git_diff_hunk_cb hunk_cb
,
1190 git_diff_line_cb line_cb
,
1194 * Directly run a diff between a blob and a buffer.
1196 * As with `git_diff_blobs`, comparing a blob and buffer lacks some context,
1197 * so the `git_diff_file` parameters to the callbacks will be faked a la the
1198 * rules for `git_diff_blobs()`.
1200 * Passing NULL for `old_blob` will be treated as an empty blob (i.e. the
1201 * `file_cb` will be invoked with GIT_DELTA_ADDED and the diff will be the
1202 * entire content of the buffer added). Passing NULL to the buffer will do
1203 * the reverse, with GIT_DELTA_REMOVED and blob content removed.
1205 * @param old_blob Blob for old side of diff, or NULL for empty blob
1206 * @param old_as_path Treat old blob as if it had this filename; can be NULL
1207 * @param buffer Raw data for new side of diff, or NULL for empty
1208 * @param buffer_len Length of raw data for new side of diff
1209 * @param buffer_as_path Treat buffer as if it had this filename; can be NULL
1210 * @param options Options for diff, or NULL for default options
1211 * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1212 * @param binary_cb Callback for binary files; can be NULL
1213 * @param hunk_cb Callback for each hunk in diff; can be NULL
1214 * @param line_cb Callback for each line in diff; can be NULL
1215 * @param payload Payload passed to each callback function
1216 * @return 0 on success, non-zero callback return value, or error code
1218 GIT_EXTERN(int) git_diff_blob_to_buffer(
1219 const git_blob
*old_blob
,
1220 const char *old_as_path
,
1223 const char *buffer_as_path
,
1224 const git_diff_options
*options
,
1225 git_diff_file_cb file_cb
,
1226 git_diff_binary_cb binary_cb
,
1227 git_diff_hunk_cb hunk_cb
,
1228 git_diff_line_cb line_cb
,
1232 * Directly run a diff between two buffers.
1234 * Even more than with `git_diff_blobs`, comparing two buffer lacks
1235 * context, so the `git_diff_file` parameters to the callbacks will be
1236 * faked a la the rules for `git_diff_blobs()`.
1238 * @param old_buffer Raw data for old side of diff, or NULL for empty
1239 * @param old_len Length of the raw data for old side of the diff
1240 * @param old_as_path Treat old buffer as if it had this filename; can be NULL
1241 * @param new_buffer Raw data for new side of diff, or NULL for empty
1242 * @param new_len Length of raw data for new side of diff
1243 * @param new_as_path Treat buffer as if it had this filename; can be NULL
1244 * @param options Options for diff, or NULL for default options
1245 * @param file_cb Callback for "file"; made once if there is a diff; can be NULL
1246 * @param binary_cb Callback for binary files; can be NULL
1247 * @param hunk_cb Callback for each hunk in diff; can be NULL
1248 * @param line_cb Callback for each line in diff; can be NULL
1249 * @param payload Payload passed to each callback function
1250 * @return 0 on success, non-zero callback return value, or error code
1252 GIT_EXTERN(int) git_diff_buffers(
1253 const void *old_buffer
,
1255 const char *old_as_path
,
1256 const void *new_buffer
,
1258 const char *new_as_path
,
1259 const git_diff_options
*options
,
1260 git_diff_file_cb file_cb
,
1261 git_diff_binary_cb binary_cb
,
1262 git_diff_hunk_cb hunk_cb
,
1263 git_diff_line_cb line_cb
,
1267 * Read the contents of a git patch file into a `git_diff` object.
1269 * The diff object produced is similar to the one that would be
1270 * produced if you actually produced it computationally by comparing
1271 * two trees, however there may be subtle differences. For example,
1272 * a patch file likely contains abbreviated object IDs, so the
1273 * object IDs in a `git_diff_delta` produced by this function will
1274 * also be abbreviated.
1276 * This function will only read patch files created by a git
1277 * implementation, it will not read unified diffs produced by
1278 * the `diff` program, nor any other types of patch files.
1280 * @param out A pointer to a git_diff pointer that will be allocated.
1281 * @param content The contents of a patch file
1282 * @param content_len The length of the patch file contents
1283 * @return 0 or an error code
1285 GIT_EXTERN(int) git_diff_from_buffer(
1287 const char *content
,
1288 size_t content_len
);
1291 * This is an opaque structure which is allocated by `git_diff_get_stats`.
1292 * You are responsible for releasing the object memory when done, using the
1293 * `git_diff_stats_free()` function.
1295 typedef struct git_diff_stats git_diff_stats
;
1298 * Formatting options for diff stats
1302 GIT_DIFF_STATS_NONE
= 0,
1304 /** Full statistics, equivalent of `--stat` */
1305 GIT_DIFF_STATS_FULL
= (1u << 0),
1307 /** Short statistics, equivalent of `--shortstat` */
1308 GIT_DIFF_STATS_SHORT
= (1u << 1),
1310 /** Number statistics, equivalent of `--numstat` */
1311 GIT_DIFF_STATS_NUMBER
= (1u << 2),
1313 /** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */
1314 GIT_DIFF_STATS_INCLUDE_SUMMARY
= (1u << 3),
1315 } git_diff_stats_format_t
;
1318 * Accumulate diff statistics for all patches.
1320 * @param out Structure containg the diff statistics.
1321 * @param diff A git_diff generated by one of the above functions.
1322 * @return 0 on success; non-zero on error
1324 GIT_EXTERN(int) git_diff_get_stats(
1325 git_diff_stats
**out
,
1329 * Get the total number of files changed in a diff
1331 * @param stats A `git_diff_stats` generated by one of the above functions.
1332 * @return total number of files changed in the diff
1334 GIT_EXTERN(size_t) git_diff_stats_files_changed(
1335 const git_diff_stats
*stats
);
1338 * Get the total number of insertions in a diff
1340 * @param stats A `git_diff_stats` generated by one of the above functions.
1341 * @return total number of insertions in the diff
1343 GIT_EXTERN(size_t) git_diff_stats_insertions(
1344 const git_diff_stats
*stats
);
1347 * Get the total number of deletions in a diff
1349 * @param stats A `git_diff_stats` generated by one of the above functions.
1350 * @return total number of deletions in the diff
1352 GIT_EXTERN(size_t) git_diff_stats_deletions(
1353 const git_diff_stats
*stats
);
1356 * Print diff statistics to a `git_buf`.
1358 * @param out buffer to store the formatted diff statistics in.
1359 * @param stats A `git_diff_stats` generated by one of the above functions.
1360 * @param format Formatting option.
1361 * @param width Target width for output (only affects GIT_DIFF_STATS_FULL)
1362 * @return 0 on success; non-zero on error
1364 GIT_EXTERN(int) git_diff_stats_to_buf(
1366 const git_diff_stats
*stats
,
1367 git_diff_stats_format_t format
,
1371 * Deallocate a `git_diff_stats`.
1373 * @param stats The previously created statistics object;
1374 * cannot be used after free.
1376 GIT_EXTERN(void) git_diff_stats_free(git_diff_stats
*stats
);
1379 * Patch ID options structure
1381 * Initialize with `GIT_PATCHID_OPTIONS_INIT`. Alternatively, you can
1382 * use `git_diff_patchid_options_init`.
1385 typedef struct git_diff_patchid_options
{
1386 unsigned int version
;
1387 } git_diff_patchid_options
;
1389 #define GIT_DIFF_PATCHID_OPTIONS_VERSION 1
1390 #define GIT_DIFF_PATCHID_OPTIONS_INIT { GIT_DIFF_PATCHID_OPTIONS_VERSION }
1393 * Initialize git_diff_patchid_options structure
1395 * Initializes a `git_diff_patchid_options` with default values. Equivalent to
1396 * creating an instance with `GIT_DIFF_PATCHID_OPTIONS_INIT`.
1398 * @param opts The `git_diff_patchid_options` struct to initialize.
1399 * @param version The struct version; pass `GIT_DIFF_PATCHID_OPTIONS_VERSION`.
1400 * @return Zero on success; -1 on failure.
1402 GIT_EXTERN(int) git_diff_patchid_options_init(
1403 git_diff_patchid_options
*opts
,
1404 unsigned int version
);
1407 * Calculate the patch ID for the given patch.
1409 * Calculate a stable patch ID for the given patch by summing the
1410 * hash of the file diffs, ignoring whitespace and line numbers.
1411 * This can be used to derive whether two diffs are the same with
1412 * a high probability.
1414 * Currently, this function only calculates stable patch IDs, as
1415 * defined in git-patch-id(1), and should in fact generate the
1416 * same IDs as the upstream git project does.
1418 * @param out Pointer where the calculated patch ID should be stored
1419 * @param diff The diff to calculate the ID for
1420 * @param opts Options for how to calculate the patch ID. This is
1421 * intended for future changes, as currently no options are
1423 * @return 0 on success, an error code otherwise.
1425 GIT_EXTERN(int) git_diff_patchid(git_oid
*out
, git_diff
*diff
, git_diff_patchid_options
*opts
);