blob: 5b634585e8970de81067b9807d8813c083b86b0a [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%) */
21#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 */
Jeff King122aa6f2008-10-05 17:43:36 -040045
46 struct userdiff_driver *driver;
47 /* data should be considered "binary"; -1 means "don't know yet" */
48 int is_binary;
Junio C Hamano427dcb42005-05-21 02:39:09 -070049};
50
51extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 11:19:10 -070052extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070053extern void fill_filespec(struct diff_filespec *, const unsigned char *,
54 unsigned short);
55
Junio C Hamanof0c6b2a2005-05-27 15:56:38 -070056extern int diff_populate_filespec(struct diff_filespec *, int);
Junio C Hamano19397b42005-09-14 14:06:50 -070057extern void diff_free_filespec_data(struct diff_filespec *);
Junio C Hamano8ae92e62007-10-02 21:01:03 -070058extern void diff_free_filespec_blob(struct diff_filespec *);
Junio C Hamano29a3eef2007-07-06 00:18:54 -070059extern int diff_filespec_is_binary(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 02:39:09 -070060
Junio C Hamano52e95782005-05-21 02:40:01 -070061struct diff_filepair {
Junio C Hamano427dcb42005-05-21 02:39:09 -070062 struct diff_filespec *one;
63 struct diff_filespec *two;
Junio C Hamano01c4e702005-05-29 16:56:48 -070064 unsigned short int score;
Yann Dirsona5a323f2008-11-02 14:37:28 +010065 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 -070066 unsigned broken_pair : 1;
Junio C Hamanoef677682006-08-03 12:01:01 -070067 unsigned renamed_pair : 1;
Junio C Hamanoe9c84092007-01-05 01:25:18 -080068 unsigned is_unmerged : 1;
Junio C Hamano427dcb42005-05-21 02:39:09 -070069};
Junio C Hamanoe9c84092007-01-05 01:25:18 -080070#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 02:39:09 -070071
Junio C Hamanoef677682006-08-03 12:01:01 -070072#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 16:56:48 -070073
Junio C Hamanof345b0a2005-05-30 00:08:37 -070074#define DIFF_PAIR_BROKEN(p) \
75 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
76 ((p)->broken_pair != 0) )
77
Junio C Hamano96716a12005-05-25 15:07:08 -070078#define DIFF_PAIR_TYPE_CHANGED(p) \
79 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
80
Junio C Hamano4130b992005-05-26 02:24:30 -070081#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
82
Junio C Hamano226406f2005-05-27 15:50:30 -070083extern void diff_free_filepair(struct diff_filepair *);
84
Junio C Hamanof7c15122005-05-22 21:26:09 -070085extern int diff_unmodified_pair(struct diff_filepair *);
86
Junio C Hamano427dcb42005-05-21 02:39:09 -070087struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 02:40:01 -070088 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 02:39:09 -070089 int alloc;
90 int nr;
91};
92
Junio C Hamano38c6f782005-05-21 19:40:36 -070093extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 02:40:01 -070094extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
95 struct diff_filespec *,
96 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 10:04:37 -070097extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-22 21:26:09 -070098
Junio C Hamanoce240672005-06-03 01:36:43 -070099extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 00:18:27 -0700100extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 01:40:28 -0700101extern void diffcore_merge_broken(void);
Junio C Hamanoce240672005-06-03 01:36:43 -0700102extern void diffcore_pickaxe(const char *needle, int opts);
103extern void diffcore_order(const char *orderfile);
104
Junio C Hamano25d5ea42005-05-24 01:10:48 -0700105#define DIFF_DEBUG 0
106#if DIFF_DEBUG
107void diff_debug_filespec(struct diff_filespec *, int, const char *);
108void diff_debug_filepair(const struct diff_filepair *, int);
109void diff_debug_queue(const char *, struct diff_queue_struct *);
110#else
111#define diff_debug_filespec(a,b,c) do {} while(0)
112#define diff_debug_filepair(a,b) do {} while(0)
113#define diff_debug_queue(a,b) do {} while(0)
114#endif
115
Junio C Hamanod8c3d032007-06-28 22:54:37 -0700116extern int diffcore_count_changes(struct diff_filespec *src,
117 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 03:22:10 -0800118 void **src_count_p,
119 void **dst_count_p,
Junio C Hamano65416752006-02-28 16:01:36 -0800120 unsigned long delta_limit,
121 unsigned long *src_copied,
122 unsigned long *literal_added);
123
Junio C Hamano427dcb42005-05-21 02:39:09 -0700124#endif