blob: 33ea2de348803b29a08a6713ae4cab1345f874d9 [file] [log] [blame]
Junio C Hamano427dcb42005-05-21 02:39:09 -07001/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
Junio C Hamanoe0173ad2007-04-28 23:38:52 -07004#ifndef DIFFCORE_H
5#define DIFFCORE_H
Junio C Hamano427dcb42005-05-21 02:39:09 -07006
7/* This header file is internal between diff.c and its diff transformers
8 * (e.g. diffcore-rename, diffcore-pickaxe). Never include this header
9 * in anything else.
10 */
Junio C Hamanoeeaa4602005-06-03 01:40:28 -070011
12/* We internally use unsigned short as the score value,
13 * and rely on an int capable to hold 32-bits. -B can take
14 * -Bmerge_score/break_score format and the two scores are
15 * passed around in one int (high 16-bit for merge and low 16-bit
16 * for break).
17 */
Junio C Hamanoee3d2992006-01-15 21:08:42 -080018#define MAX_SCORE 60000.0
Junio C Hamanof345b0a2005-05-30 00:08:37 -070019#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
Junio C Hamano4d0f39c2006-03-04 01:03:53 -080020#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
Matthieu Moycf958af2010-08-05 18:14:25 +020021#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */
Junio C Hamanoeeaa4602005-06-03 01:40:28 -070022
23#define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
Junio C Hamano427dcb42005-05-21 02:39:09 -070024
Jeff King122aa6f2008-10-05 17:43:36 -040025struct userdiff_driver;
26
Junio C Hamano427dcb42005-05-21 02:39:09 -070027struct diff_filespec {
28 unsigned char sha1[20];
29 char *path;
30 void *data;
Junio C Hamanoc06c7962006-03-12 03:22:10 -080031 void *cnt_data;
Junio C Hamano427dcb42005-05-21 02:39:09 -070032 unsigned long size;
Linus Torvalds9fb88412007-10-25 11:19:10 -070033 int count; /* Reference count */
Linus Torvalds64479712007-10-25 11:20:56 -070034 int rename_used; /* Count of rename users */
Junio C Hamano427dcb42005-05-21 02:39:09 -070035 unsigned short mode; /* file mode */
36 unsigned sha1_valid : 1; /* if true, use sha1 and trust mode;
37 * if false, use the name and read from
38 * the filesystem.
39 */
Junio C Hamanodc7090e2005-06-12 17:23:15 -070040#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
Junio C Hamano427dcb42005-05-21 02:39:09 -070041 unsigned should_free : 1; /* data should be free()'ed */
42 unsigned should_munmap : 1; /* data should be munmap()'ed */
Jens Lehmannc7e1a732010-03-04 22:20:33 +010043 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
44#define DIRTY_SUBMODULE_UNTRACKED 1
45#define DIRTY_SUBMODULE_MODIFIED 2
Jeff Kingb837f5d2014-01-16 20:19:46 -050046 unsigned is_stdin : 1;
Junio C Hamano25e5e2b2011-08-19 23:32:51 -070047 unsigned has_more_entries : 1; /* only appear in combined diff */
Jeff King122aa6f2008-10-05 17:43:36 -040048 /* data should be considered "binary"; -1 means "don't know yet" */
Richard Lowe7d0a9a72014-02-23 19:54:47 -050049 signed int is_binary : 2;
Jeff Kingb38f70a2014-01-16 20:22:56 -050050 struct userdiff_driver *driver;
Junio C Hamano427dcb42005-05-21 02:39:09 -070051};
52
53extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 11:19:10 -070054extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070055extern void fill_filespec(struct diff_filespec *, const unsigned char *,
Jeff Kinge5450102012-07-28 11:03:01 -040056 int, unsigned short);
Junio C Hamano427dcb42005-05-21 02:39:09 -070057
Nguyễn Thái Ngọc Duy8e5dd3d2014-08-16 10:08:04 +070058#define CHECK_SIZE_ONLY 1
Nguyễn Thái Ngọc Duy6bf3b812014-08-16 10:08:05 +070059#define CHECK_BINARY 2
Nguyễn Thái Ngọc Duy8e5dd3d2014-08-16 10:08:04 +070060extern int diff_populate_filespec(struct diff_filespec *, unsigned int);
Junio C Hamano19397b42005-09-14 14:06:50 -070061extern void diff_free_filespec_data(struct diff_filespec *);
Junio C Hamano8ae92e62007-10-02 21:01:03 -070062extern void diff_free_filespec_blob(struct diff_filespec *);
Junio C Hamano29a3eef2007-07-06 00:18:54 -070063extern int diff_filespec_is_binary(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070064
Junio C Hamano52e95782005-05-21 02:40:01 -070065struct diff_filepair {
Junio C Hamano427dcb42005-05-21 02:39:09 -070066 struct diff_filespec *one;
67 struct diff_filespec *two;
Junio C Hamano01c4e702005-05-29 16:56:48 -070068 unsigned short int score;
Yann Dirsona5a323f2008-11-02 14:37:28 +010069 char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */
Junio C Hamanof345b0a2005-05-30 00:08:37 -070070 unsigned broken_pair : 1;
Junio C Hamanoef677682006-08-03 12:01:01 -070071 unsigned renamed_pair : 1;
Junio C Hamanoe9c84092007-01-05 01:25:18 -080072 unsigned is_unmerged : 1;
Nguyễn Thái Ngọc Duyf34b2052014-01-25 13:46:50 +070073 unsigned done_skip_stat_unmatch : 1;
74 unsigned skip_stat_unmatch_result : 1;
Junio C Hamano427dcb42005-05-21 02:39:09 -070075};
Junio C Hamanoe9c84092007-01-05 01:25:18 -080076#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 02:39:09 -070077
Junio C Hamanoef677682006-08-03 12:01:01 -070078#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 16:56:48 -070079
Junio C Hamanof345b0a2005-05-30 00:08:37 -070080#define DIFF_PAIR_BROKEN(p) \
81 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
82 ((p)->broken_pair != 0) )
83
Junio C Hamano96716a12005-05-25 15:07:08 -070084#define DIFF_PAIR_TYPE_CHANGED(p) \
85 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
86
Junio C Hamano4130b992005-05-26 02:24:30 -070087#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
88
Junio C Hamano226406f2005-05-27 15:50:30 -070089extern void diff_free_filepair(struct diff_filepair *);
90
Junio C Hamanof7c15122005-05-22 21:26:09 -070091extern int diff_unmodified_pair(struct diff_filepair *);
92
Junio C Hamano427dcb42005-05-21 02:39:09 -070093struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 02:40:01 -070094 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 02:39:09 -070095 int alloc;
96 int nr;
97};
Bo Yang9ca5df92010-05-06 21:52:27 -070098#define DIFF_QUEUE_CLEAR(q) \
99 do { \
100 (q)->queue = NULL; \
101 (q)->nr = (q)->alloc = 0; \
Jonathan Nieder98746062010-08-12 17:11:15 -0500102 } while (0)
Junio C Hamano427dcb42005-05-21 02:39:09 -0700103
Junio C Hamano38c6f782005-05-21 19:40:36 -0700104extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 02:40:01 -0700105extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
106 struct diff_filespec *,
107 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 10:04:37 -0700108extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-22 21:26:09 -0700109
Junio C Hamanoce240672005-06-03 01:36:43 -0700110extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700111extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 01:40:28 -0700112extern void diffcore_merge_broken(void);
Junio C Hamano382f0132010-08-31 13:44:39 -0700113extern void diffcore_pickaxe(struct diff_options *);
Junio C Hamanoce240672005-06-03 01:36:43 -0700114extern void diffcore_order(const char *orderfile);
115
Kirill Smelkov1df43202014-01-20 20:20:38 +0400116/* low-level interface to diffcore_order */
117struct obj_order {
118 void *obj; /* setup by caller */
119
120 /* setup/used by order_objects() */
121 int orig_order;
122 int order;
123};
124
125typedef const char *(*obj_path_fn_t)(void *obj);
126
127void order_objects(const char *orderfile, obj_path_fn_t obj_path,
128 struct obj_order *objs, int nr);
129
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700130#define DIFF_DEBUG 0
131#if DIFF_DEBUG
132void diff_debug_filespec(struct diff_filespec *, int, const char *);
133void diff_debug_filepair(const struct diff_filepair *, int);
134void diff_debug_queue(const char *, struct diff_queue_struct *);
135#else
Jonathan Nieder98746062010-08-12 17:11:15 -0500136#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
137#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
138#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700139#endif
140
Junio C Hamanod8c3d032007-06-28 22:54:37 -0700141extern int diffcore_count_changes(struct diff_filespec *src,
142 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 03:22:10 -0800143 void **src_count_p,
144 void **dst_count_p,
Junio C Hamano65416752006-02-28 16:01:36 -0800145 unsigned long delta_limit,
146 unsigned long *src_copied,
147 unsigned long *literal_added);
148
Junio C Hamano427dcb42005-05-21 02:39:09 -0700149#endif