1/*
2* Copyright (C) 2005 Junio C Hamano
3*/
4#ifndef _DIFFCORE_H_
5#define _DIFFCORE_H_
67
/* 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 60000
12#define DEFAULT_RENAME_SCORE 30000 /* rename/copy similarity minimum (50%) */
13#define DEFAULT_BREAK_SCORE 59400 /* minimum for break to happen (99%)*/
1415
#define RENAME_DST_MATCHED 01
1617
struct diff_filespec {
18unsigned char sha1[20];
19char *path;
20void *data;
21unsigned long size;
22int xfrm_flags; /* for use by the xfrm */
23unsigned short mode; /* file mode */
24unsigned sha1_valid : 1; /* if true, use sha1 and trust mode;
25* if false, use the name and read from
26* the filesystem.
27*/
28#define DIFF_FILE_VALID(spec) (((spec)->mode) != 0)
29unsigned should_free : 1; /* data should be free()'ed */
30unsigned should_munmap : 1; /* data should be munmap()'ed */
31};
3233
extern struct diff_filespec *alloc_filespec(const char *);
34extern void fill_filespec(struct diff_filespec *, const unsigned char *,
35unsigned short);
3637
extern int diff_populate_filespec(struct diff_filespec *, int);
38extern void diff_free_filespec_data(struct diff_filespec *);
3940
struct diff_filepair {
41struct diff_filespec *one;
42struct diff_filespec *two;
43unsigned short int score;
44char status; /* M C R N D U (see Documentation/diff-format.txt) */
45unsigned source_stays : 1; /* all of R/C are copies */
46unsigned broken_pair : 1;
47};
48#define DIFF_PAIR_UNMERGED(p) \
49(!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
5051
#define DIFF_PAIR_RENAME(p) (strcmp((p)->one->path, (p)->two->path))
5253
#define DIFF_PAIR_BROKEN(p) \
54( (!DIFF_FILE_VALID((p)->one) != !DIFF_FILE_VALID((p)->two)) && \
55((p)->broken_pair != 0) )
5657
#define DIFF_PAIR_TYPE_CHANGED(p) \
58((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
5960
#define DIFF_PAIR_MODE_CHANGED(p) ((p)->one->mode != (p)->two->mode)
6162
#define DIFF_FILE_CANON_MODE(mode) \
63(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
64S_ISLNK(mode) ? S_IFLNK : S_IFDIR)
6566
extern void diff_free_filepair(struct diff_filepair *);
6768
extern int diff_unmodified_pair(struct diff_filepair *);
6970
struct diff_queue_struct {
71struct diff_filepair **queue;
72int alloc;
73int nr;
74};
7576
extern struct diff_queue_struct diff_queued_diff;
77extern struct diff_filepair *diff_queue(struct diff_queue_struct *,
78struct diff_filespec *,
79struct diff_filespec *);
80extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
8182
#define DIFF_DEBUG 0
83#if DIFF_DEBUG
84void diff_debug_filespec(struct diff_filespec *, int, const char *);
85void diff_debug_filepair(const struct diff_filepair *, int);
86void diff_debug_queue(const char *, struct diff_queue_struct *);
87#else
88#define diff_debug_filespec(a,b,c) do {} while(0)
89#define diff_debug_filepair(a,b) do {} while(0)
90#define diff_debug_queue(a,b) do {} while(0)
91#endif
9293
#endif