2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
9 static const char *diff_files_usage
=
10 "git-diff-files [-q] "
11 "[<common diff options>] [<path>...]"
12 COMMON_DIFF_OPTIONS_HELP
;
14 static int diff_output_format
= DIFF_FORMAT_HUMAN
;
15 static int detect_rename
= 0;
16 static int find_copies_harder
= 0;
17 static int diff_setup_opt
= 0;
18 static int diff_score_opt
= 0;
19 static const char *pickaxe
= NULL
;
20 static int pickaxe_opts
= 0;
21 static int diff_break_opt
= -1;
22 static const char *orderfile
= NULL
;
23 static const char *diff_filter
= NULL
;
24 static int silent
= 0;
26 static void show_unmerge(const char *path
)
31 static void show_file(int pfx
, struct cache_entry
*ce
)
33 diff_addremove(pfx
, ntohl(ce
->ce_mode
), ce
->sha1
, ce
->name
, NULL
);
36 static void show_modified(int oldmode
, int mode
,
37 const unsigned char *old_sha1
, const unsigned char *sha1
,
40 diff_change(oldmode
, mode
, old_sha1
, sha1
, path
, NULL
);
43 int main(int argc
, const char **argv
)
45 static const unsigned char null_sha1
[20] = { 0, };
46 const char **pathspec
;
47 int entries
= read_cache();
50 while (1 < argc
&& argv
[1][0] == '-') {
51 if (!strcmp(argv
[1], "-p") || !strcmp(argv
[1], "-u"))
52 diff_output_format
= DIFF_FORMAT_PATCH
;
53 else if (!strcmp(argv
[1], "-q"))
55 else if (!strcmp(argv
[1], "-r"))
57 else if (!strcmp(argv
[1], "-s"))
59 else if (!strcmp(argv
[1], "-z"))
60 diff_output_format
= DIFF_FORMAT_MACHINE
;
61 else if (!strcmp(argv
[1], "--name-only"))
62 diff_output_format
= DIFF_FORMAT_NAME
;
63 else if (!strcmp(argv
[1], "--name-only-z"))
64 diff_output_format
= DIFF_FORMAT_NAME_Z
;
65 else if (!strcmp(argv
[1], "-R"))
66 diff_setup_opt
|= DIFF_SETUP_REVERSE
;
67 else if (!strncmp(argv
[1], "-S", 2))
68 pickaxe
= argv
[1] + 2;
69 else if (!strncmp(argv
[1], "-O", 2))
70 orderfile
= argv
[1] + 2;
71 else if (!strncmp(argv
[1], "--diff-filter=", 14))
72 diff_filter
= argv
[1] + 14;
73 else if (!strcmp(argv
[1], "--pickaxe-all"))
74 pickaxe_opts
= DIFF_PICKAXE_ALL
;
75 else if (!strncmp(argv
[1], "-B", 2)) {
77 diff_scoreopt_parse(argv
[1])) == -1)
78 usage(diff_files_usage
);
80 else if (!strncmp(argv
[1], "-M", 2)) {
82 diff_scoreopt_parse(argv
[1])) == -1)
83 usage(diff_files_usage
);
84 detect_rename
= DIFF_DETECT_RENAME
;
86 else if (!strncmp(argv
[1], "-C", 2)) {
88 diff_scoreopt_parse(argv
[1])) == -1)
89 usage(diff_files_usage
);
90 detect_rename
= DIFF_DETECT_COPY
;
92 else if (!strcmp(argv
[1], "--find-copies-harder"))
93 find_copies_harder
= 1;
95 usage(diff_files_usage
);
99 /* Do we have a pathspec? */
100 pathspec
= (argc
> 1) ? argv
+ 1 : NULL
;
102 if (find_copies_harder
&& detect_rename
!= DIFF_DETECT_COPY
)
103 usage(diff_files_usage
);
105 /* At this point, if argc == 1, then we are doing everything.
106 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
109 perror("read_cache");
113 diff_setup(diff_setup_opt
);
115 for (i
= 0; i
< entries
; i
++) {
117 unsigned int oldmode
;
118 struct cache_entry
*ce
= active_cache
[i
];
121 if (!ce_path_match(ce
, pathspec
))
125 show_unmerge(ce
->name
);
126 while (i
< entries
&&
127 !strcmp(ce
->name
, active_cache
[i
]->name
))
129 i
--; /* compensate for loop control increments */
133 if (lstat(ce
->name
, &st
) < 0) {
134 if (errno
!= ENOENT
&& errno
!= ENOTDIR
) {
143 changed
= ce_match_stat(ce
, &st
);
144 if (!changed
&& !find_copies_harder
)
146 oldmode
= ntohl(ce
->ce_mode
);
147 show_modified(oldmode
, DIFF_FILE_CANON_MODE(st
.st_mode
),
148 ce
->sha1
, (changed
? null_sha1
: ce
->sha1
),
151 diffcore_std(pathspec
,
152 detect_rename
, diff_score_opt
,
153 pickaxe
, pickaxe_opts
,
155 orderfile
, diff_filter
);
156 diff_flush(diff_output_format
);