🌐 AI搜索 & 代理 主页
blob: 33ea2de348803b29a08a6713ae4cab1345f874d9 [file] [log] [blame]
Junio C Hamano427dcb42005-05-21 09:39:091/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
Junio C Hamanoe0173ad2007-04-29 06:38:524#ifndef DIFFCORE_H
5#define DIFFCORE_H
Junio C Hamano427dcb42005-05-21 09:39:096
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 08:40:2811
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-16 05:08:4218#define MAX_SCORE 60000.0
Junio C Hamanof345b0a2005-05-30 07:08:3719#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
Junio C Hamano4d0f39c2006-03-04 09:03:5320#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
Matthieu Moycf958af2010-08-05 16:14:2521#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */
Junio C Hamanoeeaa4602005-06-03 08:40:2822
23#define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
Junio C Hamano427dcb42005-05-21 09:39:0924
Jeff King122aa6f2008-10-05 21:43:3625struct userdiff_driver;
26
Junio C Hamano427dcb42005-05-21 09:39:0927struct diff_filespec {
28 unsigned char sha1[20];
29 char *path;
30 void *data;
Junio C Hamanoc06c7962006-03-12 11:22:1031 void *cnt_data;
Junio C Hamano427dcb42005-05-21 09:39:0932 unsigned long size;
Linus Torvalds9fb88412007-10-25 18:19:1033 int count; /* Reference count */
Linus Torvalds64479712007-10-25 18:20:5634 int rename_used; /* Count of rename users */
Junio C Hamano427dcb42005-05-21 09:39:0935 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-13 00:23:1540#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
Junio C Hamano427dcb42005-05-21 09:39:0941 unsigned should_free : 1; /* data should be free()'ed */
42 unsigned should_munmap : 1; /* data should be munmap()'ed */
Jens Lehmannc7e1a732010-03-04 21:20:3343 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
Jens Lehmannc7e1a732010-03-04 21:20:3344#define DIRTY_SUBMODULE_UNTRACKED 1
45#define DIRTY_SUBMODULE_MODIFIED 2
Jeff Kingb837f5d2014-01-17 01:19:4646 unsigned is_stdin : 1;
Junio C Hamano25e5e2b2011-08-20 06:32:5147 unsigned has_more_entries : 1; /* only appear in combined diff */
Jeff King122aa6f2008-10-05 21:43:3648 /* data should be considered "binary"; -1 means "don't know yet" */
Richard Lowe7d0a9a72014-02-24 00:54:4749 signed int is_binary : 2;
Jeff Kingb38f70a2014-01-17 01:22:5650 struct userdiff_driver *driver;
Junio C Hamano427dcb42005-05-21 09:39:0951};
52
53extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 18:19:1054extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 09:39:0955extern void fill_filespec(struct diff_filespec *, const unsigned char *,
Jeff Kinge5450102012-07-28 15:03:0156 int, unsigned short);
Junio C Hamano427dcb42005-05-21 09:39:0957
Nguyễn Thái Ngọc Duy8e5dd3d2014-08-16 03:08:0458#define CHECK_SIZE_ONLY 1
Nguyễn Thái Ngọc Duy6bf3b812014-08-16 03:08:0559#define CHECK_BINARY 2
Nguyễn Thái Ngọc Duy8e5dd3d2014-08-16 03:08:0460extern int diff_populate_filespec(struct diff_filespec *, unsigned int);
Junio C Hamano19397b42005-09-14 21:06:5061extern void diff_free_filespec_data(struct diff_filespec *);
Junio C Hamano8ae92e62007-10-03 04:01:0362extern void diff_free_filespec_blob(struct diff_filespec *);
Junio C Hamano29a3eef2007-07-06 07:18:5463extern int diff_filespec_is_binary(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 09:39:0964
Junio C Hamano52e95782005-05-21 09:40:0165struct diff_filepair {
Junio C Hamano427dcb42005-05-21 09:39:0966 struct diff_filespec *one;
67 struct diff_filespec *two;
Junio C Hamano01c4e702005-05-29 23:56:4868 unsigned short int score;
Yann Dirsona5a323f2008-11-02 13:37:2869 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 07:08:3770 unsigned broken_pair : 1;
Junio C Hamanoef677682006-08-03 19:01:0171 unsigned renamed_pair : 1;
Junio C Hamanoe9c84092007-01-05 09:25:1872 unsigned is_unmerged : 1;
Nguyễn Thái Ngọc Duyf34b2052014-01-25 06:46:5073 unsigned done_skip_stat_unmatch : 1;
74 unsigned skip_stat_unmatch_result : 1;
Junio C Hamano427dcb42005-05-21 09:39:0975};
Junio C Hamanoe9c84092007-01-05 09:25:1876#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 09:39:0977
Junio C Hamanoef677682006-08-03 19:01:0178#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 23:56:4879
Junio C Hamanof345b0a2005-05-30 07:08:3780#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 22:07:0884#define DIFF_PAIR_TYPE_CHANGED(p) \
85 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
86
Junio C Hamano4130b992005-05-26 09:24:3087#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
88
Junio C Hamano226406f2005-05-27 22:50:3089extern void diff_free_filepair(struct diff_filepair *);
90
Junio C Hamanof7c15122005-05-23 04:26:0991extern int diff_unmodified_pair(struct diff_filepair *);
92
Junio C Hamano427dcb42005-05-21 09:39:0993struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 09:40:0194 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 09:39:0995 int alloc;
96 int nr;
97};
Bo Yang9ca5df92010-05-07 04:52:2798#define DIFF_QUEUE_CLEAR(q) \
99 do { \
100 (q)->queue = NULL; \
101 (q)->nr = (q)->alloc = 0; \
Jonathan Nieder98746062010-08-12 22:11:15102 } while (0)
Junio C Hamano427dcb42005-05-21 09:39:09103
Junio C Hamano38c6f782005-05-22 02:40:36104extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 09:40:01105extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
106 struct diff_filespec *,
107 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 17:04:37108extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-23 04:26:09109
Junio C Hamanoce240672005-06-03 08:36:43110extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 07:18:27111extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 08:40:28112extern void diffcore_merge_broken(void);
Junio C Hamano382f0132010-08-31 20:44:39113extern void diffcore_pickaxe(struct diff_options *);
Junio C Hamanoce240672005-06-03 08:36:43114extern void diffcore_order(const char *orderfile);
115
Kirill Smelkov1df43202014-01-20 16:20:38116/* 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 08:10:48130#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 22:11:15136#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 08:10:48139#endif
140
Junio C Hamanod8c3d032007-06-29 05:54:37141extern int diffcore_count_changes(struct diff_filespec *src,
142 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 11:22:10143 void **src_count_p,
144 void **dst_count_p,
Junio C Hamano65416752006-03-01 00:01:36145 unsigned long delta_limit,
146 unsigned long *src_copied,
147 unsigned long *literal_added);
148
Junio C Hamano427dcb42005-05-21 09:39:09149#endif