summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b8f8092)
raw | patch | inline | side by side (parent: b8f8092)
author | Junio C Hamano <junkio@cox.net> | |
Sun, 17 Apr 2005 04:29:45 +0000 (21:29 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Sun, 17 Apr 2005 04:29:45 +0000 (21:29 -0700) |
This patch adds the -z option to the show-diff command,
primarily for use by scripts. The information emitted is
similar to that of -q option, but in a more machine readable
form. Records are terminated with NUL instead of LF, so that
the scripts can deal with pathnames with embedded newlines.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
primarily for use by scripts. The information emitted is
similar to that of -q option, but in a more machine readable
form. Records are terminated with NUL instead of LF, so that
the scripts can deal with pathnames with embedded newlines.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
show-diff.c | patch | blob | history |
diff --git a/show-diff.c b/show-diff.c
index f9e8c12f90e793bc039a6181a6b6424b3725f6dc..4221d3ae4c7a844627cd72c3f4772bbe94abda16 100644 (file)
--- a/show-diff.c
+++ b/show-diff.c
}
}
-static const char *show_diff_usage = "show-diff [-s] [-q] [paths...]";
+static const char *show_diff_usage = "show-diff [-s] [-q] [-z] [paths...]";
static int matches_pathspec(struct cache_entry *ce, char **spec, int cnt)
{
{
int silent = 0;
int silent_on_nonexisting_files = 0;
+ int machine_readable = 0;
int entries = read_cache();
int i;
silent_on_nonexisting_files = silent = 1;
else if (!strcmp(argv[1], "-q"))
silent_on_nonexisting_files = 1;
+ else if (!strcmp(argv[1], "-z")) {
+ machine_readable = 1;
+ }
else
usage(show_diff_usage);
argv++; argc--;
for (i = 0; i < entries; i++) {
struct stat st;
struct cache_entry *ce = active_cache[i];
- int n, changed;
+ int changed;
unsigned long size;
char type[20];
void *new;
if (stat(ce->name, &st) < 0) {
if (errno == ENOENT && silent_on_nonexisting_files)
continue;
- printf("%s: %s\n", ce->name, strerror(errno));
- if (errno == ENOENT)
- show_diff_empty(ce);
+ if (machine_readable)
+ printf("X %s%c", ce->name, 0);
+ else {
+ printf("%s: %s\n", ce->name, strerror(errno));
+ if (errno == ENOENT)
+ show_diff_empty(ce);
+ }
continue;
}
changed = cache_match_stat(ce, &st);
if (!changed)
continue;
- printf("%s: ", ce->name);
- for (n = 0; n < 20; n++)
- printf("%02x", ce->sha1[n]);
- printf("\n");
+ if (!machine_readable)
+ printf("%s: %s\n", ce->name, sha1_to_hex(ce->sha1));
+ else {
+ printf("%s %s%c", sha1_to_hex(ce->sha1), ce->name, 0);
+ continue;
+ }
fflush(stdout);
if (silent)
continue;