]>
| Commit | Line | Data |
|---|---|---|
| 1 | /* | |
| 2 | * Copyright (C) 2005 Junio C Hamano | |
| 3 | */ | |
| 4 | #ifndef DIFFCORE_H | |
| 5 | #define DIFFCORE_H | |
| 6 | ||
| 7 | #include "hash.h" | |
| 8 | ||
| 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; | |
| 16 | ||
| 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 | */ | |
| 21 | ||
| 22 | /* A range [start, end). Lines are numbered starting at 0. */ | |
| 23 | struct range { | |
| 24 | long start, end; | |
| 25 | }; | |
| 26 | ||
| 27 | /* A set of ranges. The ranges must always be disjoint and sorted. */ | |
| 28 | struct range_set { | |
| 29 | unsigned int alloc, nr; | |
| 30 | struct range *ranges; | |
| 31 | }; | |
| 32 | ||
| 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 | */ | |
| 39 | #define MAX_SCORE 60000.0 | |
| 40 | #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */ | |
| 41 | #define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */ | |
| 42 | #define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */ | |
| 43 | ||
| 44 | #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */ | |
| 45 | ||
| 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 | */ | |
| 52 | struct diff_filespec { | |
| 53 | struct object_id oid; | |
| 54 | char *path; | |
| 55 | void *data; | |
| 56 | void *cnt_data; | |
| 57 | unsigned long size; | |
| 58 | int count; /* Reference count */ | |
| 59 | int rename_used; /* Count of rename users */ | |
| 60 | unsigned short mode; /* file mode */ | |
| 61 | unsigned oid_valid : 1; /* if true, use oid and trust mode; | |
| 62 | * if false, use the name and read from | |
| 63 | * the filesystem. | |
| 64 | */ | |
| 65 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) | |
| 66 | unsigned should_free : 1; /* data should be free()'ed */ | |
| 67 | unsigned should_munmap : 1; /* data should be munmap()'ed */ | |
| 68 | unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */ | |
| 69 | #define DIRTY_SUBMODULE_UNTRACKED 1 | |
| 70 | #define DIRTY_SUBMODULE_MODIFIED 2 | |
| 71 | unsigned is_stdin : 1; | |
| 72 | unsigned has_more_entries : 1; /* only appear in combined diff */ | |
| 73 | /* data should be considered "binary"; -1 means "don't know yet" */ | |
| 74 | signed int is_binary : 2; | |
| 75 | struct userdiff_driver *driver; | |
| 76 | }; | |
| 77 | ||
| 78 | struct diff_filespec *alloc_filespec(const char *); | |
| 79 | void free_filespec(struct diff_filespec *); | |
| 80 | void fill_filespec(struct diff_filespec *, const struct object_id *, | |
| 81 | int, unsigned short); | |
| 82 | ||
| 83 | /* | |
| 84 | * Prefetch the entries in diff_queued_diff. The parameter is a pointer to a | |
| 85 | * struct repository. | |
| 86 | */ | |
| 87 | void diff_queued_diff_prefetch(void *repository); | |
| 88 | ||
| 89 | struct diff_populate_filespec_options { | |
| 90 | unsigned check_size_only : 1; | |
| 91 | unsigned check_binary : 1; | |
| 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; | |
| 99 | }; | |
| 100 | int diff_populate_filespec(struct repository *, struct diff_filespec *, | |
| 101 | const struct diff_populate_filespec_options *); | |
| 102 | void diff_free_filespec_data(struct diff_filespec *); | |
| 103 | void diff_free_filespec_blob(struct diff_filespec *); | |
| 104 | int diff_filespec_is_binary(struct repository *, struct diff_filespec *); | |
| 105 | ||
| 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 | */ | |
| 117 | struct diff_filepair { | |
| 118 | struct diff_filespec *one; | |
| 119 | struct diff_filespec *two; | |
| 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; | |
| 125 | unsigned short int score; | |
| 126 | char status; /* M C R A D U etc. (see Documentation/diff-format.adoc or DIFF_STATUS_* in diff.h) */ | |
| 127 | unsigned broken_pair : 1; | |
| 128 | unsigned renamed_pair : 1; | |
| 129 | unsigned is_unmerged : 1; | |
| 130 | unsigned done_skip_stat_unmatch : 1; | |
| 131 | unsigned skip_stat_unmatch_result : 1; | |
| 132 | }; | |
| 133 | ||
| 134 | #define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged) | |
| 135 | ||
| 136 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) | |
| 137 | ||
| 138 | #define DIFF_PAIR_BROKEN(p) \ | |
| 139 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ | |
| 140 | ((p)->broken_pair != 0) ) | |
| 141 | ||
| 142 | #define DIFF_PAIR_TYPE_CHANGED(p) \ | |
| 143 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) | |
| 144 | ||
| 145 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) | |
| 146 | ||
| 147 | void diff_free_filepair(struct diff_filepair *); | |
| 148 | void pool_diff_free_filepair(struct mem_pool *pool, | |
| 149 | struct diff_filepair *p); | |
| 150 | ||
| 151 | int diff_unmodified_pair(struct diff_filepair *); | |
| 152 | ||
| 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 | */ | |
| 166 | struct diff_queue_struct { | |
| 167 | struct diff_filepair **queue; | |
| 168 | int alloc; | |
| 169 | int nr; | |
| 170 | }; | |
| 171 | ||
| 172 | #define DIFF_QUEUE_INIT { 0 } | |
| 173 | ||
| 174 | void diff_queue_init(struct diff_queue_struct *q); | |
| 175 | void diff_queue_clear(struct diff_queue_struct *q); | |
| 176 | ||
| 177 | extern struct diff_queue_struct diff_queued_diff; | |
| 178 | struct diff_filepair *diff_queue(struct diff_queue_struct *, | |
| 179 | struct diff_filespec *, | |
| 180 | struct diff_filespec *); | |
| 181 | void diff_q(struct diff_queue_struct *, struct diff_filepair *); | |
| 182 | ||
| 183 | /* dir_rename_relevance: the reason we want rename information for a dir */ | |
| 184 | enum dir_rename_relevance { | |
| 185 | NOT_RELEVANT = 0, | |
| 186 | RELEVANT_FOR_ANCESTOR = 1, | |
| 187 | RELEVANT_FOR_SELF = 2 | |
| 188 | }; | |
| 189 | /* file_rename_relevance: the reason(s) we want rename information for a file */ | |
| 190 | enum file_rename_relevance { | |
| 191 | RELEVANT_NO_MORE = 0, /* i.e. NOT relevant */ | |
| 192 | RELEVANT_CONTENT = 1, | |
| 193 | RELEVANT_LOCATION = 2 | |
| 194 | }; | |
| 195 | ||
| 196 | void partial_clear_dir_rename_count(struct strmap *dir_rename_count); | |
| 197 | ||
| 198 | void diffcore_break(struct repository *, int); | |
| 199 | void diffcore_rename(struct diff_options *); | |
| 200 | void diffcore_rename_extended(struct diff_options *options, | |
| 201 | struct mem_pool *pool, | |
| 202 | struct strintmap *relevant_sources, | |
| 203 | struct strintmap *dirs_removed, | |
| 204 | struct strmap *dir_rename_count, | |
| 205 | struct strmap *cached_pairs); | |
| 206 | void diffcore_merge_broken(void); | |
| 207 | void diffcore_pickaxe(struct diff_options *); | |
| 208 | void diffcore_order(const char *orderfile); | |
| 209 | void diffcore_rotate(struct diff_options *); | |
| 210 | ||
| 211 | /* low-level interface to diffcore_order */ | |
| 212 | struct obj_order { | |
| 213 | void *obj; /* setup by caller */ | |
| 214 | ||
| 215 | /* setup/used by order_objects() */ | |
| 216 | int orig_order; | |
| 217 | int order; | |
| 218 | }; | |
| 219 | ||
| 220 | typedef const char *(*obj_path_fn_t)(void *obj); | |
| 221 | ||
| 222 | void order_objects(const char *orderfile, obj_path_fn_t obj_path, | |
| 223 | struct obj_order *objs, int nr); | |
| 224 | ||
| 225 | #define DIFF_DEBUG 0 | |
| 226 | #if DIFF_DEBUG | |
| 227 | void diff_debug_filespec(struct diff_filespec *, int, const char *); | |
| 228 | void diff_debug_filepair(const struct diff_filepair *, int); | |
| 229 | void diff_debug_queue(const char *, struct diff_queue_struct *); | |
| 230 | #else | |
| 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) | |
| 234 | #endif | |
| 235 | ||
| 236 | int diffcore_count_changes(struct repository *r, | |
| 237 | struct diff_filespec *src, | |
| 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); | |
| 243 | ||
| 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 | */ | |
| 248 | void diff_add_if_missing(struct repository *r, | |
| 249 | struct oid_array *to_fetch, | |
| 250 | const struct diff_filespec *filespec); | |
| 251 | ||
| 252 | #endif |