]>
Commit | Line | Data |
---|---|---|
65b09b1d | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
65b09b1d RB |
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_diff_h__ | |
8 | #define INCLUDE_diff_h__ | |
9 | ||
5f69a31f | 10 | #include "git2/diff.h" |
9c8ed499 | 11 | #include "git2/sys/diff.h" |
5f69a31f RB |
12 | #include "git2/oid.h" |
13 | ||
65b09b1d RB |
14 | #include <stdio.h> |
15 | #include "vector.h" | |
16 | #include "buffer.h" | |
74fa4bfa RB |
17 | #include "iterator.h" |
18 | #include "repository.h" | |
19fa2bc1 | 19 | #include "pool.h" |
effdbeb3 | 20 | #include "odb.h" |
65b09b1d | 21 | |
16b83019 RB |
22 | #define DIFF_OLD_PREFIX_DEFAULT "a/" |
23 | #define DIFF_NEW_PREFIX_DEFAULT "b/" | |
eb3d71a5 | 24 | |
95dfb031 RB |
25 | enum { |
26 | GIT_DIFFCAPS_HAS_SYMLINKS = (1 << 0), /* symlinks on platform? */ | |
3e57069e | 27 | GIT_DIFFCAPS_IGNORE_STAT = (1 << 1), /* use stat? */ |
0abd7244 | 28 | GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */ |
95dfb031 RB |
29 | GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */ |
30 | GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */ | |
e35e2684 | 31 | GIT_DIFFCAPS_TRUST_NANOSECS = (1 << 5), /* use stat time nanoseconds */ |
95dfb031 RB |
32 | }; |
33 | ||
114f5a6c RB |
34 | #define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY) |
35 | #define DIFF_FLAGS_NOT_BINARY (GIT_DIFF_FLAG_NOT_BINARY|GIT_DIFF_FLAG__NO_DATA) | |
36 | ||
71a3d27e RB |
37 | enum { |
38 | GIT_DIFF_FLAG__FREE_PATH = (1 << 7), /* `path` is allocated memory */ | |
39 | GIT_DIFF_FLAG__FREE_DATA = (1 << 8), /* internal file data is allocated */ | |
40 | GIT_DIFF_FLAG__UNMAP_DATA = (1 << 9), /* internal file data is mmap'ed */ | |
41 | GIT_DIFF_FLAG__NO_DATA = (1 << 10), /* file data should not be loaded */ | |
114f5a6c RB |
42 | GIT_DIFF_FLAG__FREE_BLOB = (1 << 11), /* release the blob when done */ |
43 | GIT_DIFF_FLAG__LOADED = (1 << 12), /* file data has been loaded */ | |
a21cbb12 RB |
44 | |
45 | GIT_DIFF_FLAG__TO_DELETE = (1 << 16), /* delete entry during rename det. */ | |
46 | GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */ | |
47 | GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18), | |
48 | GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19), | |
49 | GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20), | |
71a3d27e | 50 | }; |
b4f5bb07 | 51 | |
a21cbb12 RB |
52 | #define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF) |
53 | ||
67db583d RB |
54 | #define GIT_DIFF__VERBOSE (1 << 30) |
55 | ||
3ff1d123 | 56 | struct git_diff { |
f335ecd6 | 57 | git_refcount rc; |
65b09b1d RB |
58 | git_repository *repo; |
59 | git_diff_options opts; | |
14a513e0 | 60 | git_vector pathspec; |
52a61bb8 | 61 | git_vector deltas; /* vector of git_diff_delta */ |
19fa2bc1 | 62 | git_pool pool; |
74fa4bfa RB |
63 | git_iterator_type_t old_src; |
64 | git_iterator_type_t new_src; | |
95dfb031 | 65 | uint32_t diffcaps; |
9c8ed499 | 66 | git_diff_perfdata perf; |
c2e1b058 | 67 | bool index_updated; |
55cbd05b | 68 | |
0f3def71 RB |
69 | int (*strcomp)(const char *, const char *); |
70 | int (*strncomp)(const char *, const char *, size_t); | |
71 | int (*pfxcomp)(const char *str, const char *pfx); | |
72 | int (*entrycomp)(const void *a, const void *b); | |
65b09b1d RB |
73 | }; |
74 | ||
0abd7244 RB |
75 | extern void git_diff__cleanup_modes( |
76 | uint32_t diffcaps, uint32_t *omode, uint32_t *nmode); | |
77 | ||
3ff1d123 | 78 | extern void git_diff_addref(git_diff *diff); |
b36effa2 | 79 | |
db106d01 | 80 | extern int git_diff_delta__cmp(const void *a, const void *b); |
351888cf | 81 | extern int git_diff_delta__casecmp(const void *a, const void *b); |
db106d01 | 82 | |
2b672d5b RB |
83 | extern const char *git_diff_delta__path(const git_diff_delta *delta); |
84 | ||
64286308 | 85 | extern bool git_diff_delta__should_skip( |
bae957b9 | 86 | const git_diff_options *opts, const git_diff_delta *delta); |
64286308 | 87 | |
197b8966 RB |
88 | extern int git_diff_delta__format_file_header( |
89 | git_buf *out, | |
90 | const git_diff_delta *delta, | |
91 | const char *oldpfx, | |
92 | const char *newpfx, | |
93 | int oid_strlen); | |
94 | ||
55cbd05b | 95 | extern int git_diff__oid_for_file( |
0fc8e1f6 RB |
96 | git_oid *out, git_diff *, const char *, uint16_t, git_off_t); |
97 | extern int git_diff__oid_for_entry( | |
96dd171e | 98 | git_oid *out, git_diff *, const git_index_entry *, uint16_t, const git_oid *update); |
55cbd05b | 99 | |
9950d27a | 100 | extern int git_diff__from_iterators( |
3ff1d123 | 101 | git_diff **diff_ptr, |
9950d27a RB |
102 | git_repository *repo, |
103 | git_iterator *old_iter, | |
104 | git_iterator *new_iter, | |
105 | const git_diff_options *opts); | |
2f8d30be | 106 | |
114f5a6c | 107 | extern int git_diff__paired_foreach( |
3ff1d123 RB |
108 | git_diff *idx2head, |
109 | git_diff *wd2idx, | |
114f5a6c RB |
110 | int (*cb)(git_diff_delta *i2h, git_diff_delta *w2i, void *payload), |
111 | void *payload); | |
112 | ||
a1683f28 | 113 | extern int git_diff_find_similar__hashsig_for_file( |
0462fba5 ET |
114 | void **out, const git_diff_file *f, const char *path, void *p); |
115 | ||
a1683f28 | 116 | extern int git_diff_find_similar__hashsig_for_buf( |
0462fba5 ET |
117 | void **out, const git_diff_file *f, const char *buf, size_t len, void *p); |
118 | ||
a1683f28 | 119 | extern void git_diff_find_similar__hashsig_free(void *sig, void *payload); |
0462fba5 | 120 | |
a1683f28 | 121 | extern int git_diff_find_similar__calc_similarity( |
0462fba5 ET |
122 | int *score, void *siga, void *sigb, void *payload); |
123 | ||
d8cc1fb6 JG |
124 | extern int git_diff__commit( |
125 | git_diff **diff, git_repository *repo, const git_commit *commit, const git_diff_options *opts); | |
126 | ||
5ef43d41 ET |
127 | /* Merge two `git_diff`s according to the callback given by `cb`. */ |
128 | ||
129 | typedef git_diff_delta *(*git_diff__merge_cb)( | |
130 | const git_diff_delta *left, | |
131 | const git_diff_delta *right, | |
132 | git_pool *pool); | |
133 | ||
134 | extern int git_diff__merge( | |
135 | git_diff *onto, const git_diff *from, git_diff__merge_cb cb); | |
136 | ||
90177111 ET |
137 | extern git_diff_delta *git_diff__merge_like_cgit( |
138 | const git_diff_delta *a, | |
139 | const git_diff_delta *b, | |
140 | git_pool *pool); | |
141 | ||
142 | /* Duplicate a `git_diff_delta` out of the `git_pool` */ | |
143 | extern git_diff_delta *git_diff__delta_dup( | |
144 | const git_diff_delta *d, git_pool *pool); | |
145 | ||
effdbeb3 RB |
146 | /* |
147 | * Sometimes a git_diff_file will have a zero size; this attempts to | |
148 | * fill in the size without loading the blob if possible. If that is | |
149 | * not possible, then it will return the git_odb_object that had to be | |
150 | * loaded and the caller can use it or dispose of it as needed. | |
151 | */ | |
152 | GIT_INLINE(int) git_diff_file__resolve_zero_size( | |
153 | git_diff_file *file, git_odb_object **odb_obj, git_repository *repo) | |
154 | { | |
155 | int error; | |
156 | git_odb *odb; | |
157 | size_t len; | |
158 | git_otype type; | |
159 | ||
160 | if ((error = git_repository_odb(&odb, repo)) < 0) | |
161 | return error; | |
162 | ||
163 | error = git_odb__read_header_or_object( | |
9950bb4e | 164 | odb_obj, &len, &type, odb, &file->id); |
effdbeb3 RB |
165 | |
166 | git_odb_free(odb); | |
167 | ||
168 | if (!error) | |
169 | file->size = (git_off_t)len; | |
170 | ||
171 | return error; | |
172 | } | |
173 | ||
65b09b1d RB |
174 | #endif |
175 |