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_diff_generate_h__
8 #define INCLUDE_diff_generate_h__
17 GIT_DIFFCAPS_HAS_SYMLINKS
= (1 << 0), /* symlinks on platform? */
18 GIT_DIFFCAPS_IGNORE_STAT
= (1 << 1), /* use stat? */
19 GIT_DIFFCAPS_TRUST_MODE_BITS
= (1 << 2), /* use st_mode? */
20 GIT_DIFFCAPS_TRUST_CTIME
= (1 << 3), /* use st_ctime? */
21 GIT_DIFFCAPS_USE_DEV
= (1 << 4) /* use st_dev? */
24 #define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY)
25 #define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA)
28 GIT_DIFF_FLAG__FREE_PATH
= (1 << 7), /* `path` is allocated memory */
29 GIT_DIFF_FLAG__FREE_DATA
= (1 << 8), /* internal file data is allocated */
30 GIT_DIFF_FLAG__UNMAP_DATA
= (1 << 9), /* internal file data is mmap'ed */
31 GIT_DIFF_FLAG__NO_DATA
= (1 << 10), /* file data should not be loaded */
32 GIT_DIFF_FLAG__FREE_BLOB
= (1 << 11), /* release the blob when done */
33 GIT_DIFF_FLAG__LOADED
= (1 << 12), /* file data has been loaded */
35 GIT_DIFF_FLAG__TO_DELETE
= (1 << 16), /* delete entry during rename det. */
36 GIT_DIFF_FLAG__TO_SPLIT
= (1 << 17), /* split entry during rename det. */
37 GIT_DIFF_FLAG__IS_RENAME_TARGET
= (1 << 18),
38 GIT_DIFF_FLAG__IS_RENAME_SOURCE
= (1 << 19),
39 GIT_DIFF_FLAG__HAS_SELF_SIMILARITY
= (1 << 20)
42 #define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF)
44 #define GIT_DIFF__VERBOSE (1 << 30)
46 extern void git_diff_addref(git_diff
*diff
);
48 extern bool git_diff_delta__should_skip(
49 const git_diff_options
*opts
, const git_diff_delta
*delta
);
51 extern int git_diff__from_iterators(
54 git_iterator
*old_iter
,
55 git_iterator
*new_iter
,
56 const git_diff_options
*opts
);
58 extern int git_diff__commit(
59 git_diff
**diff
, git_repository
*repo
, const git_commit
*commit
, const git_diff_options
*opts
);
61 extern int git_diff__paired_foreach(
64 int (*cb
)(git_diff_delta
*i2h
, git_diff_delta
*w2i
, void *payload
),
67 /* Merge two `git_diff`s according to the callback given by `cb`. */
69 typedef git_diff_delta
*(*git_diff__merge_cb
)(
70 const git_diff_delta
*left
,
71 const git_diff_delta
*right
,
74 extern int git_diff__merge(
75 git_diff
*onto
, const git_diff
*from
, git_diff__merge_cb cb
);
77 extern git_diff_delta
*git_diff__merge_like_cgit(
78 const git_diff_delta
*a
,
79 const git_diff_delta
*b
,
82 /* Duplicate a `git_diff_delta` out of the `git_pool` */
83 extern git_diff_delta
*git_diff__delta_dup(
84 const git_diff_delta
*d
, git_pool
*pool
);
86 extern int git_diff__oid_for_file(
91 git_object_size_t size
);
93 extern int git_diff__oid_for_entry(
96 const git_index_entry
*src
,
98 const git_oid
*update_match
);
101 * Sometimes a git_diff_file will have a zero size; this attempts to
102 * fill in the size without loading the blob if possible. If that is
103 * not possible, then it will return the git_odb_object that had to be
104 * loaded and the caller can use it or dispose of it as needed.
106 GIT_INLINE(int) git_diff_file__resolve_zero_size(
107 git_diff_file
*file
, git_odb_object
**odb_obj
, git_repository
*repo
)
114 if ((error
= git_repository_odb(&odb
, repo
)) < 0)
117 error
= git_odb__read_header_or_object(
118 odb_obj
, &len
, &type
, odb
, &file
->id
);
123 file
->size
= (git_object_size_t
)len
;
124 file
->flags
|= GIT_DIFF_FLAG_VALID_SIZE
;