]> git.ipfire.org Git - thirdparty/git.git/blame - diffcore.h
Git 2.54
[thirdparty/git.git] / diffcore.h
CommitLineData
427dcb4b
JH
1/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
e0173ad9
JH
4#ifndef DIFFCORE_H
5#define DIFFCORE_H
427dcb4b 6
8a676bdc 7#include "hash.h"
ef3ca954
EN
8
9struct diff_options;
41227cb1
EN
10struct mem_pool;
11struct oid_array;
b78ea5fc 12struct repository;
a49b55d5 13struct strintmap;
0c4fd732 14struct strmap;
b78ea5fc 15struct userdiff_driver;
ef3ca954 16
427dcb4b
JH
17/* This header file is internal between diff.c and its diff transformers
18 * (e.g. diffcore-rename, diffcore-pickaxe). Never include this header
19 * in anything else.
20 */
eeaa4603 21
86e986f1
MM
22/* A range [start, end). Lines are numbered starting at 0. */
23struct range {
24 long start, end;
25};
26
27/* A set of ranges. The ranges must always be disjoint and sorted. */
28struct range_set {
29 unsigned int alloc, nr;
30 struct range *ranges;
31};
32
eeaa4603
JH
33/* We internally use unsigned short as the score value,
34 * and rely on an int capable to hold 32-bits. -B can take
35 * -Bmerge_score/break_score format and the two scores are
36 * passed around in one int (high 16-bit for merge and low 16-bit
37 * for break).
38 */
ee3d299e 39#define MAX_SCORE 60000.0
f345b0a0 40#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
4d0f39ce 41#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
cf958afd 42#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */
eeaa4603
JH
43
44#define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
427dcb4b 45
13c4d7eb
HW
46/**
47 * the internal representation for a single file (blob). It records the blob
48 * object name (if known -- for a work tree file it typically is a NUL SHA-1),
49 * filemode and pathname. This is what the `diff_addremove()`, `diff_change()`
50 * and `diff_unmerge()` synthesize and feed `diff_queue()` function with.
51 */
427dcb4b 52struct diff_filespec {
a0d12c44 53 struct object_id oid;
427dcb4b
JH
54 char *path;
55 void *data;
c06c7966 56 void *cnt_data;
427dcb4b 57 unsigned long size;
9fb88419 58 int count; /* Reference count */
64479711 59 int rename_used; /* Count of rename users */
427dcb4b 60 unsigned short mode; /* file mode */
41c9560e 61 unsigned oid_valid : 1; /* if true, use oid and trust mode;
427dcb4b
JH
62 * if false, use the name and read from
63 * the filesystem.
64 */
dc7090ef 65#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
427dcb4b
JH
66 unsigned should_free : 1; /* data should be free()'ed */
67 unsigned should_munmap : 1; /* data should be munmap()'ed */
c7e1a736
JL
68 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
69#define DIRTY_SUBMODULE_UNTRACKED 1
70#define DIRTY_SUBMODULE_MODIFIED 2
b837f5d6 71 unsigned is_stdin : 1;
25e5e2bf 72 unsigned has_more_entries : 1; /* only appear in combined diff */
122aa6f9 73 /* data should be considered "binary"; -1 means "don't know yet" */
7d0a9a75 74 signed int is_binary : 2;
b38f70a8 75 struct userdiff_driver *driver;
427dcb4b
JH
76};
77
78d70d9b
NTND
78struct diff_filespec *alloc_filespec(const char *);
79void free_filespec(struct diff_filespec *);
80void fill_filespec(struct diff_filespec *, const struct object_id *,
81 int, unsigned short);
427dcb4b 82
95acf11a
JT
83/*
84 * Prefetch the entries in diff_queued_diff. The parameter is a pointer to a
85 * struct repository.
86 */
87void diff_queued_diff_prefetch(void *repository);
88
1c37e86a
JT
89struct diff_populate_filespec_options {
90 unsigned check_size_only : 1;
91 unsigned check_binary : 1;
95acf11a
JT
92
93 /*
94 * If an object is missing, diff_populate_filespec() will invoke this
95 * callback before attempting to read that object again.
96 */
97 void (*missing_object_cb)(void *);
98 void *missing_object_data;
1c37e86a
JT
99};
100int diff_populate_filespec(struct repository *, struct diff_filespec *,
101 const struct diff_populate_filespec_options *);
78d70d9b
NTND
102void diff_free_filespec_data(struct diff_filespec *);
103void diff_free_filespec_blob(struct diff_filespec *);
b78ea5fc 104int diff_filespec_is_binary(struct repository *, struct diff_filespec *);
427dcb4b 105
13c4d7eb
HW
106/**
107 * This records a pair of `struct diff_filespec`; the filespec for a file in
108 * the "old" set (i.e. preimage) is called `one`, and the filespec for a file
109 * in the "new" set (i.e. postimage) is called `two`. A change that represents
110 * file creation has NULL in `one`, and file deletion has NULL in `two`.
111 *
112 * A `filepair` starts pointing at `one` and `two` that are from the same
113 * filename, but `diffcore_std()` can break pairs and match component filespecs
114 * with other filespecs from a different filepair to form new filepair. This is
115 * called 'rename detection'.
116 */
52e95789 117struct diff_filepair {
427dcb4b
JH
118 struct diff_filespec *one;
119 struct diff_filespec *two;
86e986f1
MM
120 /*
121 * Tracked line ranges for -L filtering; borrowed from
122 * line_log_data and must not be freed.
123 */
124 const struct range_set *line_ranges;
01c4e70f 125 unsigned short int score;
3936e95a 126 char status; /* M C R A D U etc. (see Documentation/diff-format.adoc or DIFF_STATUS_* in diff.h) */
f345b0a0 127 unsigned broken_pair : 1;
ef677686 128 unsigned renamed_pair : 1;
e9c84099 129 unsigned is_unmerged : 1;
f34b205f
NTND
130 unsigned done_skip_stat_unmatch : 1;
131 unsigned skip_stat_unmatch_result : 1;
427dcb4b 132};
13c4d7eb 133
e9c84099 134#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
427dcb4b 135
ef677686 136#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
01c4e70f 137
f345b0a0
JH
138#define DIFF_PAIR_BROKEN(p) \
139 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
140 ((p)->broken_pair != 0) )
141
96716a19
JH
142#define DIFF_PAIR_TYPE_CHANGED(p) \
143 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
144
4130b995
JH
145#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
146
78d70d9b 147void diff_free_filepair(struct diff_filepair *);
a8791ef6
EN
148void pool_diff_free_filepair(struct mem_pool *pool,
149 struct diff_filepair *p);
226406f6 150
78d70d9b 151int diff_unmodified_pair(struct diff_filepair *);
f7c1512a 152
13c4d7eb
HW
153/**
154 * This is a collection of filepairs. Notable members are:
155 *
156 * - `queue`:
157 * An array of pointers to `struct diff_filepair`. This dynamically grows as
158 * you add filepairs;
159 *
160 * - `alloc`:
161 * The allocated size of the `queue` array;
162 *
163 * - `nr`:
164 * The number of elements in the `queue` array.
165 */
427dcb4b 166struct diff_queue_struct {
52e95789 167 struct diff_filepair **queue;
427dcb4b
JH
168 int alloc;
169 int nr;
170};
13c4d7eb 171
a5aecb2c
PS
172#define DIFF_QUEUE_INIT { 0 }
173
174void diff_queue_init(struct diff_queue_struct *q);
175void diff_queue_clear(struct diff_queue_struct *q);
427dcb4b 176
38c6f780 177extern struct diff_queue_struct diff_queued_diff;
78d70d9b
NTND
178struct diff_filepair *diff_queue(struct diff_queue_struct *,
179 struct diff_filespec *,
180 struct diff_filespec *);
181void diff_q(struct diff_queue_struct *, struct diff_filepair *);
f7c1512a 182
fb52938e
EN
183/* dir_rename_relevance: the reason we want rename information for a dir */
184enum dir_rename_relevance {
185 NOT_RELEVANT = 0,
186 RELEVANT_FOR_ANCESTOR = 1,
187 RELEVANT_FOR_SELF = 2
188};
ec59da60
EN
189/* file_rename_relevance: the reason(s) we want rename information for a file */
190enum file_rename_relevance {
191 RELEVANT_NO_MORE = 0, /* i.e. NOT relevant */
192 RELEVANT_CONTENT = 1,
193 RELEVANT_LOCATION = 2
194};
fb52938e 195
cd52e005
EN
196void partial_clear_dir_rename_count(struct strmap *dir_rename_count);
197
b78ea5fc 198void diffcore_break(struct repository *, int);
78d70d9b 199void diffcore_rename(struct diff_options *);
0c4fd732 200void diffcore_rename_extended(struct diff_options *options,
f239fff4 201 struct mem_pool *pool,
a49b55d5
EN
202 struct strintmap *relevant_sources,
203 struct strintmap *dirs_removed,
25e65b6d
EN
204 struct strmap *dir_rename_count,
205 struct strmap *cached_pairs);
78d70d9b
NTND
206void diffcore_merge_broken(void);
207void diffcore_pickaxe(struct diff_options *);
208void diffcore_order(const char *orderfile);
1eb4136a 209void diffcore_rotate(struct diff_options *);
ce240675 210
1df4320f
KS
211/* low-level interface to diffcore_order */
212struct obj_order {
213 void *obj; /* setup by caller */
214
215 /* setup/used by order_objects() */
216 int orig_order;
217 int order;
218};
219
220typedef const char *(*obj_path_fn_t)(void *obj);
221
222void order_objects(const char *orderfile, obj_path_fn_t obj_path,
223 struct obj_order *objs, int nr);
224
25d5ea41
JH
225#define DIFF_DEBUG 0
226#if DIFF_DEBUG
227void diff_debug_filespec(struct diff_filespec *, int, const char *);
228void diff_debug_filepair(const struct diff_filepair *, int);
229void diff_debug_queue(const char *, struct diff_queue_struct *);
230#else
98746061
JN
231#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
232#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
233#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
25d5ea41
JH
234#endif
235
b78ea5fc
NTND
236int diffcore_count_changes(struct repository *r,
237 struct diff_filespec *src,
78d70d9b
NTND
238 struct diff_filespec *dst,
239 void **src_count_p,
240 void **dst_count_p,
241 unsigned long *src_copied,
242 unsigned long *literal_added);
65416758 243
95acf11a
JT
244/*
245 * If filespec contains an OID and if that object is missing from the given
246 * repository, add that OID to to_fetch.
247 */
248void diff_add_if_missing(struct repository *r,
249 struct oid_array *to_fetch,
250 const struct diff_filespec *filespec);
251
427dcb4b 252#endif