blob: 1c16c8595b21c2712259041c01d4b58d76a60222 [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 Hamanoe0e324a2007-07-07 01:49:58 -070032 const char *funcname_pattern_ident;
Junio C Hamano427dcb42005-05-21 02:39:09 -070033 unsigned long size;
Linus Torvalds9fb88412007-10-25 11:19:10 -070034 int count; /* Reference count */
Junio C Hamano427dcb42005-05-21 02:39:09 -070035 int xfrm_flags; /* for use by the xfrm */
Linus Torvalds64479712007-10-25 11:20:56 -070036 int rename_used; /* Count of rename users */
Junio C Hamano427dcb42005-05-21 02:39:09 -070037 unsigned short mode; /* file mode */
38 unsigned sha1_valid : 1; /* if true, use sha1 and trust mode;
39 * if false, use the name and read from
40 * the filesystem.
41 */
Junio C Hamanodc7090e2005-06-12 17:23:15 -070042#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
Junio C Hamano427dcb42005-05-21 02:39:09 -070043 unsigned should_free : 1; /* data should be free()'ed */
44 unsigned should_munmap : 1; /* data should be munmap()'ed */
Jens Lehmannc7e1a732010-03-04 22:20:33 +010045 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
Junio C Hamano4682d852012-06-27 20:14:47 -070046 unsigned is_stdin : 1;
Jens Lehmannc7e1a732010-03-04 22:20:33 +010047#define DIRTY_SUBMODULE_UNTRACKED 1
48#define DIRTY_SUBMODULE_MODIFIED 2
Junio C Hamano25e5e2b2011-08-19 23:32:51 -070049 unsigned has_more_entries : 1; /* only appear in combined diff */
Jeff King122aa6f2008-10-05 17:43:36 -040050 struct userdiff_driver *driver;
51 /* data should be considered "binary"; -1 means "don't know yet" */
52 int is_binary;
Junio C Hamano427dcb42005-05-21 02:39:09 -070053};
54
55extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 11:19:10 -070056extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070057extern void fill_filespec(struct diff_filespec *, const unsigned char *,
Jeff Kinge5450102012-07-28 11:03:01 -040058 int, unsigned short);
Junio C Hamano427dcb42005-05-21 02:39:09 -070059
Junio C Hamanof0c6b2a2005-05-27 15:56:38 -070060extern int diff_populate_filespec(struct diff_filespec *, 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;
Junio C Hamano427dcb42005-05-21 02:39:09 -070073};
Junio C Hamanoe9c84092007-01-05 01:25:18 -080074#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 02:39:09 -070075
Junio C Hamanoef677682006-08-03 12:01:01 -070076#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 16:56:48 -070077
Junio C Hamanof345b0a2005-05-30 00:08:37 -070078#define DIFF_PAIR_BROKEN(p) \
79 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
80 ((p)->broken_pair != 0) )
81
Junio C Hamano96716a12005-05-25 15:07:08 -070082#define DIFF_PAIR_TYPE_CHANGED(p) \
83 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
84
Junio C Hamano4130b992005-05-26 02:24:30 -070085#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
86
Junio C Hamano226406f2005-05-27 15:50:30 -070087extern void diff_free_filepair(struct diff_filepair *);
88
Junio C Hamanof7c15122005-05-22 21:26:09 -070089extern int diff_unmodified_pair(struct diff_filepair *);
90
Junio C Hamano427dcb42005-05-21 02:39:09 -070091struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 02:40:01 -070092 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 02:39:09 -070093 int alloc;
94 int nr;
95};
Bo Yang9ca5df92010-05-06 21:52:27 -070096#define DIFF_QUEUE_CLEAR(q) \
97 do { \
98 (q)->queue = NULL; \
99 (q)->nr = (q)->alloc = 0; \
Jonathan Nieder98746062010-08-12 17:11:15 -0500100 } while (0)
Junio C Hamano427dcb42005-05-21 02:39:09 -0700101
Junio C Hamano38c6f782005-05-21 19:40:36 -0700102extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 02:40:01 -0700103extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
104 struct diff_filespec *,
105 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 10:04:37 -0700106extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-22 21:26:09 -0700107
Junio C Hamanoce240672005-06-03 01:36:43 -0700108extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700109extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 01:40:28 -0700110extern void diffcore_merge_broken(void);
Junio C Hamano382f0132010-08-31 13:44:39 -0700111extern void diffcore_pickaxe(struct diff_options *);
Junio C Hamanoce240672005-06-03 01:36:43 -0700112extern void diffcore_order(const char *orderfile);
113
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700114#define DIFF_DEBUG 0
115#if DIFF_DEBUG
116void diff_debug_filespec(struct diff_filespec *, int, const char *);
117void diff_debug_filepair(const struct diff_filepair *, int);
118void diff_debug_queue(const char *, struct diff_queue_struct *);
119#else
Jonathan Nieder98746062010-08-12 17:11:15 -0500120#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
121#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
122#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700123#endif
124
Junio C Hamanod8c3d032007-06-28 22:54:37 -0700125extern int diffcore_count_changes(struct diff_filespec *src,
126 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 03:22:10 -0800127 void **src_count_p,
128 void **dst_count_p,
Junio C Hamano65416752006-02-28 16:01:36 -0800129 unsigned long delta_limit,
130 unsigned long *src_copied,
131 unsigned long *literal_added);
132
Junio C Hamano427dcb42005-05-21 02:39:09 -0700133#endif