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>] [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 silent
= 0;
20 static void show_unmerge(const char *path
)
25 static void show_file(int pfx
, struct cache_entry
*ce
)
27 diff_addremove(pfx
, ntohl(ce
->ce_mode
), ce
->sha1
, ce
->name
, NULL
);
30 static void show_modified(int oldmode
, int mode
,
31 const unsigned char *old_sha1
, const unsigned char *sha1
,
34 diff_change(oldmode
, mode
, old_sha1
, sha1
, path
, NULL
);
37 int main(int argc
, const char **argv
)
39 static const unsigned char null_sha1
[20] = { 0, };
40 int entries
= read_cache();
43 while (1 < argc
&& argv
[1][0] == '-') {
44 if (!strcmp(argv
[1], "-p"))
45 diff_output_format
= DIFF_FORMAT_PATCH
;
46 else if (!strcmp(argv
[1], "-q"))
48 else if (!strcmp(argv
[1], "-r"))
50 else if (!strcmp(argv
[1], "-s"))
52 else if (!strcmp(argv
[1], "-z"))
53 diff_output_format
= DIFF_FORMAT_MACHINE
;
54 else if (!strcmp(argv
[1], "-R"))
55 diff_setup_opt
|= DIFF_SETUP_REVERSE
;
56 else if (!strncmp(argv
[1], "-S", 2))
57 pickaxe
= argv
[1] + 2;
58 else if (!strcmp(argv
[1], "--pickaxe-all"))
59 pickaxe_opts
= DIFF_PICKAXE_ALL
;
60 else if (!strncmp(argv
[1], "-M", 2)) {
61 diff_score_opt
= diff_scoreopt_parse(argv
[1]);
62 detect_rename
= DIFF_DETECT_RENAME
;
64 else if (!strncmp(argv
[1], "-C", 2)) {
65 diff_score_opt
= diff_scoreopt_parse(argv
[1]);
66 detect_rename
= DIFF_DETECT_COPY
;
69 usage(diff_files_usage
);
73 /* At this point, if argc == 1, then we are doing everything.
74 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
81 diff_setup(diff_setup_opt
);
83 for (i
= 0; i
< entries
; i
++) {
85 unsigned int oldmode
, mode
;
86 struct cache_entry
*ce
= active_cache
[i
];
90 show_unmerge(ce
->name
);
92 !strcmp(ce
->name
, active_cache
[i
]->name
))
94 i
--; /* compensate for loop control increments */
98 if (lstat(ce
->name
, &st
) < 0) {
99 if (errno
!= ENOENT
&& errno
!= ENOTDIR
) {
108 changed
= ce_match_stat(ce
, &st
);
109 if (!changed
&& detect_rename
< DIFF_DETECT_COPY
)
112 oldmode
= ntohl(ce
->ce_mode
);
113 mode
= (S_ISLNK(st
.st_mode
) ? S_IFLNK
:
114 S_IFREG
| ce_permissions(st
.st_mode
));
116 show_modified(oldmode
, mode
, ce
->sha1
, null_sha1
,
120 diffcore_pathspec(argv
+ 1);
122 diffcore_rename(detect_rename
, diff_score_opt
);
124 diffcore_pickaxe(pickaxe
, pickaxe_opts
);
125 diff_flush(diff_output_format
, 1);