2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 static const char *diff_files_usage
=
10 "git-diff-files [-p] [-q] [-r] [-z] [-M] [-C] [-R] [-S<string>] [-O<orderfile>] [paths...]";
12 static int diff_output_format
= DIFF_FORMAT_HUMAN
;
13 static int detect_rename
= 0;
14 static int diff_setup_opt
= 0;
15 static int diff_score_opt
= 0;
16 static const char *pickaxe
= NULL
;
17 static int pickaxe_opts
= 0;
18 static int diff_break_opt
= -1;
19 static const char *orderfile
= NULL
;
20 static const char *diff_filter
= NULL
;
21 static int silent
= 0;
23 static void show_unmerge(const char *path
)
28 static void show_file(int pfx
, struct cache_entry
*ce
)
30 diff_addremove(pfx
, ntohl(ce
->ce_mode
), ce
->sha1
, ce
->name
, NULL
);
33 static void show_modified(int oldmode
, int mode
,
34 const unsigned char *old_sha1
, const unsigned char *sha1
,
37 diff_change(oldmode
, mode
, old_sha1
, sha1
, path
, NULL
);
40 int main(int argc
, const char **argv
)
42 static const unsigned char null_sha1
[20] = { 0, };
43 int entries
= read_cache();
46 while (1 < argc
&& argv
[1][0] == '-') {
47 if (!strcmp(argv
[1], "-p"))
48 diff_output_format
= DIFF_FORMAT_PATCH
;
49 else if (!strcmp(argv
[1], "-q"))
51 else if (!strcmp(argv
[1], "-r"))
53 else if (!strcmp(argv
[1], "-s"))
55 else if (!strcmp(argv
[1], "-z"))
56 diff_output_format
= DIFF_FORMAT_MACHINE
;
57 else if (!strcmp(argv
[1], "-R"))
58 diff_setup_opt
|= DIFF_SETUP_REVERSE
;
59 else if (!strncmp(argv
[1], "-S", 2))
60 pickaxe
= argv
[1] + 2;
61 else if (!strncmp(argv
[1], "-O", 2))
62 orderfile
= argv
[1] + 2;
63 else if (!strncmp(argv
[1], "--diff-filter=", 14))
64 diff_filter
= argv
[1] + 14;
65 else if (!strcmp(argv
[1], "--pickaxe-all"))
66 pickaxe_opts
= DIFF_PICKAXE_ALL
;
67 else if (!strncmp(argv
[1], "-B", 2)) {
69 diff_scoreopt_parse(argv
[1])) == -1)
70 usage(diff_files_usage
);
72 else if (!strncmp(argv
[1], "-M", 2)) {
74 diff_scoreopt_parse(argv
[1])) == -1)
75 usage(diff_files_usage
);
76 detect_rename
= DIFF_DETECT_RENAME
;
78 else if (!strncmp(argv
[1], "-C", 2)) {
80 diff_scoreopt_parse(argv
[1])) == -1)
81 usage(diff_files_usage
);
82 detect_rename
= DIFF_DETECT_COPY
;
85 usage(diff_files_usage
);
89 /* At this point, if argc == 1, then we are doing everything.
90 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
97 diff_setup(diff_setup_opt
);
99 for (i
= 0; i
< entries
; i
++) {
101 unsigned int oldmode
;
102 struct cache_entry
*ce
= active_cache
[i
];
106 show_unmerge(ce
->name
);
107 while (i
< entries
&&
108 !strcmp(ce
->name
, active_cache
[i
]->name
))
110 i
--; /* compensate for loop control increments */
114 if (lstat(ce
->name
, &st
) < 0) {
115 if (errno
!= ENOENT
&& errno
!= ENOTDIR
) {
124 changed
= ce_match_stat(ce
, &st
);
125 if (!changed
&& detect_rename
< DIFF_DETECT_COPY
)
128 oldmode
= ntohl(ce
->ce_mode
);
129 show_modified(oldmode
, DIFF_FILE_CANON_MODE(st
.st_mode
),
133 diffcore_std((1 < argc
) ? argv
+ 1 : NULL
,
134 detect_rename
, diff_score_opt
,
135 pickaxe
, pickaxe_opts
,
137 orderfile
, diff_filter
);
138 diff_flush(diff_output_format
);