🌐 AI搜索 & 代理 主页
blob: 66687c3fe5ea4552cff2b864b73696460ca40b1e [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%) */
21#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 Hamanoe0e324a2007-07-07 08:49:5832 const char *funcname_pattern_ident;
Junio C Hamano427dcb42005-05-21 09:39:0933 unsigned long size;
Linus Torvalds9fb88412007-10-25 18:19:1034 int count; /* Reference count */
Junio C Hamano427dcb42005-05-21 09:39:0935 int xfrm_flags; /* for use by the xfrm */
Linus Torvalds64479712007-10-25 18:20:5636 int rename_used; /* Count of rename users */
Junio C Hamano427dcb42005-05-21 09:39:0937 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-13 00:23:1542#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
Junio C Hamano427dcb42005-05-21 09:39:0943 unsigned should_free : 1; /* data should be free()'ed */
44 unsigned should_munmap : 1; /* data should be munmap()'ed */
Jens Lehmanne3d42c42010-01-18 20:26:1845 unsigned dirty_submodule : 1; /* For submodules: its work tree is dirty */
Jeff King122aa6f2008-10-05 21:43:3646
47 struct userdiff_driver *driver;
48 /* data should be considered "binary"; -1 means "don't know yet" */
49 int is_binary;
Junio C Hamano427dcb42005-05-21 09:39:0950};
51
52extern struct diff_filespec *alloc_filespec(const char *);
Linus Torvalds9fb88412007-10-25 18:19:1053extern void free_filespec(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 09:39:0954extern void fill_filespec(struct diff_filespec *, const unsigned char *,
55 unsigned short);
56
Junio C Hamanof0c6b2a2005-05-27 22:56:3857extern int diff_populate_filespec(struct diff_filespec *, int);
Junio C Hamano19397b42005-09-14 21:06:5058extern void diff_free_filespec_data(struct diff_filespec *);
Junio C Hamano8ae92e62007-10-03 04:01:0359extern void diff_free_filespec_blob(struct diff_filespec *);
Junio C Hamano29a3eef2007-07-06 07:18:5460extern int diff_filespec_is_binary(struct diff_filespec *);
Junio C Hamano427dcb42005-05-21 09:39:0961
Junio C Hamano52e95782005-05-21 09:40:0162struct diff_filepair {
Junio C Hamano427dcb42005-05-21 09:39:0963 struct diff_filespec *one;
64 struct diff_filespec *two;
Junio C Hamano01c4e702005-05-29 23:56:4865 unsigned short int score;
Yann Dirsona5a323f2008-11-02 13:37:2866 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:3767 unsigned broken_pair : 1;
Junio C Hamanoef677682006-08-03 19:01:0168 unsigned renamed_pair : 1;
Junio C Hamanoe9c84092007-01-05 09:25:1869 unsigned is_unmerged : 1;
Junio C Hamano427dcb42005-05-21 09:39:0970};
Junio C Hamanoe9c84092007-01-05 09:25:1871#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
Junio C Hamano427dcb42005-05-21 09:39:0972
Junio C Hamanoef677682006-08-03 19:01:0173#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
Junio C Hamano01c4e702005-05-29 23:56:4874
Junio C Hamanof345b0a2005-05-30 07:08:3775#define DIFF_PAIR_BROKEN(p) \
76 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
77 ((p)->broken_pair != 0) )
78
Junio C Hamano96716a12005-05-25 22:07:0879#define DIFF_PAIR_TYPE_CHANGED(p) \
80 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
81
Junio C Hamano4130b992005-05-26 09:24:3082#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
83
Junio C Hamano226406f2005-05-27 22:50:3084extern void diff_free_filepair(struct diff_filepair *);
85
Junio C Hamanof7c15122005-05-23 04:26:0986extern int diff_unmodified_pair(struct diff_filepair *);
87
Junio C Hamano427dcb42005-05-21 09:39:0988struct diff_queue_struct {
Junio C Hamano52e95782005-05-21 09:40:0189 struct diff_filepair **queue;
Junio C Hamano427dcb42005-05-21 09:39:0990 int alloc;
91 int nr;
92};
93
Junio C Hamano38c6f782005-05-22 02:40:3694extern struct diff_queue_struct diff_queued_diff;
Junio C Hamano52e95782005-05-21 09:40:0195extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
96 struct diff_filespec *,
97 struct diff_filespec *);
Junio C Hamano6b14d7f2005-05-22 17:04:3798extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
Junio C Hamanof7c15122005-05-23 04:26:0999
Junio C Hamanoce240672005-06-03 08:36:43100extern void diffcore_break(int);
Junio C Hamano8082d8d2005-09-21 07:18:27101extern void diffcore_rename(struct diff_options *);
Junio C Hamanoeeaa4602005-06-03 08:40:28102extern void diffcore_merge_broken(void);
Junio C Hamanoce240672005-06-03 08:36:43103extern void diffcore_pickaxe(const char *needle, int opts);
104extern void diffcore_order(const char *orderfile);
105
Junio C Hamano25d5ea42005-05-24 08:10:48106#define DIFF_DEBUG 0
107#if DIFF_DEBUG
108void diff_debug_filespec(struct diff_filespec *, int, const char *);
109void diff_debug_filepair(const struct diff_filepair *, int);
110void diff_debug_queue(const char *, struct diff_queue_struct *);
111#else
112#define diff_debug_filespec(a,b,c) do {} while(0)
113#define diff_debug_filepair(a,b) do {} while(0)
114#define diff_debug_queue(a,b) do {} while(0)
115#endif
116
Junio C Hamanod8c3d032007-06-29 05:54:37117extern int diffcore_count_changes(struct diff_filespec *src,
118 struct diff_filespec *dst,
Junio C Hamanoc06c7962006-03-12 11:22:10119 void **src_count_p,
120 void **dst_count_p,
Junio C Hamano65416752006-03-01 00:01:36121 unsigned long delta_limit,
122 unsigned long *src_copied,
123 unsigned long *literal_added);
124
Junio C Hamano427dcb42005-05-21 09:39:09125#endif