[PATCH] diff: code clean-up and removal of rename hack.
[git/git.git] / diffcore.h
1 /*
2 * Copyright (C) 2005 Junio C Hamano
3 */
4 #ifndef _DIFFCORE_H_
5 #define _DIFFCORE_H_
6
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 */
11 #define MAX_SCORE 10000
12 #define DEFAULT_MINIMUM_SCORE 5000
13
14 #define RENAME_DST_MATCHED 01
15
16 struct diff_filespec {
17 unsigned char sha1[20];
18 char *path;
19 void *data;
20 unsigned long size;
21 int xfrm_flags; /* for use by the xfrm */
22 unsigned short mode; /* file mode */
23 unsigned sha1_valid : 1; /* if true, use sha1 and trust mode;
24 * if false, use the name and read from
25 * the filesystem.
26 */
27 #define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
28 unsigned should_free : 1; /* data should be free()'ed */
29 unsigned should_munmap : 1; /* data should be munmap()'ed */
30 };
31
32 extern struct diff_filespec *alloc_filespec(const char *);
33 extern void fill_filespec(struct diff_filespec *, const unsigned char *,
34 unsigned short);
35
36 extern int diff_populate_filespec(struct diff_filespec *, int);
37 extern void diff_free_filespec_data(struct diff_filespec *);
38
39 struct diff_filepair {
40 struct diff_filespec *one;
41 struct diff_filespec *two;
42 unsigned short int score;
43 char source_stays; /* all of R/C are copies */
44 char status; /* M C R N D U (see Documentation/diff-format.txt) */
45 };
46 #define DIFF_PAIR_UNMERGED(p) \
47 (!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
48
49 #define DIFF_PAIR_RENAME(p) (strcmp((p)->one->path, (p)->two->path))
50
51 #define DIFF_PAIR_TYPE_CHANGED(p) \
52 ((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
53
54 #define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
55
56 #define DIFF_FILE_CANON_MODE(mode) \
57 (S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
58 S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
59
60 extern void diff_free_filepair(struct diff_filepair *);
61
62 extern int diff_unmodified_pair(struct diff_filepair *);
63
64 struct diff_queue_struct {
65 struct diff_filepair **queue;
66 int alloc;
67 int nr;
68 };
69
70 extern struct diff_queue_struct diff_queued_diff;
71 extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
72 struct diff_filespec *,
73 struct diff_filespec *);
74 extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
75
76 #define DIFF_DEBUG 0
77 #if DIFF_DEBUG
78 void diff_debug_filespec(struct diff_filespec *, int, const char *);
79 void diff_debug_filepair(const struct diff_filepair *, int);
80 void diff_debug_queue(const char *, struct diff_queue_struct *);
81 #else
82 #define diff_debug_filespec(a,b,c) do {} while(0)
83 #define diff_debug_filepair(a,b) do {} while(0)
84 #define diff_debug_queue(a,b) do {} while(0)
85 #endif
86
87 #endif