@matheusbsbs / matheus-bagliano / commits / 946f5f7c24
Fork 0

Diff: --name-status output format.

The new output format shows only the status letter and paths. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 21, 2005 at 00:20 UTC 946f5f7c245a0f9398417be5946795cfebfd1c62
3 files changed +17 -11
Documentation/diff-options.txt
+2 -2
@@ -15,8 +15,8 @@
15 --name-only::
16 Show only names of changed files.
17
18 ---name-only-z::
19 - Same as --name-only, but terminate lines with NUL.
18 +--name-status::
19 + Show only names and status of changed files.
20
21 -B::
22 Break complete rewrite changes into pairs of delete and create.
diff.c
+13 -9
@@ -709,6 +709,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
709 options->rename_limit = strtoul(arg+2, NULL, 10);
710 else if (!strcmp(arg, "--name-only"))
711 options->output_format = DIFF_FORMAT_NAME;
712 + else if (!strcmp(arg, "--name-status"))
713 + options->output_format = DIFF_FORMAT_NAME_STATUS;
714 else if (!strcmp(arg, "-R"))
715 options->reverse_diff = 1;
716 else if (!strncmp(arg, "-S", 2))
@@ -835,7 +837,8 @@ void diff_free_filepair(struct diff_filepair *p)
837
838 static void diff_flush_raw(struct diff_filepair *p,
839 int line_termination,
838 - int inter_name_termination)
840 + int inter_name_termination,
841 + int output_format)
842 {
843 int two_paths;
844 char status[10];
@@ -871,13 +874,12 @@ static void diff_flush_raw(struct diff_filepair *p,
874 two_paths = 0;
875 break;
876 }
874 - printf(":%06o %06o %s ",
875 - p->one->mode, p->two->mode, sha1_to_hex(p->one->sha1));
876 - printf("%s %s%c%s",
877 - sha1_to_hex(p->two->sha1),
878 - status,
879 - inter_name_termination,
880 - p->one->path);
877 + if (output_format != DIFF_FORMAT_NAME_STATUS) {
878 + printf(":%06o %06o %s ",
879 + p->one->mode, p->two->mode, sha1_to_hex(p->one->sha1));
880 + printf("%s ", sha1_to_hex(p->two->sha1));
881 + }
882 + printf("%s%c%s",status, inter_name_termination, p->one->path);
883 if (two_paths)
884 printf("%c%s", inter_name_termination, p->two->path);
885 putchar(line_termination);
@@ -1067,8 +1069,10 @@ void diff_flush(struct diff_options *options)
1069 diff_flush_patch(p);
1070 break;
1071 case DIFF_FORMAT_RAW:
1072 + case DIFF_FORMAT_NAME_STATUS:
1073 diff_flush_raw(p, line_termination,
1071 - inter_name_termination);
1074 + inter_name_termination,
1075 + diff_output_format);
1076 break;
1077 case DIFF_FORMAT_NAME:
1078 diff_flush_name(p, line_termination);
diff.h
+2
@@ -67,6 +67,7 @@ extern void diffcore_std_no_resolve(struct diff_options *);
67 " -p output patch format.\n" \
68 " -u synonym for -p.\n" \
69 " --name-only show only names of changed files.\n" \
70 +" --name-status show names and status of changed files.\n" \
71 " -R swap input file pairs.\n" \
72 " -B detect complete rewrites.\n" \
73 " -M detect renames.\n" \
@@ -85,6 +86,7 @@ extern int diff_queue_is_empty(void);
86 #define DIFF_FORMAT_PATCH 2
87 #define DIFF_FORMAT_NO_OUTPUT 3
88 #define DIFF_FORMAT_NAME 4
89 +#define DIFF_FORMAT_NAME_STATUS 5
90
91 extern void diff_flush(struct diff_options*);
92