Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 Junio C Hamano |
| 3 | */ |
Junio C Hamano | e0173ad | 2007-04-28 23:38:52 -0700 | [diff] [blame] | 4 | #ifndef DIFFCORE_H |
| 5 | #define DIFFCORE_H |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 6 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 7 | #include "cache.h" |
| 8 | |
| 9 | struct diff_options; |
Nguyễn Thái Ngọc Duy | b78ea5f | 2018-09-21 17:57:19 +0200 | [diff] [blame] | 10 | struct repository; |
| 11 | struct userdiff_driver; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 12 | |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 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 | */ |
Junio C Hamano | eeaa460 | 2005-06-03 01:40:28 -0700 | [diff] [blame] | 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 | */ |
Junio C Hamano | ee3d299 | 2006-01-15 21:08:42 -0800 | [diff] [blame] | 24 | #define MAX_SCORE 60000.0 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 25 | #define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */ |
Junio C Hamano | 4d0f39c | 2006-03-04 01:03:53 -0800 | [diff] [blame] | 26 | #define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */ |
Matthieu Moy | cf958af | 2010-08-05 18:14:25 +0200 | [diff] [blame] | 27 | #define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */ |
Junio C Hamano | eeaa460 | 2005-06-03 01:40:28 -0700 | [diff] [blame] | 28 | |
| 29 | #define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */ |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 30 | |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 31 | struct diff_filespec { |
brian m. carlson | a0d12c4 | 2016-06-24 23:09:23 +0000 | [diff] [blame] | 32 | struct object_id oid; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 33 | char *path; |
| 34 | void *data; |
Junio C Hamano | c06c796 | 2006-03-12 03:22:10 -0800 | [diff] [blame] | 35 | void *cnt_data; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 36 | unsigned long size; |
Linus Torvalds | 9fb8841 | 2007-10-25 11:19:10 -0700 | [diff] [blame] | 37 | int count; /* Reference count */ |
Linus Torvalds | 6447971 | 2007-10-25 11:20:56 -0700 | [diff] [blame] | 38 | int rename_used; /* Count of rename users */ |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 39 | unsigned short mode; /* file mode */ |
brian m. carlson | 41c9560 | 2016-06-24 23:09:24 +0000 | [diff] [blame] | 40 | unsigned oid_valid : 1; /* if true, use oid and trust mode; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 41 | * if false, use the name and read from |
| 42 | * the filesystem. |
| 43 | */ |
Junio C Hamano | dc7090e | 2005-06-12 17:23:15 -0700 | [diff] [blame] | 44 | #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0) |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 45 | unsigned should_free : 1; /* data should be free()'ed */ |
| 46 | unsigned should_munmap : 1; /* data should be munmap()'ed */ |
Jens Lehmann | c7e1a73 | 2010-03-04 22:20:33 +0100 | [diff] [blame] | 47 | unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */ |
| 48 | #define DIRTY_SUBMODULE_UNTRACKED 1 |
| 49 | #define DIRTY_SUBMODULE_MODIFIED 2 |
Jeff King | b837f5d | 2014-01-16 20:19:46 -0500 | [diff] [blame] | 50 | unsigned is_stdin : 1; |
Junio C Hamano | 25e5e2b | 2011-08-19 23:32:51 -0700 | [diff] [blame] | 51 | unsigned has_more_entries : 1; /* only appear in combined diff */ |
Jeff King | 122aa6f | 2008-10-05 17:43:36 -0400 | [diff] [blame] | 52 | /* data should be considered "binary"; -1 means "don't know yet" */ |
Richard Lowe | 7d0a9a7 | 2014-02-23 19:54:47 -0500 | [diff] [blame] | 53 | signed int is_binary : 2; |
Jeff King | b38f70a | 2014-01-16 20:22:56 -0500 | [diff] [blame] | 54 | struct userdiff_driver *driver; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 57 | struct diff_filespec *alloc_filespec(const char *); |
| 58 | void free_filespec(struct diff_filespec *); |
| 59 | void fill_filespec(struct diff_filespec *, const struct object_id *, |
| 60 | int, unsigned short); |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 61 | |
Nguyễn Thái Ngọc Duy | 8e5dd3d | 2014-08-16 10:08:04 +0700 | [diff] [blame] | 62 | #define CHECK_SIZE_ONLY 1 |
Nguyễn Thái Ngọc Duy | 6bf3b81 | 2014-08-16 10:08:05 +0700 | [diff] [blame] | 63 | #define CHECK_BINARY 2 |
Nguyễn Thái Ngọc Duy | b78ea5f | 2018-09-21 17:57:19 +0200 | [diff] [blame] | 64 | int diff_populate_filespec(struct repository *, struct diff_filespec *, unsigned int); |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 65 | void diff_free_filespec_data(struct diff_filespec *); |
| 66 | void diff_free_filespec_blob(struct diff_filespec *); |
Nguyễn Thái Ngọc Duy | b78ea5f | 2018-09-21 17:57:19 +0200 | [diff] [blame] | 67 | int diff_filespec_is_binary(struct repository *, struct diff_filespec *); |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 68 | |
Junio C Hamano | 52e9578 | 2005-05-21 02:40:01 -0700 | [diff] [blame] | 69 | struct diff_filepair { |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 70 | struct diff_filespec *one; |
| 71 | struct diff_filespec *two; |
Junio C Hamano | 01c4e70 | 2005-05-29 16:56:48 -0700 | [diff] [blame] | 72 | unsigned short int score; |
Yann Dirson | a5a323f | 2008-11-02 14:37:28 +0100 | [diff] [blame] | 73 | char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */ |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 74 | unsigned broken_pair : 1; |
Junio C Hamano | ef67768 | 2006-08-03 12:01:01 -0700 | [diff] [blame] | 75 | unsigned renamed_pair : 1; |
Junio C Hamano | e9c8409 | 2007-01-05 01:25:18 -0800 | [diff] [blame] | 76 | unsigned is_unmerged : 1; |
Nguyễn Thái Ngọc Duy | f34b205 | 2014-01-25 13:46:50 +0700 | [diff] [blame] | 77 | unsigned done_skip_stat_unmatch : 1; |
| 78 | unsigned skip_stat_unmatch_result : 1; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 79 | }; |
Junio C Hamano | e9c8409 | 2007-01-05 01:25:18 -0800 | [diff] [blame] | 80 | #define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged) |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 81 | |
Junio C Hamano | ef67768 | 2006-08-03 12:01:01 -0700 | [diff] [blame] | 82 | #define DIFF_PAIR_RENAME(p) ((p)->renamed_pair) |
Junio C Hamano | 01c4e70 | 2005-05-29 16:56:48 -0700 | [diff] [blame] | 83 | |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 84 | #define DIFF_PAIR_BROKEN(p) \ |
| 85 | ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \ |
| 86 | ((p)->broken_pair != 0) ) |
| 87 | |
Junio C Hamano | 96716a1 | 2005-05-25 15:07:08 -0700 | [diff] [blame] | 88 | #define DIFF_PAIR_TYPE_CHANGED(p) \ |
| 89 | ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode)) |
| 90 | |
Junio C Hamano | 4130b99 | 2005-05-26 02:24:30 -0700 | [diff] [blame] | 91 | #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode) |
| 92 | |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 93 | void diff_free_filepair(struct diff_filepair *); |
Junio C Hamano | 226406f | 2005-05-27 15:50:30 -0700 | [diff] [blame] | 94 | |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 95 | int diff_unmodified_pair(struct diff_filepair *); |
Junio C Hamano | f7c1512 | 2005-05-22 21:26:09 -0700 | [diff] [blame] | 96 | |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 97 | struct diff_queue_struct { |
Junio C Hamano | 52e9578 | 2005-05-21 02:40:01 -0700 | [diff] [blame] | 98 | struct diff_filepair **queue; |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 99 | int alloc; |
| 100 | int nr; |
| 101 | }; |
Bo Yang | 9ca5df9 | 2010-05-06 21:52:27 -0700 | [diff] [blame] | 102 | #define DIFF_QUEUE_CLEAR(q) \ |
| 103 | do { \ |
| 104 | (q)->queue = NULL; \ |
| 105 | (q)->nr = (q)->alloc = 0; \ |
Jonathan Nieder | 9874606 | 2010-08-12 17:11:15 -0500 | [diff] [blame] | 106 | } while (0) |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 107 | |
Junio C Hamano | 38c6f78 | 2005-05-21 19:40:36 -0700 | [diff] [blame] | 108 | extern struct diff_queue_struct diff_queued_diff; |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 109 | struct diff_filepair *diff_queue(struct diff_queue_struct *, |
| 110 | struct diff_filespec *, |
| 111 | struct diff_filespec *); |
| 112 | void diff_q(struct diff_queue_struct *, struct diff_filepair *); |
Junio C Hamano | f7c1512 | 2005-05-22 21:26:09 -0700 | [diff] [blame] | 113 | |
Nguyễn Thái Ngọc Duy | b78ea5f | 2018-09-21 17:57:19 +0200 | [diff] [blame] | 114 | void diffcore_break(struct repository *, int); |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 115 | void diffcore_rename(struct diff_options *); |
| 116 | void diffcore_merge_broken(void); |
| 117 | void diffcore_pickaxe(struct diff_options *); |
| 118 | void diffcore_order(const char *orderfile); |
Junio C Hamano | ce24067 | 2005-06-03 01:36:43 -0700 | [diff] [blame] | 119 | |
Kirill Smelkov | 1df4320 | 2014-01-20 20:20:38 +0400 | [diff] [blame] | 120 | /* low-level interface to diffcore_order */ |
| 121 | struct obj_order { |
| 122 | void *obj; /* setup by caller */ |
| 123 | |
| 124 | /* setup/used by order_objects() */ |
| 125 | int orig_order; |
| 126 | int order; |
| 127 | }; |
| 128 | |
| 129 | typedef const char *(*obj_path_fn_t)(void *obj); |
| 130 | |
| 131 | void order_objects(const char *orderfile, obj_path_fn_t obj_path, |
| 132 | struct obj_order *objs, int nr); |
| 133 | |
Junio C Hamano | 25d5ea4 | 2005-05-24 01:10:48 -0700 | [diff] [blame] | 134 | #define DIFF_DEBUG 0 |
| 135 | #if DIFF_DEBUG |
| 136 | void diff_debug_filespec(struct diff_filespec *, int, const char *); |
| 137 | void diff_debug_filepair(const struct diff_filepair *, int); |
| 138 | void diff_debug_queue(const char *, struct diff_queue_struct *); |
| 139 | #else |
Jonathan Nieder | 9874606 | 2010-08-12 17:11:15 -0500 | [diff] [blame] | 140 | #define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0) |
| 141 | #define diff_debug_filepair(a,b) do { /* nothing */ } while (0) |
| 142 | #define diff_debug_queue(a,b) do { /* nothing */ } while (0) |
Junio C Hamano | 25d5ea4 | 2005-05-24 01:10:48 -0700 | [diff] [blame] | 143 | #endif |
| 144 | |
Nguyễn Thái Ngọc Duy | b78ea5f | 2018-09-21 17:57:19 +0200 | [diff] [blame] | 145 | int diffcore_count_changes(struct repository *r, |
| 146 | struct diff_filespec *src, |
Nguyễn Thái Ngọc Duy | 78d70d9 | 2018-06-30 11:20:25 +0200 | [diff] [blame] | 147 | struct diff_filespec *dst, |
| 148 | void **src_count_p, |
| 149 | void **dst_count_p, |
| 150 | unsigned long *src_copied, |
| 151 | unsigned long *literal_added); |
Junio C Hamano | 6541675 | 2006-02-28 16:01:36 -0800 | [diff] [blame] | 152 | |
Junio C Hamano | 427dcb4 | 2005-05-21 02:39:09 -0700 | [diff] [blame] | 153 | #endif |