]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2005 Junio C Hamano | |
3 | */ | |
4 | #ifndef DIFFCORE_H | |
5 | #define DIFFCORE_H | |
6 | ||
7 | #include "cache.h" | |
8 | ||
9 | struct diff_options; | |
10 | struct repository; | |
11 | struct userdiff_driver; | |
12 | ||
13 | /* This header file is internal between diff.c and its diff transformers | |
14 | * (e.g. diffcore-rename, diffcore-pickaxe). Never include this header | |
15 | * in anything else. | |
16 | */ | |
17 | ||
18 | /* We internally use unsigned short as the score value, | |
19 | * and rely on an int capable to hold 32-bits. -B can take | |
20 | * -Bmerge_score/break_score format and the two scores are | |
21 | * passed around in one int (high 16-bit for merge and low 16-bit | |
22 | * for break). | |
23 | */ | |
24 | #define MAX_SCORE 60000.0 | |
25 | #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */ | |
26 | #define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */ | |
27 | #define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */ | |
28 | ||
29 | #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */ | |
30 | ||
31 | /** | |
32 | * the internal representation for a single file (blob). It records the blob | |
33 | * object name (if known -- for a work tree file it typically is a NUL SHA-1), | |
34 | * filemode and pathname. This is what the `diff_addremove()`, `diff_change()` | |
35 | * and `diff_unmerge()` synthesize and feed `diff_queue()` function with. | |
36 | */ | |
37 | struct diff_filespec { | |
38 | struct object_id oid; | |
39 | char *path; | |
40 | void *data; | |
41 | void *cnt_data; | |
42 | unsigned long size; | |
43 | int count; /* Reference count */ | |
44 | int rename_used; /* Count of rename users */ | |
45 | unsigned short mode; /* file mode */ | |
46 | unsigned oid_valid : 1; /* if true, use oid and trust mode; | |
47 | * if false, use the name and read from | |
48 | * the filesystem. | |
49 | */ | |
50 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) | |
51 | unsigned should_free : 1; /* data should be free()'ed */ | |
52 | unsigned should_munmap : 1; /* data should be munmap()'ed */ | |
53 | unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */ | |
54 | #define DIRTY_SUBMODULE_UNTRACKED 1 | |
55 | #define DIRTY_SUBMODULE_MODIFIED 2 | |
56 | unsigned is_stdin : 1; | |
57 | unsigned has_more_entries : 1; /* only appear in combined diff */ | |
58 | /* data should be considered "binary"; -1 means "don't know yet" */ | |
59 | signed int is_binary : 2; | |
60 | struct userdiff_driver *driver; | |
61 | }; | |
62 | ||
63 | struct diff_filespec *alloc_filespec(const char *); | |
64 | void free_filespec(struct diff_filespec *); | |
65 | void fill_filespec(struct diff_filespec *, const struct object_id *, | |
66 | int, unsigned short); | |
67 | ||
68 | /* | |
69 | * Prefetch the entries in diff_queued_diff. The parameter is a pointer to a | |
70 | * struct repository. | |
71 | */ | |
72 | void diff_queued_diff_prefetch(void *repository); | |
73 | ||
74 | struct diff_populate_filespec_options { | |
75 | unsigned check_size_only : 1; | |
76 | unsigned check_binary : 1; | |
77 | ||
78 | /* | |
79 | * If an object is missing, diff_populate_filespec() will invoke this | |
80 | * callback before attempting to read that object again. | |
81 | */ | |
82 | void (*missing_object_cb)(void *); | |
83 | void *missing_object_data; | |
84 | }; | |
85 | int diff_populate_filespec(struct repository *, struct diff_filespec *, | |
86 | const struct diff_populate_filespec_options *); | |
87 | void diff_free_filespec_data(struct diff_filespec *); | |
88 | void diff_free_filespec_blob(struct diff_filespec *); | |
89 | int diff_filespec_is_binary(struct repository *, struct diff_filespec *); | |
90 | ||
91 | /** | |
92 | * This records a pair of `struct diff_filespec`; the filespec for a file in | |
93 | * the "old" set (i.e. preimage) is called `one`, and the filespec for a file | |
94 | * in the "new" set (i.e. postimage) is called `two`. A change that represents | |
95 | * file creation has NULL in `one`, and file deletion has NULL in `two`. | |
96 | * | |
97 | * A `filepair` starts pointing at `one` and `two` that are from the same | |
98 | * filename, but `diffcore_std()` can break pairs and match component filespecs | |
99 | * with other filespecs from a different filepair to form new filepair. This is | |
100 | * called 'rename detection'. | |
101 | */ | |
102 | struct diff_filepair { | |
103 | struct diff_filespec *one; | |
104 | struct diff_filespec *two; | |
105 | unsigned short int score; | |
106 | char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */ | |
107 | unsigned broken_pair : 1; | |
108 | unsigned renamed_pair : 1; | |
109 | unsigned is_unmerged : 1; | |
110 | unsigned done_skip_stat_unmatch : 1; | |
111 | unsigned skip_stat_unmatch_result : 1; | |
112 | }; | |
113 | ||
114 | #define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged) | |
115 | ||
116 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) | |
117 | ||
118 | #define DIFF_PAIR_BROKEN(p) \ | |
119 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ | |
120 | ((p)->broken_pair != 0) ) | |
121 | ||
122 | #define DIFF_PAIR_TYPE_CHANGED(p) \ | |
123 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) | |
124 | ||
125 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) | |
126 | ||
127 | void diff_free_filepair(struct diff_filepair *); | |
128 | ||
129 | int diff_unmodified_pair(struct diff_filepair *); | |
130 | ||
131 | /** | |
132 | * This is a collection of filepairs. Notable members are: | |
133 | * | |
134 | * - `queue`: | |
135 | * An array of pointers to `struct diff_filepair`. This dynamically grows as | |
136 | * you add filepairs; | |
137 | * | |
138 | * - `alloc`: | |
139 | * The allocated size of the `queue` array; | |
140 | * | |
141 | * - `nr`: | |
142 | * The number of elements in the `queue` array. | |
143 | */ | |
144 | struct diff_queue_struct { | |
145 | struct diff_filepair **queue; | |
146 | int alloc; | |
147 | int nr; | |
148 | }; | |
149 | ||
150 | #define DIFF_QUEUE_CLEAR(q) \ | |
151 | do { \ | |
152 | (q)->queue = NULL; \ | |
153 | (q)->nr = (q)->alloc = 0; \ | |
154 | } while (0) | |
155 | ||
156 | extern struct diff_queue_struct diff_queued_diff; | |
157 | struct diff_filepair *diff_queue(struct diff_queue_struct *, | |
158 | struct diff_filespec *, | |
159 | struct diff_filespec *); | |
160 | void diff_q(struct diff_queue_struct *, struct diff_filepair *); | |
161 | ||
162 | void diffcore_break(struct repository *, int); | |
163 | void diffcore_rename(struct diff_options *); | |
164 | void diffcore_merge_broken(void); | |
165 | void diffcore_pickaxe(struct diff_options *); | |
166 | void diffcore_order(const char *orderfile); | |
167 | ||
168 | /* low-level interface to diffcore_order */ | |
169 | struct obj_order { | |
170 | void *obj; /* setup by caller */ | |
171 | ||
172 | /* setup/used by order_objects() */ | |
173 | int orig_order; | |
174 | int order; | |
175 | }; | |
176 | ||
177 | typedef const char *(*obj_path_fn_t)(void *obj); | |
178 | ||
179 | void order_objects(const char *orderfile, obj_path_fn_t obj_path, | |
180 | struct obj_order *objs, int nr); | |
181 | ||
182 | #define DIFF_DEBUG 0 | |
183 | #if DIFF_DEBUG | |
184 | void diff_debug_filespec(struct diff_filespec *, int, const char *); | |
185 | void diff_debug_filepair(const struct diff_filepair *, int); | |
186 | void diff_debug_queue(const char *, struct diff_queue_struct *); | |
187 | #else | |
188 | #define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0) | |
189 | #define diff_debug_filepair(a,b) do { /* nothing */ } while (0) | |
190 | #define diff_debug_queue(a,b) do { /* nothing */ } while (0) | |
191 | #endif | |
192 | ||
193 | int diffcore_count_changes(struct repository *r, | |
194 | struct diff_filespec *src, | |
195 | struct diff_filespec *dst, | |
196 | void **src_count_p, | |
197 | void **dst_count_p, | |
198 | unsigned long *src_copied, | |
199 | unsigned long *literal_added); | |
200 | ||
201 | /* | |
202 | * If filespec contains an OID and if that object is missing from the given | |
203 | * repository, add that OID to to_fetch. | |
204 | */ | |
205 | void diff_add_if_missing(struct repository *r, | |
206 | struct oid_array *to_fetch, | |
207 | const struct diff_filespec *filespec); | |
208 | ||
209 | #endif |