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