date: make DATE_MODE thread-safe
[git.git] / diffcore.h
blob5ffe4ec788f84044df42b13eb847dec1f4e1fd36
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #ifndef DIFFCORE_H
5 #define DIFFCORE_H
7 #include "hash-ll.h"
9 struct diff_options;
10 struct mem_pool;
11 struct oid_array;
12 struct repository;
13 struct strintmap;
14 struct strmap;
15 struct userdiff_driver;
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.
22 /* We internally use unsigned short as the score value,
23 * and rely on an int capable to hold 32-bits. -B can take
24 * -Bmerge_score/break_score format and the two scores are
25 * passed around in one int (high 16-bit for merge and low 16-bit
26 * for break).
28 #define MAX_SCORE 60000.0
29 #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
30 #define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
31 #define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */
33 #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
35 /**
36 * the internal representation for a single file (blob). It records the blob
37 * object name (if known -- for a work tree file it typically is a NUL SHA-1),
38 * filemode and pathname. This is what the `diff_addremove()`, `diff_change()`
39 * and `diff_unmerge()` synthesize and feed `diff_queue()` function with.
41 struct diff_filespec {
42 struct object_id oid;
43 char *path;
44 void *data;
45 void *cnt_data;
46 unsigned long size;
47 int count; /* Reference count */
48 int rename_used; /* Count of rename users */
49 unsigned short mode; /* file mode */
50 unsigned oid_valid : 1; /* if true, use oid and trust mode;
51 * if false, use the name and read from
52 * the filesystem.
54 #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
55 unsigned should_free : 1; /* data should be free()'ed */
56 unsigned should_munmap : 1; /* data should be munmap()'ed */
57 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
58 #define DIRTY_SUBMODULE_UNTRACKED 1
59 #define DIRTY_SUBMODULE_MODIFIED 2
60 unsigned is_stdin : 1;
61 unsigned has_more_entries : 1; /* only appear in combined diff */
62 /* data should be considered "binary"; -1 means "don't know yet" */
63 signed int is_binary : 2;
64 struct userdiff_driver *driver;
67 struct diff_filespec *alloc_filespec(const char *);
68 void free_filespec(struct diff_filespec *);
69 void fill_filespec(struct diff_filespec *, const struct object_id *,
70 int, unsigned short);
73 * Prefetch the entries in diff_queued_diff. The parameter is a pointer to a
74 * struct repository.
76 void diff_queued_diff_prefetch(void *repository);
78 struct diff_populate_filespec_options {
79 unsigned check_size_only : 1;
80 unsigned check_binary : 1;
83 * If an object is missing, diff_populate_filespec() will invoke this
84 * callback before attempting to read that object again.
86 void (*missing_object_cb)(void *);
87 void *missing_object_data;
89 int diff_populate_filespec(struct repository *, struct diff_filespec *,
90 const struct diff_populate_filespec_options *);
91 void diff_free_filespec_data(struct diff_filespec *);
92 void diff_free_filespec_blob(struct diff_filespec *);
93 int diff_filespec_is_binary(struct repository *, struct diff_filespec *);
95 /**
96 * This records a pair of `struct diff_filespec`; the filespec for a file in
97 * the "old" set (i.e. preimage) is called `one`, and the filespec for a file
98 * in the "new" set (i.e. postimage) is called `two`. A change that represents
99 * file creation has NULL in `one`, and file deletion has NULL in `two`.
101 * A `filepair` starts pointing at `one` and `two` that are from the same
102 * filename, but `diffcore_std()` can break pairs and match component filespecs
103 * with other filespecs from a different filepair to form new filepair. This is
104 * called 'rename detection'.
106 struct diff_filepair {
107 struct diff_filespec *one;
108 struct diff_filespec *two;
109 unsigned short int score;
110 char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */
111 unsigned broken_pair : 1;
112 unsigned renamed_pair : 1;
113 unsigned is_unmerged : 1;
114 unsigned done_skip_stat_unmatch : 1;
115 unsigned skip_stat_unmatch_result : 1;
118 #define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
120 #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
122 #define DIFF_PAIR_BROKEN(p) \
123 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
124 ((p)->broken_pair != 0) )
126 #define DIFF_PAIR_TYPE_CHANGED(p) \
127 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
129 #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
131 void diff_free_filepair(struct diff_filepair *);
132 void pool_diff_free_filepair(struct mem_pool *pool,
133 struct diff_filepair *p);
135 int diff_unmodified_pair(struct diff_filepair *);
138 * This is a collection of filepairs. Notable members are:
140 * - `queue`:
141 * An array of pointers to `struct diff_filepair`. This dynamically grows as
142 * you add filepairs;
144 * - `alloc`:
145 * The allocated size of the `queue` array;
147 * - `nr`:
148 * The number of elements in the `queue` array.
150 struct diff_queue_struct {
151 struct diff_filepair **queue;
152 int alloc;
153 int nr;
156 #define DIFF_QUEUE_CLEAR(q) \
157 do { \
158 (q)->queue = NULL; \
159 (q)->nr = (q)->alloc = 0; \
160 } while (0)
162 extern struct diff_queue_struct diff_queued_diff;
163 struct diff_filepair *diff_queue(struct diff_queue_struct *,
164 struct diff_filespec *,
165 struct diff_filespec *);
166 void diff_q(struct diff_queue_struct *, struct diff_filepair *);
167 void diff_free_queue(struct diff_queue_struct *q);
169 /* dir_rename_relevance: the reason we want rename information for a dir */
170 enum dir_rename_relevance {
171 NOT_RELEVANT = 0,
172 RELEVANT_FOR_ANCESTOR = 1,
173 RELEVANT_FOR_SELF = 2
175 /* file_rename_relevance: the reason(s) we want rename information for a file */
176 enum file_rename_relevance {
177 RELEVANT_NO_MORE = 0, /* i.e. NOT relevant */
178 RELEVANT_CONTENT = 1,
179 RELEVANT_LOCATION = 2
182 void partial_clear_dir_rename_count(struct strmap *dir_rename_count);
184 void diffcore_break(struct repository *, int);
185 void diffcore_rename(struct diff_options *);
186 void diffcore_rename_extended(struct diff_options *options,
187 struct mem_pool *pool,
188 struct strintmap *relevant_sources,
189 struct strintmap *dirs_removed,
190 struct strmap *dir_rename_count,
191 struct strmap *cached_pairs);
192 void diffcore_merge_broken(void);
193 void diffcore_pickaxe(struct diff_options *);
194 void diffcore_order(const char *orderfile);
195 void diffcore_rotate(struct diff_options *);
197 /* low-level interface to diffcore_order */
198 struct obj_order {
199 void *obj; /* setup by caller */
201 /* setup/used by order_objects() */
202 int orig_order;
203 int order;
206 typedef const char *(*obj_path_fn_t)(void *obj);
208 void order_objects(const char *orderfile, obj_path_fn_t obj_path,
209 struct obj_order *objs, int nr);
211 #define DIFF_DEBUG 0
212 #if DIFF_DEBUG
213 void diff_debug_filespec(struct diff_filespec *, int, const char *);
214 void diff_debug_filepair(const struct diff_filepair *, int);
215 void diff_debug_queue(const char *, struct diff_queue_struct *);
216 #else
217 #define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
218 #define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
219 #define diff_debug_queue(a,b) do { /* nothing */ } while (0)
220 #endif
222 int diffcore_count_changes(struct repository *r,
223 struct diff_filespec *src,
224 struct diff_filespec *dst,
225 void **src_count_p,
226 void **dst_count_p,
227 unsigned long *src_copied,
228 unsigned long *literal_added);
231 * If filespec contains an OID and if that object is missing from the given
232 * repository, add that OID to to_fetch.
234 void diff_add_if_missing(struct repository *r,
235 struct oid_array *to_fetch,
236 const struct diff_filespec *filespec);
238 #endif