diff options
author | Junio C Hamano <junkio@cox.net> | 2005-07-13 12:45:51 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-07-13 12:55:07 -0700 |
commit | 52f28529f4f90cebdca47f8eacbff5cb20004bed (patch) | |
tree | 5582a75c2121fca35a99eb35d9e22f97cd2ed5b3 | |
parent | [PATCH] diff-stages: support "-u" as a synonym for "-p". (diff) | |
download | tgif-52f28529f4f90cebdca47f8eacbff5cb20004bed.tar.xz |
[PATCH] git-diff-*: --name-only and --name-only-z.
Porcelain layers often want to find only names of changed files,
and even with diff-raw output format they end up having to pick
out only the filename. Support --name-only (and --name-only-z
for xargs -0 and cpio -0 users that want to treat filenames with
embedded newlines sanely) flag to help them.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r-- | diff-cache.c | 8 | ||||
-rw-r--r-- | diff-files.c | 4 | ||||
-rw-r--r-- | diff-stages.c | 4 | ||||
-rw-r--r-- | diff-tree.c | 8 | ||||
-rw-r--r-- | diff.c | 13 | ||||
-rw-r--r-- | diff.h | 2 |
6 files changed, 38 insertions, 1 deletions
diff --git a/diff-cache.c b/diff-cache.c index 33b3b31779..e1ac57dde8 100644 --- a/diff-cache.c +++ b/diff-cache.c @@ -223,6 +223,14 @@ int main(int argc, const char **argv) diff_output_format = DIFF_FORMAT_MACHINE; continue; } + if (!strcmp(arg, "--name-only")) { + diff_output_format = DIFF_FORMAT_NAME; + continue; + } + if (!strcmp(arg, "--name-only-z")) { + diff_output_format = DIFF_FORMAT_NAME_Z; + continue; + } if (!strcmp(arg, "-R")) { diff_setup_opt |= DIFF_SETUP_REVERSE; continue; diff --git a/diff-files.c b/diff-files.c index 3221e31979..6d2aec3406 100644 --- a/diff-files.c +++ b/diff-files.c @@ -55,6 +55,10 @@ int main(int argc, const char **argv) ; /* no-op */ else if (!strcmp(argv[1], "-z")) diff_output_format = DIFF_FORMAT_MACHINE; + else if (!strcmp(argv[1], "--name-only")) + diff_output_format = DIFF_FORMAT_NAME; + else if (!strcmp(argv[1], "--name-only-z")) + diff_output_format = DIFF_FORMAT_NAME_Z; else if (!strcmp(argv[1], "-R")) diff_setup_opt |= DIFF_SETUP_REVERSE; else if (!strncmp(argv[1], "-S", 2)) diff --git a/diff-stages.c b/diff-stages.c index 738fe5d987..9d33535fe0 100644 --- a/diff-stages.c +++ b/diff-stages.c @@ -87,6 +87,10 @@ int main(int ac, const char **av) find_copies_harder = 1; else if (!strcmp(arg, "-z")) diff_output_format = DIFF_FORMAT_MACHINE; + else if (!strcmp(arg, "--name-only")) + diff_output_format = DIFF_FORMAT_NAME; + else if (!strcmp(arg, "--name-only-z")) + diff_output_format = DIFF_FORMAT_NAME_Z; else if (!strcmp(arg, "-R")) diff_setup_opt |= DIFF_SETUP_REVERSE; else if (!strncmp(arg, "-S", 2)) diff --git a/diff-tree.c b/diff-tree.c index ea237051ee..f499d2ead5 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -480,6 +480,14 @@ int main(int argc, const char **argv) find_copies_harder = 1; continue; } + if (!strcmp(arg, "--name-only")) { + diff_output_format = DIFF_FORMAT_NAME; + continue; + } + if (!strcmp(arg, "--name-only-z")) { + diff_output_format = DIFF_FORMAT_NAME_Z; + continue; + } if (!strcmp(arg, "-z")) { diff_output_format = DIFF_FORMAT_MACHINE; continue; @@ -818,6 +818,12 @@ static void diff_flush_raw(struct diff_filepair *p, putchar(line_termination); } +static void diff_flush_name(struct diff_filepair *p, + int line_termination) +{ + printf("%s%c", p->two->path, line_termination); +} + int diff_unmodified_pair(struct diff_filepair *p) { /* This function is written stricter than necessary to support @@ -978,7 +984,8 @@ void diff_flush(int diff_output_style) int line_termination = '\n'; int inter_name_termination = '\t'; - if (diff_output_style == DIFF_FORMAT_MACHINE) + if (diff_output_style == DIFF_FORMAT_MACHINE || + diff_output_style == DIFF_FORMAT_NAME_Z) line_termination = inter_name_termination = 0; for (i = 0; i < q->nr; i++) { @@ -997,6 +1004,10 @@ void diff_flush(int diff_output_style) diff_flush_raw(p, line_termination, inter_name_termination); break; + case DIFF_FORMAT_NAME: + case DIFF_FORMAT_NAME_Z: + diff_flush_name(p, line_termination); + break; } } for (i = 0; i < q->nr; i++) @@ -59,6 +59,8 @@ extern int diff_queue_is_empty(void); #define DIFF_FORMAT_MACHINE 1 #define DIFF_FORMAT_PATCH 2 #define DIFF_FORMAT_NO_OUTPUT 3 +#define DIFF_FORMAT_NAME 4 +#define DIFF_FORMAT_NAME_Z 5 extern void diff_flush(int output_style); |