]> git.ipfire.org Git - thirdparty/git.git/blame - diffcore.h
Sync with maint
[thirdparty/git.git] / diffcore.h
CommitLineData
427dcb4b
JH
1/*
2 * Copyright (C) 2005 Junio C Hamano
3 */
e0173ad9
JH
4#ifndef DIFFCORE_H
5#define DIFFCORE_H
427dcb4b 6
ef3ca954
EN
7#include "cache.h"
8
9struct diff_options;
b78ea5fc
NTND
10struct repository;
11struct userdiff_driver;
ef3ca954 12
427dcb4b
JH
13/* This header file is internal between diff.c and its diff transformers
14 * (e.g. diffcore-rename, diffcore-pickaxe). Never include this header
15 * in anything else.
16 */
eeaa4603
JH
17
18/* We internally use unsigned short as the score value,
19 * and rely on an int capable to hold 32-bits. -B can take
20 * -Bmerge_score/break_score format and the two scores are
21 * passed around in one int (high 16-bit for merge and low 16-bit
22 * for break).
23 */
ee3d299e 24#define MAX_SCORE 60000.0
f345b0a0 25#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
4d0f39ce 26#define DEFAULT_BREAK_SCORE 30000 /* minimum for break to happen (50%) */
cf958afd 27#define DEFAULT_MERGE_SCORE 36000 /* maximum for break-merge to happen (60%) */
eeaa4603
JH
28
29#define MINIMUM_BREAK_SIZE 400 /* do not break a file smaller than this */
427dcb4b 30
13c4d7eb
HW
31/**
32 * the internal representation for a single file (blob). It records the blob
33 * object name (if known -- for a work tree file it typically is a NUL SHA-1),
34 * filemode and pathname. This is what the `diff_addremove()`, `diff_change()`
35 * and `diff_unmerge()` synthesize and feed `diff_queue()` function with.
36 */
427dcb4b 37struct diff_filespec {
a0d12c44 38 struct object_id oid;
427dcb4b
JH
39 char *path;
40 void *data;
c06c7966 41 void *cnt_data;
427dcb4b 42 unsigned long size;
9fb88419 43 int count; /* Reference count */
64479711 44 int rename_used; /* Count of rename users */
427dcb4b 45 unsigned short mode; /* file mode */
41c9560e 46 unsigned oid_valid : 1; /* if true, use oid and trust mode;
427dcb4b
JH
47 * if false, use the name and read from
48 * the filesystem.
49 */
dc7090ef 50#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
427dcb4b
JH
51 unsigned should_free : 1; /* data should be free()'ed */
52 unsigned should_munmap : 1; /* data should be munmap()'ed */
c7e1a736
JL
53 unsigned dirty_submodule : 2; /* For submodules: its work tree is dirty */
54#define DIRTY_SUBMODULE_UNTRACKED 1
55#define DIRTY_SUBMODULE_MODIFIED 2
b837f5d6 56 unsigned is_stdin : 1;
25e5e2bf 57 unsigned has_more_entries : 1; /* only appear in combined diff */
122aa6f9 58 /* data should be considered "binary"; -1 means "don't know yet" */
7d0a9a75 59 signed int is_binary : 2;
b38f70a8 60 struct userdiff_driver *driver;
427dcb4b
JH
61};
62
78d70d9b
NTND
63struct diff_filespec *alloc_filespec(const char *);
64void free_filespec(struct diff_filespec *);
65void fill_filespec(struct diff_filespec *, const struct object_id *,
66 int, unsigned short);
427dcb4b 67
8e5dd3d6 68#define CHECK_SIZE_ONLY 1
6bf3b813 69#define CHECK_BINARY 2
b78ea5fc 70int diff_populate_filespec(struct repository *, struct diff_filespec *, unsigned int);
78d70d9b
NTND
71void diff_free_filespec_data(struct diff_filespec *);
72void diff_free_filespec_blob(struct diff_filespec *);
b78ea5fc 73int diff_filespec_is_binary(struct repository *, struct diff_filespec *);
427dcb4b 74
13c4d7eb
HW
75/**
76 * This records a pair of `struct diff_filespec`; the filespec for a file in
77 * the "old" set (i.e. preimage) is called `one`, and the filespec for a file
78 * in the "new" set (i.e. postimage) is called `two`. A change that represents
79 * file creation has NULL in `one`, and file deletion has NULL in `two`.
80 *
81 * A `filepair` starts pointing at `one` and `two` that are from the same
82 * filename, but `diffcore_std()` can break pairs and match component filespecs
83 * with other filespecs from a different filepair to form new filepair. This is
84 * called 'rename detection'.
85 */
52e95789 86struct diff_filepair {
427dcb4b
JH
87 struct diff_filespec *one;
88 struct diff_filespec *two;
01c4e70f 89 unsigned short int score;
a5a323f3 90 char status; /* M C R A D U etc. (see Documentation/diff-format.txt or DIFF_STATUS_* in diff.h) */
f345b0a0 91 unsigned broken_pair : 1;
ef677686 92 unsigned renamed_pair : 1;
e9c84099 93 unsigned is_unmerged : 1;
f34b205f
NTND
94 unsigned done_skip_stat_unmatch : 1;
95 unsigned skip_stat_unmatch_result : 1;
427dcb4b 96};
13c4d7eb 97
e9c84099 98#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
427dcb4b 99
ef677686 100#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
01c4e70f 101
f345b0a0
JH
102#define DIFF_PAIR_BROKEN(p) \
103 ( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
104 ((p)->broken_pair != 0) )
105
96716a19
JH
106#define DIFF_PAIR_TYPE_CHANGED(p) \
107 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
108
4130b995
JH
109#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
110
78d70d9b 111void diff_free_filepair(struct diff_filepair *);
226406f6 112
78d70d9b 113int diff_unmodified_pair(struct diff_filepair *);
f7c1512a 114
13c4d7eb
HW
115/**
116 * This is a collection of filepairs. Notable members are:
117 *
118 * - `queue`:
119 * An array of pointers to `struct diff_filepair`. This dynamically grows as
120 * you add filepairs;
121 *
122 * - `alloc`:
123 * The allocated size of the `queue` array;
124 *
125 * - `nr`:
126 * The number of elements in the `queue` array.
127 */
427dcb4b 128struct diff_queue_struct {
52e95789 129 struct diff_filepair **queue;
427dcb4b
JH
130 int alloc;
131 int nr;
132};
13c4d7eb 133
9ca5df90
BY
134#define DIFF_QUEUE_CLEAR(q) \
135 do { \
136 (q)->queue = NULL; \
137 (q)->nr = (q)->alloc = 0; \
98746061 138 } while (0)
427dcb4b 139
38c6f780 140extern struct diff_queue_struct diff_queued_diff;
78d70d9b
NTND
141struct diff_filepair *diff_queue(struct diff_queue_struct *,
142 struct diff_filespec *,
143 struct diff_filespec *);
144void diff_q(struct diff_queue_struct *, struct diff_filepair *);
f7c1512a 145
b78ea5fc 146void diffcore_break(struct repository *, int);
78d70d9b
NTND
147void diffcore_rename(struct diff_options *);
148void diffcore_merge_broken(void);
149void diffcore_pickaxe(struct diff_options *);
150void diffcore_order(const char *orderfile);
ce240675 151
1df4320f
KS
152/* low-level interface to diffcore_order */
153struct obj_order {
154 void *obj; /* setup by caller */
155
156 /* setup/used by order_objects() */
157 int orig_order;
158 int order;
159};
160
161typedef const char *(*obj_path_fn_t)(void *obj);
162
163void order_objects(const char *orderfile, obj_path_fn_t obj_path,
164 struct obj_order *objs, int nr);
165
25d5ea41
JH
166#define DIFF_DEBUG 0
167#if DIFF_DEBUG
168void diff_debug_filespec(struct diff_filespec *, int, const char *);
169void diff_debug_filepair(const struct diff_filepair *, int);
170void diff_debug_queue(const char *, struct diff_queue_struct *);
171#else
98746061
JN
172#define diff_debug_filespec(a,b,c) do { /* nothing */ } while (0)
173#define diff_debug_filepair(a,b) do { /* nothing */ } while (0)
174#define diff_debug_queue(a,b) do { /* nothing */ } while (0)
25d5ea41
JH
175#endif
176
b78ea5fc
NTND
177int diffcore_count_changes(struct repository *r,
178 struct diff_filespec *src,
78d70d9b
NTND
179 struct diff_filespec *dst,
180 void **src_count_p,
181 void **dst_count_p,
182 unsigned long *src_copied,
183 unsigned long *literal_added);
65416758 184
427dcb4b 185#endif