blob: 8f32b824cdc1bac1f094d743f3bee9f32890edca [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 */
46#define DIRTY_SUBMODULE_UNTRACKED 1
47#define DIRTY_SUBMODULE_MODIFIED 2
Junio C Hamano25e5e2b2011-08-19 23:32:51 -070048 unsigned has_more_entries : 1; /* only appear in combined diff */
Jeff King122aa6f2008-10-05 17:43:36 -040049 struct userdiff_driver *driver;
50 /* data should be considered "binary"; -1 means "don't know yet" */
51 int is_binary;
Junio C Hamano427dcb42005-05-21 02:39:09 -070052};
53
54extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 11:19:10 -070055extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070056extern void fill_filespec(struct diff_filespec *, const unsigned char *,
57 unsigned short);
58
Junio C Hamanof0c6b2a2005-05-27 15:56:38 -070059extern int diff_populate_filespec(struct diff_filespec *, int);
Junio C Hamano19397b42005-09-14 14:06:50 -070060extern void diff_free_filespec_data(struct diff_filespec *);
Junio C Hamano8ae92e62007-10-02 21:01:03 -070061extern void diff_free_filespec_blob(struct diff_filespec *);
Junio C Hamano29a3eef2007-07-06 00:18:54 -070062extern int diff_filespec_is_binary(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070063
Junio C Hamano52e95782005-05-21 02:40:01 -070064struct diff_filepair {
Junio C Hamano427dcb42005-05-21 02:39:09 -070065 struct diff_filespec *one;
66 struct diff_filespec *two;
Junio C Hamano01c4e702005-05-29 16:56:48 -070067 unsigned short int score;
Yann Dirsona5a323f2008-11-02 14:37:28 +010068 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 -070069 unsigned broken_pair : 1;
Junio C Hamanoef677682006-08-03 12:01:01 -070070 unsigned renamed_pair : 1;
Junio C Hamanoe9c84092007-01-05 01:25:18 -080071 unsigned is_unmerged : 1;
Junio C Hamano427dcb42005-05-21 02:39:09 -070072};
Junio C Hamanoe9c84092007-01-05 01:25:18 -080073#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 02:39:09 -070074
Junio C Hamanoef677682006-08-03 12:01:01 -070075#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 16:56:48 -070076
Junio C Hamanof345b0a2005-05-30 00:08:37 -070077#define DIFF_PAIR_BROKEN(p) \
78 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
79 ((p)->broken_pair != 0) )
80
Junio C Hamano96716a12005-05-25 15:07:08 -070081#define DIFF_PAIR_TYPE_CHANGED(p) \
82 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
83
Junio C Hamano4130b992005-05-26 02:24:30 -070084#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
85
Junio C Hamano226406f2005-05-27 15:50:30 -070086extern void diff_free_filepair(struct diff_filepair *);
87
Junio C Hamanof7c15122005-05-22 21:26:09 -070088extern int diff_unmodified_pair(struct diff_filepair *);
89
Junio C Hamano427dcb42005-05-21 02:39:09 -070090struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 02:40:01 -070091 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 02:39:09 -070092 int alloc;
93 int nr;
94};
Bo Yang9ca5df92010-05-06 21:52:27 -070095#define DIFF_QUEUE_CLEAR(q) \
96 do { \
97 (q)->queue = NULL; \
98 (q)->nr = (q)->alloc = 0; \
Jonathan Nieder98746062010-08-12 17:11:15 -050099 } while (0)
Junio C Hamano427dcb42005-05-21 02:39:09 -0700100
Junio C Hamano38c6f782005-05-21 19:40:36 -0700101extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 02:40:01 -0700102extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
103 struct diff_filespec *,
104 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 10:04:37 -0700105extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-22 21:26:09 -0700106
Junio C Hamanoce240672005-06-03 01:36:43 -0700107extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700108extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 01:40:28 -0700109extern void diffcore_merge_broken(void);
Junio C Hamano382f0132010-08-31 13:44:39 -0700110extern void diffcore_pickaxe(struct diff_options *);
Junio C Hamanoce240672005-06-03 01:36:43 -0700111extern void diffcore_order(const char *orderfile);
112
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700113#define DIFF_DEBUG 0
114#if DIFF_DEBUG
115void diff_debug_filespec(struct diff_filespec *, int, const char *);
116void diff_debug_filepair(const struct diff_filepair *, int);
117void diff_debug_queue(const char *, struct diff_queue_struct *);
118#else
Jonathan Nieder98746062010-08-12 17:11:15 -0500119#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
120#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
121#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700122#endif
123
Junio C Hamanod8c3d032007-06-28 22:54:37 -0700124extern int diffcore_count_changes(struct diff_filespec *src,
125 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 03:22:10 -0800126 void **src_count_p,
127 void **dst_count_p,
Junio C Hamano65416752006-02-28 16:01:36 -0800128 unsigned long delta_limit,
129 unsigned long *src_copied,
130 unsigned long *literal_added);
131
Junio C Hamano427dcb42005-05-21 02:39:09 -0700132#endif