2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
8 static const char *show_diff_usage
= "show-diff [-q] [-s] [-z] [paths...]";
10 static int recursive
= 0;
11 static int line_termination
= '\n';
12 static int silent
= 0;
13 static int silent_on_nonexisting_files
= 0;
15 static int matches_pathspec(struct cache_entry
*ce
, char **spec
, int cnt
)
18 int namelen
= ce_namelen(ce
);
19 for (i
= 0; i
< cnt
; i
++) {
20 int speclen
= strlen(spec
[i
]);
21 if (! strncmp(spec
[i
], ce
->name
, speclen
) &&
23 (ce
->name
[speclen
] == 0 ||
24 ce
->name
[speclen
] == '/'))
30 static void show_file(const char *prefix
, struct cache_entry
*ce
)
32 printf("%s%o\t%s\t%s\t%s%c", prefix
, ntohl(ce
->ce_mode
), "blob",
33 sha1_to_hex(ce
->sha1
), ce
->name
, line_termination
);
36 int main(int argc
, char **argv
)
38 static const char null_sha1_hex
[] = "0000000000000000000000000000000000000000";
39 int entries
= read_cache();
42 while (1 < argc
&& argv
[1][0] == '-') {
43 if (!strcmp(argv
[1], "-s"))
44 silent_on_nonexisting_files
= silent
= 1;
45 else if (!strcmp(argv
[1], "-q"))
46 silent_on_nonexisting_files
= 1;
47 else if (!strcmp(argv
[1], "-z"))
49 else if (!strcmp(argv
[1], "-r"))
50 recursive
= 1; /* No-op */
52 usage(show_diff_usage
);
56 /* At this point, if argc == 1, then we are doing everything.
57 * Otherwise argv[1] .. argv[argc-1] have the explicit paths.
64 for (i
= 0; i
< entries
; i
++) {
66 unsigned int oldmode
, mode
;
67 struct cache_entry
*ce
= active_cache
[i
];
71 ! matches_pathspec(ce
, argv
+1, argc
-1))
75 printf("U %s%c", ce
->name
, line_termination
);
78 !strcmp(ce
->name
, active_cache
[i
]->name
))
80 i
--; /* compensate for loop control increments */
84 if (stat(ce
->name
, &st
) < 0) {
85 if (errno
!= ENOENT
) {
89 if (silent_on_nonexisting_files
)
94 changed
= cache_match_stat(ce
, &st
);
98 oldmode
= ntohl(ce
->ce_mode
);
99 mode
= S_IFREG
| ce_permissions(st
.st_mode
);
101 printf("*%o->%o\t%s\t%s->%s\t%s%c",
102 oldmode
, mode
, "blob",
103 sha1_to_hex(ce
->sha1
), null_sha1_hex
,
104 ce
->name
, line_termination
);