Skip to contentSkip to conversation

Rework diff options

PATCH In review Timo Hirvonen 3 participants 20 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Rework diff options

This patch series cleans up diff output format options.

This makes it possible to use any combination of --raw, -p, --stat and --summary options and they work as you would expect.

These patches passed all test and are for the next branch. Patches 6 and 7 are optional.

 b/builtin-diff-files.c  |   10 --
 b/builtin-diff-index.c  |    3 
 b/builtin-diff-stages.c |    3 
 b/builtin-diff-tree.c   |    3 
 b/builtin-diff.c        |   62 +++----------
 b/builtin-log.c         |   13 +-
 b/combine-diff.c        |   55 +++++------
 b/diff.c                |  221 +++++++++++++++++++++++-------------------------
 b/diff.h                |   27 +++--
 b/log-tree.c            |   10 +-
 b/revision.c            |    4 
 11 files changed, 189 insertions(+), 222 deletions(-)
Signature · 1 line
http://onion.dynserv.net/~timo/
#1 lore raw

PATCH 1/7 Clean up diff.c

---
 diff.c |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)
diff.c +6 -12
index ad77543..f358546 100644
@@ -203,7 +203,7 @@ static void emit_rewrite_diff(const char
 static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
 {
 	if (!DIFF_FILE_VALID(one)) {
-		mf->ptr = ""; /* does not matter */
+		mf->ptr = (char *)""; /* does not matter */
 		mf->size = 0;
 		return 0;
 	}
@@ -395,7 +395,7 @@ static void show_stats(struct diffstat_t
 	}
 
 	for (i = 0; i < data->nr; i++) {
-		char *prefix = "";
+		const char *prefix = "";
 		char *name = data->files[i]->name;
 		int added = data->files[i]->added;
 		int deleted = data->files[i]->deleted;
@@ -918,7 +918,7 @@ int diff_populate_filespec(struct diff_f
 			err_empty:
 				err = -1;
 			empty:
-				s->data = "";
+				s->data = (char *)"";
 				s->size = 0;
 				return err;
 			}
@@ -1409,7 +1409,7 @@ int diff_setup_done(struct diff_options 
 	return 0;
 }
 
-int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
+static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val)
 {
 	char c, *eq;
 	int len;
@@ -1725,16 +1725,12 @@ static void diff_flush_raw(struct diff_f
 		free((void*)path_two);
 }
 
-static void diff_flush_name(struct diff_filepair *p,
-			    int inter_name_termination,
-			    int line_termination)
+static void diff_flush_name(struct diff_filepair *p, int line_termination)
 {
 	char *path = p->two->path;
 
 	if (line_termination)
 		path = quote_one(p->two->path);
-	else
-		path = p->two->path;
 	printf("%s%c", path, line_termination);
 	if (p->two->path != path)
 		free(path);
@@ -1955,9 +1951,7 @@ static void flush_one_pair(struct diff_f
 				       options, diff_output_format);
 			break;
 		case DIFF_FORMAT_NAME:
-			diff_flush_name(p,
-					inter_name_termination,
-					line_termination);
+			diff_flush_name(p, line_termination);
 			break;
 		case DIFF_FORMAT_NO_OUTPUT:
 			break;
Signature · 1 line
1.4.1.rc1.g8637
#2 lore raw

PATCH 2/7 Merge with_raw, with_stat and summary variables to output_format

In reply to Timo Hirvonen

DIFF_FORMAT_* are now bit-flags instead of enumerated values.

---
 builtin-diff.c |    2 -
 builtin-log.c  |    4 -
 combine-diff.c |   55 +++++++----------
 diff.c         |  183 +++++++++++++++++++++++++++-----------------------------
 diff.h         |   27 +++++---
 log-tree.c     |    9 ++-
 6 files changed, 136 insertions(+), 144 deletions(-)
builtin-diff.c +1 -1
index 99a2f76..3b44296 100644
@@ -56,7 +56,7 @@ static int builtin_diff_files(struct rev
 	    3 < revs->max_count)
 		usage(builtin_diff_usage);
 	if (revs->max_count < 0 &&
-	    (revs->diffopt.output_format == DIFF_FORMAT_PATCH))
+	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
 		revs->combine_merges = revs->dense_combined_merges = 1;
 	/*
 	 * Backward compatibility wart - "diff-files -s" used to
builtin-log.c +1 -3
index 5a8a50b..5c656bc 100644
@@ -176,11 +176,9 @@ int cmd_format_patch(int argc, const cha
 	rev.commit_format = CMIT_FMT_EMAIL;
 	rev.verbose_header = 1;
 	rev.diff = 1;
-	rev.diffopt.with_raw = 0;
-	rev.diffopt.with_stat = 1;
 	rev.combine_merges = 0;
 	rev.ignore_merges = 1;
-	rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+	rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
 
 	git_config(git_format_config);
 	rev.extra_headers = extra_headers;
combine-diff.c +24 -31

105 lines not on this page · raw message

diff.c +88 -95

277 lines not on this page · raw message

diff.h +15 -12
index b61fdc8..2b6dc0c 100644
@@ -20,19 +20,31 @@ typedef void (*add_remove_fn_t)(struct d
 		    const unsigned char *sha1,
 		    const char *base, const char *path);
 
+#define DIFF_FORMAT_RAW		0x0001
+#define DIFF_FORMAT_DIFFSTAT	0x0002
+#define DIFF_FORMAT_SUMMARY	0x0004
+#define DIFF_FORMAT_PATCH	0x0008
+
+/* These override all above */
+#define DIFF_FORMAT_NAME	0x0010
+#define DIFF_FORMAT_NAME_STATUS	0x0020
+#define DIFF_FORMAT_CHECKDIFF	0x0040
+
+/* Same as output_format = 0 but we know that -s flag was given
+ * and we should not give default value to output_format.
+ */
+#define DIFF_FORMAT_NO_OUTPUT	0x0080
+
 struct diff_options {
 	const char *filter;
 	const char *orderfile;
 	const char *pickaxe;
 	unsigned recursive:1,
-		 with_raw:1,
-		 with_stat:1,
 		 tree_in_recursive:1,
 		 binary:1,
 		 full_index:1,
 		 silent_on_remove:1,
 		 find_copies_harder:1,
-		 summary:1,
 		 color_diff:1;
 	int context;
 	int break_opt;
@@ -151,15 +163,6 @@ #define COMMON_DIFF_OPTIONS_HELP \
 "                show all files diff when -S is used and hit is found.\n"
 
 extern int diff_queue_is_empty(void);
-
-#define DIFF_FORMAT_RAW		1
-#define DIFF_FORMAT_PATCH	2
-#define DIFF_FORMAT_NO_OUTPUT	3
-#define DIFF_FORMAT_NAME	4
-#define DIFF_FORMAT_NAME_STATUS	5
-#define DIFF_FORMAT_DIFFSTAT	6
-#define DIFF_FORMAT_CHECKDIFF	7
-
 extern void diff_flush(struct diff_options*);
 
 /* diff-raw status letters */
log-tree.c +7 -2
index ebb49f2..7d4c51f 100644
@@ -163,8 +163,13 @@ int log_tree_diff_flush(struct rev_info 
 		return 0;
 	}
 
-	if (opt->loginfo && !opt->no_commit_id)
-		show_log(opt, opt->loginfo, opt->diffopt.with_stat ? "---\n" : "\n");
+	if (opt->loginfo && !opt->no_commit_id) {
+		if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) {
+			show_log(opt, opt->loginfo,  "---\n");
+		} else {
+			show_log(opt, opt->loginfo,  "\n");
+		}
+	}
 	diff_flush(&opt->diffopt);
 	return 1;
 }
Signature · 1 line
1.4.1.rc1.g8637
#3 lore raw

PATCH 1/1 Add msg_sep to diff_options

Add msg_sep variable to struct diff_options. msg_sep is printed after commit message. Default is "\n", format-patch sets it to "---\n".

This also removes the second argument from show_log() because all callers derived it from the first argument:

    show_log(rev, rev->loginfo, ...

---

I'm not 100% sure if format-patch is the only one wanting "---\n". But I think "\n" should be used for every command that doesn't create patches.

 builtin-log.c  |    1 +
 combine-diff.c |    7 ++++---
 diff.c         |    1 +
 diff.h         |    1 +
 log-tree.c     |   15 ++++++---------
 log-tree.h     |    2 +-
 6 files changed, 14 insertions(+), 13 deletions(-)
builtin-log.c +1 -0
index f173070..5b3fadc 100644
@@ -175,6 +175,7 @@ int cmd_format_patch(int argc, const cha
 	rev.diff = 1;
 	rev.combine_merges = 0;
 	rev.ignore_merges = 1;
+	rev.diffopt.msg_sep = "---\n";
 
 	git_config(git_format_config);
 	rev.extra_headers = extra_headers;
combine-diff.c +4 -3
index 3daa8cb..39fb10c 100644
@@ -701,7 +701,7 @@ static int show_patch_diff(struct combin
 		const char *abb;
 
 		if (rev->loginfo)
-			show_log(rev, rev->loginfo, "\n");
+			show_log(rev, opt->msg_sep);
 		dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path);
 		printf("index ");
 		for (i = 0; i < num_parent; i++) {
@@ -769,7 +769,7 @@ static void show_raw_diff(struct combine
 		inter_name_termination = 0;
 
 	if (rev->loginfo)
-		show_log(rev, rev->loginfo, "\n");
+		show_log(rev, opt->msg_sep);
 
 	if (opt->output_format & DIFF_FORMAT_RAW) {
 		offset = strlen(COLONS) - num_parent;
@@ -855,7 +855,8 @@ void diff_tree_combined(const unsigned c
 		paths = intersect_paths(paths, i, num_parent);
 
 		if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
-			show_log(rev, rev->loginfo, "---\n");
+			show_log(rev, opt->msg_sep);
+
 		diff_flush(&diffopts);
 		if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
 			putchar('\n');
diff.c +1 -0
index 4b1b4eb..cc2af30 100644
@@ -1359,6 +1359,7 @@ void diff_setup(struct diff_options *opt
 	options->break_opt = -1;
 	options->rename_limit = -1;
 	options->context = 3;
+	options->msg_sep = "\n";
 
 	options->change = diff_change;
 	options->add_remove = diff_addremove;
diff.h +1 -0
index 2b6dc0c..729cd02 100644
@@ -57,6 +57,7 @@ struct diff_options {
 	int rename_limit;
 	int setup;
 	int abbrev;
+	const char *msg_sep;
 	const char *stat_sep;
 	long xdl_opts;
 
log-tree.c +6 -9
index 7d4c51f..ab6b682 100644
@@ -43,9 +43,10 @@ static int append_signoff(char *buf, int
 	return at;
 }
 
-void show_log(struct rev_info *opt, struct log_info *log, const char *sep)
+void show_log(struct rev_info *opt, const char *sep)
 {
 	static char this_header[16384];
+	struct log_info *log = opt->loginfo;
 	struct commit *commit = log->commit, *parent = log->parent;
 	int abbrev = opt->diffopt.abbrev;
 	int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
@@ -163,13 +164,9 @@ int log_tree_diff_flush(struct rev_info 
 		return 0;
 	}
 
-	if (opt->loginfo && !opt->no_commit_id) {
-		if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) {
-			show_log(opt, opt->loginfo,  "---\n");
-		} else {
-			show_log(opt, opt->loginfo,  "\n");
-		}
-	}
+	if (opt->loginfo && !opt->no_commit_id)
+		show_log(opt, opt->diffopt.msg_sep);
+
 	diff_flush(&opt->diffopt);
 	return 1;
 }
@@ -266,7 +263,7 @@ int log_tree_commit(struct rev_info *opt
 	shown = log_tree_diff(opt, commit, &log);
 	if (!shown && opt->loginfo && opt->always_show_header) {
 		log.parent = NULL;
-		show_log(opt, opt->loginfo, "");
+		show_log(opt, "");
 		shown = 1;
 	}
 	opt->loginfo = NULL;
log-tree.h +1 -1
index a26e484..e82b56a 100644
@@ -11,6 +11,6 @@ void init_log_tree_opt(struct rev_info *
 int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
 int log_tree_opt_parse(struct rev_info *, const char **, int);
-void show_log(struct rev_info *opt, struct log_info *log, const char *sep);
+void show_log(struct rev_info *opt, const char *sep);
 
 #endif
Signature · 1 line
1.4.1.rc1.g35ee-dirty
#4 lore raw

Re: [PATCH] Add msg_sep to diff_options

Quoted 7 lines · Timo Hirvonen

Add msg_sep variable to struct diff_options. msg_sep is printed after commit message. Default is "\n", format-patch sets it to "---\n".

This also removes the second argument from show_log() because all callers derived it from the first argument:

    show_log(rev, rev->loginfo, ...

Good catch. Thanks.

Quoted 2 lines

---

I often wonder if the separator should be "\n---\n" instead when I see something like the above, but do not change it yet please.

Quoted 1 line

I'm not 100% sure if format-patch is the only one wanting "---\n".

git log --patch-with-stat should also show "---\n".

Quoted 2 lines

But I think "\n" should be used for every command that doesn't create patches.

This sounds good.

We probably would want to have an output format testsuite to catch regression.

#5 lore raw

PATCH 1/1 whatchanged: Default to DIFF_FORMAT_RAW

In reply to Timo Hirvonen
---
 builtin-log.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
builtin-log.c +9 -0
index 5b3fadc..8a39770 100644
@@ -28,6 +28,15 @@ static int cmd_log_wc(int argc, const ch
 			rev->always_show_header = 0;
 	}
 
+	if (!rev->diffopt.output_format && !rev->simplify_history) {
+		/* Ugly hack!
+		 *
+		 * rev->simplify_history == 0 -> whatchanged
+		 * Can't do this before setup_revisions()
+		 */
+		rev->diffopt.output_format = DIFF_FORMAT_RAW;
+	}
+
 	if (argc > 1)
 		die("unrecognized argument: %s", argv[1]);
 
Signature · 1 line
1.4.1.rc1.g6e272-dirty
#6 lore raw

Re: [PATCH] whatchanged: Default to DIFF_FORMAT_RAW

Quoted 10 lines · Timo Hirvonen
---
 builtin-log.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
builtin-log.c +0 -0
index 5b3fadc..8a39770 100644

builtin-log.c static int cmd_log_wc(int argc, const ch · line 36

Quoted 9 lines
builtin-log.c +6 -0
@@ -28,6 +28,15 @@ static int cmd_log_wc(int argc, const ch
 			rev->always_show_header = 0;
 	}
 
+	if (!rev->diffopt.output_format && !rev->simplify_history) {
+		/* Ugly hack!
+		 *
+		 * rev->simplify_history == 0 -> whatchanged
+		 * Can't do this before setup_revisions()
+		 */

Indeed it is ugly. Might it be a cleaner option to signal _wc function what command its caller is, by adding an extra parameter (or check argv -- ugh)?

#7 lore raw

PATCH 1/1 whatchanged: Default to DIFF_FORMAT_RAW

Split cmd_log_wc() to cmd_log_init() and cmd_log_walk() and set default diff output format for whatchanged to DIFF_FORMAT_RAW.

---

Forget the previous patch, this is cleaner.

 builtin-log.c |   27 ++++++++++++++++-----------
 1 files changed, 16 insertions(+), 11 deletions(-)
builtin-log.c +16 -11
index 5b3fadc..28cd8bf 100644
@@ -14,22 +14,22 @@ #include "builtin.h"
 /* this is in builtin-diff.c */
 void add_head(struct rev_info *revs);
 
-static int cmd_log_wc(int argc, const char **argv, char **envp,
+static void cmd_log_init(int argc, const char **argv, char **envp,
 		      struct rev_info *rev)
 {
-	struct commit *commit;
-
 	rev->abbrev = DEFAULT_ABBREV;
 	rev->commit_format = CMIT_FMT_DEFAULT;
 	rev->verbose_header = 1;
 	argc = setup_revisions(argc, argv, rev, "HEAD");
-	if (rev->always_show_header) {
-		if (rev->diffopt.pickaxe || rev->diffopt.filter)
-			rev->always_show_header = 0;
-	}
-
+	if (rev->diffopt.pickaxe || rev->diffopt.filter)
+		rev->always_show_header = 0;
 	if (argc > 1)
 		die("unrecognized argument: %s", argv[1]);
+}
+
+static int cmd_log_walk(struct rev_info *rev)
+{
+	struct commit *commit;
 
 	prepare_revision_walk(rev);
 	setup_pager();
@@ -51,7 +51,10 @@ int cmd_whatchanged(int argc, const char
 	rev.diff = 1;
 	rev.diffopt.recursive = 1;
 	rev.simplify_history = 0;
-	return cmd_log_wc(argc, argv, envp, &rev);
+	cmd_log_init(argc, argv, envp, &rev);
+	if (!rev.diffopt.output_format)
+		rev.diffopt.output_format = DIFF_FORMAT_RAW;
+	return cmd_log_walk(&rev);
 }
 
 int cmd_show(int argc, const char **argv, char **envp)
@@ -66,7 +69,8 @@ int cmd_show(int argc, const char **argv
 	rev.always_show_header = 1;
 	rev.ignore_merges = 0;
 	rev.no_walk = 1;
-	return cmd_log_wc(argc, argv, envp, &rev);
+	cmd_log_init(argc, argv, envp, &rev);
+	return cmd_log_walk(&rev);
 }
 
 int cmd_log(int argc, const char **argv, char **envp)
@@ -76,7 +80,8 @@ int cmd_log(int argc, const char **argv,
 	init_revisions(&rev);
 	rev.always_show_header = 1;
 	rev.diffopt.recursive = 1;
-	return cmd_log_wc(argc, argv, envp, &rev);
+	cmd_log_init(argc, argv, envp, &rev);
+	return cmd_log_walk(&rev);
 }
 
 static int istitlechar(char c)
Signature · 1 line
1.4.1.rc1.g39849-dirty
#8 lore raw

PATCH 1/1 Don't xcalloc() struct diffstat_t

In reply to Timo Hirvonen
---
 diff.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
diff.c +5 -6
index cc2af30..8880150 100644
@@ -2062,17 +2062,16 @@ void diff_flush(struct diff_options *opt
 	}
 
 	if (output_format & DIFF_FORMAT_DIFFSTAT) {
-		struct diffstat_t *diffstat;
+		struct diffstat_t diffstat;
 
-		diffstat = xcalloc(sizeof (struct diffstat_t), 1);
-		diffstat->xm.consume = diffstat_consume;
+		memset(&diffstat, 0, sizeof(struct diffstat_t));
+		diffstat.xm.consume = diffstat_consume;
 		for (i = 0; i < q->nr; i++) {
 			struct diff_filepair *p = q->queue[i];
 			if (check_pair_status(p))
-				diff_flush_stat(p, options, diffstat);
+				diff_flush_stat(p, options, &diffstat);
 		}
-		show_stats(diffstat);
-		free(diffstat);
+		show_stats(&diffstat);
 	}
 
 	if (output_format & DIFF_FORMAT_SUMMARY) {
Signature · 1 line
1.4.1.rc1.g5472-dirty
#9 lore raw

Re: [PATCH 2/7] Merge with_raw, with_stat and summary variables to output_format

In reply to Timo Hirvonen

Hi,

thank you very much for doing the extra step and using the original constant names. I appreciate that.

Quoted 5 lines · Timo Hirvonen
combine-diff.c +0 -1
@@ -818,17 +817,12 @@ void show_combined_diff(struct combine_d
 	struct diff_options *opt = &rev->diffopt;
 	if (!p->len)
 		return;
-	switch (opt->output_format) {

combine-diff.c void show_combined_diff(struct combine_d · line 824

Quoted 10 lines
combine-diff.c +4 -5
-	case DIFF_FORMAT_RAW:
-	case DIFF_FORMAT_NAME_STATUS:
-	case DIFF_FORMAT_NAME:
+	if (opt->output_format & (DIFF_FORMAT_RAW |
+				  DIFF_FORMAT_NAME |
+				  DIFF_FORMAT_NAME_STATUS)) {
 		show_raw_diff(p, num_parent, rev);
-		return;
-	case DIFF_FORMAT_PATCH:
+	} else if (opt->output_format & DIFF_FORMAT_PATCH) {

Not that it matters, but this "else" could go. (Otherwise, "--raw -p" would be the same as "--raw", right?)

Quoted 10 lines
combine-diff.c +0 -3
 		show_patch_diff(p, num_parent, dense, rev);
-		return;
-	default:
-		return;
 	}
 }
 
@@ -856,19 +846,18 @@ void diff_tree_combined(const unsigned c
[...]
 

combine-diff.c void diff_tree_combined(const unsigned c · line 862

Quoted 10 lines
combine-diff.c +3 -4
-		if (do_diffstat && rev->loginfo)
-			show_log(rev, rev->loginfo,
-				 opt->with_stat ? "---\n" : "\n");
+		if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
+			show_log(rev, rev->loginfo, "---\n");
 		diff_flush(&diffopts);
-		if (opt->with_stat)
+		if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
 			putchar('\n');
 	}

Just a remark: this hunk actually changes behaviour. "with_stat" meant that the stat was prepended before something like a patch, and therefore a separator was needed. If you pass only "--stat", the separator will be printed anyway now.

Quoted 5 lines
diff.c +0 -0
index f358546..bfed79c 100644

diff.c int diff_setup_done(struct diff_options · line 1381

Quoted 10 lines
diff.c +7 -0
@@ -1372,23 +1372,27 @@ int diff_setup_done(struct diff_options 
 	    (0 <= options->rename_limit && !options->detect_rename))
 		return -1;
 
+	if (options->output_format & DIFF_FORMAT_NO_OUTPUT)
+		options->output_format = 0;
+
+	if (options->output_format & (DIFF_FORMAT_NAME |
+				      DIFF_FORMAT_NAME_STATUS |
+				      DIFF_FORMAT_CHECKDIFF |
+				      DIFF_FORMAT_NO_OUTPUT))

The DIFF_FORMAT_NO_OUTPUT here makes no sense (if it was set, you unset it above).

Quoted 9 lines
diff.c +1 -4
@@ -1671,15 +1674,17 @@ const char *diff_unique_abbrev(const uns
[...]
 
 static void diff_flush_raw(struct diff_filepair *p,
-			   int line_termination,
-			   int inter_name_termination,
-			   struct diff_options *options,
-			   int output_format)
+			   struct diff_options *options)

diff.c const char *diff_unique_abbrev(const uns · line 1687

Quoted 10 lines
diff.c +5 -0
 {
 	int two_paths;
 	char status[10];
 	int abbrev = options->abbrev;
 	const char *path_one, *path_two;
+	int inter_name_termination = '\t';
+	int line_termination = options->line_termination;
+
+	if (!line_termination)
+		inter_name_termination = 0;

<nit type=minor>
This should be part of patch 1/7.
</nit>

diff.c static void diff_summary(struct diff_fil · line 2045

Quoted 13 lines
diff.c +6 -2
@@ -2041,55 +2028,61 @@ static void diff_summary(struct diff_fil
[...]
 
-	if (options->with_raw) {
+	if (output_format & (DIFF_FORMAT_RAW |
+			     DIFF_FORMAT_NAME |
+			     DIFF_FORMAT_NAME_STATUS |
+			     DIFF_FORMAT_CHECKDIFF)) {
 		for (i = 0; i < q->nr; i++) {
 			struct diff_filepair *p = q->queue[i];
-			flush_one_pair(p, DIFF_FORMAT_RAW, options, NULL);
+			if (check_pair_status(p))
+				flush_one_pair(p, options);

This is a very nice cleanup.

Quoted 4 lines
diff.c +2 -1
 	}
-	if (options->with_stat) {
+
+	if (output_format & DIFF_FORMAT_DIFFSTAT) {

diff.c static void diff_summary(struct diff_fil · line 2057

Quoted 10 lines
diff.c +6 -2
+		struct diffstat_t *diffstat;
+
+		diffstat = xcalloc(sizeof (struct diffstat_t), 1);
+		diffstat->xm.consume = diffstat_consume;
 		for (i = 0; i < q->nr; i++) {
 			struct diff_filepair *p = q->queue[i];
-			flush_one_pair(p, DIFF_FORMAT_DIFFSTAT, options,
-				       diffstat);
+			if (check_pair_status(p))
+				diff_flush_stat(p, options, diffstat);

Again, very nice.

diff.c static void diff_summary(struct diff_fil · line 2060

Quoted 3 lines
diff.c +0 -0
 		}
 		show_stats(diffstat);
 		free(diffstat);

Why not go the full nine yards, and make diffstat not a pointer, but the struct itself? You would avoid calloc()ing and free()ing. (Of course, instead of calloc()ing you have to memset() it to 0.)

diff.c static void diff_summary(struct diff_fil · line 2074

Quoted 7 lines
diff.c +7 -0
+	if (output_format & DIFF_FORMAT_PATCH) {
+		if (output_format & (DIFF_FORMAT_DIFFSTAT |
+				     DIFF_FORMAT_SUMMARY)) {
+			if (options->stat_sep)
+				fputs(options->stat_sep, stdout);
+			else
+				putchar(options->line_termination);

Are we sure we do not want something like

	if (output_format / DIFF_FORMAT_DIFFSTAT > 1)
		/* output separator */

after each format (this example being after the diffstat), the condition
being: if there is still an output format to come, add the separator?

All in all, I like this patch.

Ciao,
Dscho

#10 lore raw

Re: [PATCH 2/7] Merge with_raw, with_stat and summary variables to output_format

Quoted 17 lines · Johannes Schindelin

Hi,

thank you very much for doing the extra step and using the original constant names. I appreciate that.

Quoted 10 lines · Timo Hirvonen
combine-diff.c +2 -4
@@ -818,17 +817,12 @@ void show_combined_diff(struct combine_d
 	struct diff_options *opt = &rev->diffopt;
 	if (!p->len)
 		return;
-	switch (opt->output_format) {
-	case DIFF_FORMAT_RAW:
-	case DIFF_FORMAT_NAME_STATUS:
-	case DIFF_FORMAT_NAME:
+	if (opt->output_format & (DIFF_FORMAT_RAW |
+				  DIFF_FORMAT_NAME |
Quoted 8 lines

combine-diff.c void show_combined_diff(struct combine_d · line 824

Quoted 5 lines
combine-diff.c +2 -2
+				  DIFF_FORMAT_NAME_STATUS)) {
 		show_raw_diff(p, num_parent, rev);
-		return;
-	case DIFF_FORMAT_PATCH:
+	} else if (opt->output_format & DIFF_FORMAT_PATCH) {

Not that it matters, but this "else" could go. (Otherwise, "--raw -p" would be the same as "--raw", right?)

Just tested, ./git log -p --raw displays both raw and patch. I think it works because I changed diff_tree_combined() to use show_raw_diff() and show_patch_diff() directly.

It feels 'wrong' to check flags and then call a function which checks the flags again. This combined diff stuff is confusing.

Quoted 18 lines

combine-diff.c void diff_tree_combined(const unsigned c · line 862

Quoted 13 lines
combine-diff.c +3 -4
@@ -856,19 +846,18 @@ void diff_tree_combined(const unsigned c
[...]
 
-		if (do_diffstat && rev->loginfo)
-			show_log(rev, rev->loginfo,
-				 opt->with_stat ? "---\n" : "\n");
+		if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
+			show_log(rev, rev->loginfo, "---\n");
 		diff_flush(&diffopts);
-		if (opt->with_stat)
+		if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
 			putchar('\n');
 	}

Just a remark: this hunk actually changes behaviour. "with_stat" meant that the stat was prepended before something like a patch, and therefore a separator was needed. If you pass only "--stat", the separator will be printed anyway now.

You are right, it now prints --- when it should print empty line.

Quoted 9 lines

diff.c const char *diff_unique_abbrev(const uns · line 1687

Quoted 5 lines
diff.c +5 -0
+	int inter_name_termination = '\t';
+	int line_termination = options->line_termination;
+
+	if (!line_termination)
+		inter_name_termination = 0;

<nit type=minor>
This should be part of patch 1/7.
</nit>

That clean up was possible only after I made other changes to the code, I think. At least it wasn't obvious when I wrote 1/7.

Quoted 6 lines

diff.c static void diff_summary(struct diff_fil · line 2060

Quoted 2 lines
diff.c +0 -0
 		show_stats(diffstat);
 		free(diffstat);

Why not go the full nine yards, and make diffstat not a pointer, but the struct itself? You would avoid calloc()ing and free()ing. (Of course, instead of calloc()ing you have to memset() it to 0.)

I was blind :)

Quoted 10 lines

diff.c static void diff_summary(struct diff_fil · line 2074

Quoted 7 lines
diff.c +7 -0
+	if (output_format & DIFF_FORMAT_PATCH) {
+		if (output_format & (DIFF_FORMAT_DIFFSTAT |
+				     DIFF_FORMAT_SUMMARY)) {
+			if (options->stat_sep)
+				fputs(options->stat_sep, stdout);
+			else
+				putchar(options->line_termination);

Are we sure we do not want something like

Quoted 5 lines
	if (output_format / DIFF_FORMAT_DIFFSTAT > 1)
		/* output separator */

after each format (this example being after the diffstat), the condition
being: if there is still an output format to come, add the separator?

I'm not sure what you mean.

It outputs separator between (diffstat and/or summary) and patch. There's no separator between diffstat and summary or raw and diffstat. Should there be one?

Thanks for your comments. Should I patch the patch or send a fixed one? I'm currently too tired to write any code.

Signature · 1 line
http://onion.dynserv.net/~timo/
#11 lore raw

Re: [PATCH 2/7] Merge with_raw, with_stat and summary variables to output_format

Hi,

Quoted 23 lines · Timo Hirvonen
Quoted 12 lines · Johannes Schindelin
Quoted 10 lines · Timo Hirvonen
combine-diff.c +2 -4
@@ -818,17 +817,12 @@ void show_combined_diff(struct combine_d
 	struct diff_options *opt = &rev->diffopt;
 	if (!p->len)
 		return;
-	switch (opt->output_format) {
-	case DIFF_FORMAT_RAW:
-	case DIFF_FORMAT_NAME_STATUS:
-	case DIFF_FORMAT_NAME:
+	if (opt->output_format & (DIFF_FORMAT_RAW |
+				  DIFF_FORMAT_NAME |
Quoted 8 lines

combine-diff.c void show_combined_diff(struct combine_d · line 824

Quoted 5 lines
combine-diff.c +2 -2
+				  DIFF_FORMAT_NAME_STATUS)) {
 		show_raw_diff(p, num_parent, rev);
-		return;
-	case DIFF_FORMAT_PATCH:
+	} else if (opt->output_format & DIFF_FORMAT_PATCH) {

Not that it matters, but this "else" could go. (Otherwise, "--raw -p" would be the same as "--raw", right?)

Quoted 6 lines

Just tested, ./git log -p --raw displays both raw and patch. I think it works because I changed diff_tree_combined() to use show_raw_diff() and show_patch_diff() directly.

It feels 'wrong' to check flags and then call a function which checks the flags again. This combined diff stuff is confusing.

Sorry for not checking the result, but just the patch. I also find this behaviour confusing. Junio?

Quoted 10 lines
Quoted 9 lines

diff.c const char *diff_unique_abbrev(const uns · line 1687

Quoted 5 lines
diff.c +5 -0
+	int inter_name_termination = '\t';
+	int line_termination = options->line_termination;
+
+	if (!line_termination)
+		inter_name_termination = 0;

<nit type=minor>
This should be part of patch 1/7.
</nit>

Quoted 2 lines

That clean up was possible only after I made other changes to the code, I think. At least it wasn't obvious when I wrote 1/7.

It is just a minor nit, I do not think it is necessary to change the patch.

Quoted 8 lines
Quoted 6 lines

diff.c static void diff_summary(struct diff_fil · line 2060

Quoted 2 lines
diff.c +0 -0
 		show_stats(diffstat);
 		free(diffstat);

Why not go the full nine yards, and make diffstat not a pointer, but the struct itself? You would avoid calloc()ing and free()ing. (Of course, instead of calloc()ing you have to memset() it to 0.)

I was blind :)

;-) In my experience, after staring at the code too long, you turn blind. This is why I like a second pair of eyeballs so much.

Quoted 13 lines
Quoted 13 lines

diff.c static void diff_summary(struct diff_fil · line 2074

Quoted 7 lines
diff.c +7 -0
+	if (output_format & DIFF_FORMAT_PATCH) {
+		if (output_format & (DIFF_FORMAT_DIFFSTAT |
+				     DIFF_FORMAT_SUMMARY)) {
+			if (options->stat_sep)
+				fputs(options->stat_sep, stdout);
+			else
+				putchar(options->line_termination);

Are we sure we do not want something like

	if (output_format / DIFF_FORMAT_DIFFSTAT > 1)
		/* output separator */
Quoted 8 lines
Quoted 2 lines

after each format (this example being after the diffstat), the condition
being: if there is still an output format to come, add the separator?

I'm not sure what you mean.

It outputs separator between (diffstat and/or summary) and patch. There's no separator between diffstat and summary or raw and diffstat. Should there be one?

IMHO there should be one.

Quoted 1 line

Thanks for your comments. Should I patch the patch or send a fixed one?

I cannot speak for Junio, but I think an additional patch to clean things up would be the way to go.

Ciao,
Dscho

#12 lore raw

PATCH 3/7 Make --raw option available for all diff commands

In reply to Timo Hirvonen
---
 builtin-diff.c |   48 ++++++++++++------------------------------------
 diff.c         |    2 ++
 2 files changed, 14 insertions(+), 36 deletions(-)
builtin-diff.c +12 -36
index 3b44296..91235a1 100644
@@ -39,8 +39,6 @@ static int builtin_diff_files(struct rev
 			revs->max_count = 3;
 		else if (!strcmp(arg, "-q"))
 			silent = 1;
-		else if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
 		else
 			usage(builtin_diff_usage);
 		argv++; argc--;
@@ -107,14 +105,9 @@ static int builtin_diff_b_f(struct rev_i
 	/* Blob vs file in the working tree*/
 	struct stat st;
 
-	while (1 < argc) {
-		const char *arg = argv[1];
-		if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
-		else
-			usage(builtin_diff_usage);
-		argv++; argc--;
-	}
+	if (argc > 1)
+		usage(builtin_diff_usage);
+
 	if (lstat(path, &st))
 		die("'%s': %s", path, strerror(errno));
 	if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)))
@@ -137,14 +130,9 @@ static int builtin_diff_blobs(struct rev
 	 */
 	unsigned mode = canon_mode(S_IFREG | 0644);
 
-	while (1 < argc) {
-		const char *arg = argv[1];
-		if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
-		else
-			usage(builtin_diff_usage);
-		argv++; argc--;
-	}
+	if (argc > 1)
+		usage(builtin_diff_usage);
+
 	stuff_change(&revs->diffopt,
 		     mode, mode,
 		     blob[1].sha1, blob[0].sha1,
@@ -162,8 +150,6 @@ static int builtin_diff_index(struct rev
 		const char *arg = argv[1];
 		if (!strcmp(arg, "--cached"))
 			cached = 1;
-		else if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
 		else
 			usage(builtin_diff_usage);
 		argv++; argc--;
@@ -185,14 +171,9 @@ static int builtin_diff_tree(struct rev_
 {
 	const unsigned char *(sha1[2]);
 	int swap = 0;
-	while (1 < argc) {
-		const char *arg = argv[1];
-		if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
-		else
-			usage(builtin_diff_usage);
-		argv++; argc--;
-	}
+
+	if (argc > 1)
+		usage(builtin_diff_usage);
 
 	/* We saw two trees, ent[0] and ent[1].
 	 * if ent[1] is unintesting, they are swapped
@@ -214,14 +195,9 @@ static int builtin_diff_combined(struct 
 	const unsigned char (*parent)[20];
 	int i;
 
-	while (1 < argc) {
-		const char *arg = argv[1];
-		if (!strcmp(arg, "--raw"))
-			revs->diffopt.output_format = DIFF_FORMAT_RAW;
-		else
-			usage(builtin_diff_usage);
-		argv++; argc--;
-	}
+	if (argc > 1)
+		usage(builtin_diff_usage);
+
 	if (!revs->dense_combined_merges && !revs->combine_merges)
 		revs->dense_combined_merges = revs->combine_merges = 1;
 	parent = xmalloc(ents * sizeof(*parent));
diff.c +2 -0
index bfed79c..6e5ae77 100644
@@ -1467,6 +1467,8 @@ int diff_opt_parse(struct diff_options *
 		options->output_format |= DIFF_FORMAT_PATCH;
 	else if (opt_arg(arg, 'U', "unified", &options->context))
 		options->output_format |= DIFF_FORMAT_PATCH;
+	else if (!strcmp(arg, "--raw"))
+		options->output_format |= DIFF_FORMAT_RAW;
 	else if (!strcmp(arg, "--patch-with-raw")) {
 		options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
 	}
Signature · 1 line
1.4.1.rc1.g8637
#13 lore raw

PATCH 4/7 Set default diff output format after parsing command line

In reply to Timo Hirvonen

Initialize output_format to 0 instead of DIFF_FORMAT_RAW so that we can see later if any command line options changed it. Default value is set only if output format was not specified.

---
 builtin-diff-files.c  |    3 +++
 builtin-diff-index.c  |    3 +++
 builtin-diff-stages.c |    3 +++
 builtin-diff-tree.c   |    3 +++
 builtin-diff.c        |    4 +++-
 builtin-log.c         |    4 +++-
 diff.c                |    1 -
 7 files changed, 18 insertions(+), 3 deletions(-)
builtin-diff-files.c +3 -0
index 5afc1d7..a655eea 100644
@@ -36,6 +36,9 @@ int cmd_diff_files(int argc, const char 
 			usage(diff_files_usage);
 		argv++; argc--;
 	}
+	if (!rev.diffopt.output_format)
+		rev.diffopt.output_format = DIFF_FORMAT_RAW;
+
 	/*
 	 * Make sure there are NO revision (i.e. pending object) parameter,
 	 * rev.max_count is reasonable (0 <= n <= 3),
builtin-diff-index.c +3 -0
index c42ef9a..b37c9e8 100644
@@ -28,6 +28,9 @@ int cmd_diff_index(int argc, const char 
 		else
 			usage(diff_cache_usage);
 	}
+	if (!rev.diffopt.output_format)
+		rev.diffopt.output_format = DIFF_FORMAT_RAW;
+
 	/*
 	 * Make sure there is one revision (i.e. pending object),
 	 * and there is no revision filtering parameters.
builtin-diff-stages.c +3 -0
index 7c157ca..30931fe 100644
@@ -85,6 +85,9 @@ int cmd_diff_stages(int ac, const char *
 		ac--; av++;
 	}
 
+	if (!diff_options.output_format)
+		diff_options.output_format = DIFF_FORMAT_RAW;
+
 	if (ac < 3 ||
 	    sscanf(av[1], "%d", &stage1) != 1 ||
 	    ! (0 <= stage1 && stage1 <= 3) ||
builtin-diff-tree.c +3 -0
index 3409a39..ae1cde9 100644
@@ -84,6 +84,9 @@ int cmd_diff_tree(int argc, const char *
 		usage(diff_tree_usage);
 	}
 
+	if (!opt->diffopt.output_format)
+		opt->diffopt.output_format = DIFF_FORMAT_RAW;
+
 	/*
 	 * NOTE! We expect "a ^b" to be equal to "a..b", so we
 	 * reverse the order of the objects if the second one
builtin-diff.c +3 -1
index 91235a1..47e0a37 100644
@@ -252,9 +252,11 @@ int cmd_diff(int argc, const char **argv
 
 	git_config(git_diff_config);
 	init_revisions(&rev);
-	rev.diffopt.output_format = DIFF_FORMAT_PATCH;
 
 	argc = setup_revisions(argc, argv, &rev, NULL);
+	if (!rev.diffopt.output_format)
+		rev.diffopt.output_format = DIFF_FORMAT_PATCH;
+
 	/* Do we have --cached and not have a pending object, then
 	 * default to HEAD by hand.  Eek.
 	 */
builtin-log.c +3 -1
index 5c656bc..65f9527 100644
@@ -178,7 +178,6 @@ int cmd_format_patch(int argc, const cha
 	rev.diff = 1;
 	rev.combine_merges = 0;
 	rev.ignore_merges = 1;
-	rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
 
 	git_config(git_format_config);
 	rev.extra_headers = extra_headers;
@@ -247,6 +246,9 @@ int cmd_format_patch(int argc, const cha
 	if (argc > 1)
 		die ("unrecognized argument: %s", argv[1]);
 
+	if (!rev.diffopt.output_format)
+		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
+
 	if (output_directory) {
 		if (use_stdout)
 			die("standard output, or directory, which one?");
diff.c +0 -1
index 6e5ae77..6be31e7 100644
@@ -1355,7 +1355,6 @@ static void run_checkdiff(struct diff_fi
 void diff_setup(struct diff_options *options)
 {
 	memset(options, 0, sizeof(*options));
-	options->output_format = DIFF_FORMAT_RAW;
 	options->line_termination = '\n';
 	options->break_opt = -1;
 	options->rename_limit = -1;
Signature · 1 line
1.4.1.rc1.g8637
#14 lore raw

PATCH 5/7 DIFF_FORMAT_RAW is not default anymore

In reply to Timo Hirvonen

diff_setup() used to initialize output_format to DIFF_FORMAT_RAW. Now the default is 0 (no output) so don't compare against DIFF_FORMAT_RAW to see if any diff format command line flags were given.

---
 builtin-log.c |    5 +----
 revision.c    |    3 +--
 2 files changed, 2 insertions(+), 6 deletions(-)
builtin-log.c +1 -4
index 65f9527..f173070 100644
@@ -24,11 +24,8 @@ static int cmd_log_wc(int argc, const ch
 	rev->verbose_header = 1;
 	argc = setup_revisions(argc, argv, rev, "HEAD");
 	if (rev->always_show_header) {
-		if (rev->diffopt.pickaxe || rev->diffopt.filter) {
+		if (rev->diffopt.pickaxe || rev->diffopt.filter)
 			rev->always_show_header = 0;
-			if (rev->diffopt.output_format == DIFF_FORMAT_RAW)
-				rev->diffopt.output_format = DIFF_FORMAT_NO_OUTPUT;
-		}
 	}
 
 	if (argc > 1)
revision.c +1 -2
index b963f2a..ae4ca82 100644
@@ -851,8 +851,7 @@ int setup_revisions(int argc, const char
 	}
 	if (revs->combine_merges) {
 		revs->ignore_merges = 0;
-		if (revs->dense_combined_merges &&
-		    (revs->diffopt.output_format != DIFF_FORMAT_DIFFSTAT))
+		if (revs->dense_combined_merges && !revs->diffopt.output_format)
 			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
 	}
 	revs->diffopt.abbrev = revs->abbrev;
Signature · 1 line
1.4.1.rc1.g8637
#15 lore raw

PATCH 6/7 --name-only, --name-status, --check and -s are mutually exclusive

In reply to Timo Hirvonen
---
 diff.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
diff.c +13 -0
index 6be31e7..4b1b4eb 100644
@@ -1366,6 +1366,19 @@ void diff_setup(struct diff_options *opt
 
 int diff_setup_done(struct diff_options *options)
 {
+	int count = 0;
+
+	if (options->output_format & DIFF_FORMAT_NAME)
+		count++;
+	if (options->output_format & DIFF_FORMAT_NAME_STATUS)
+		count++;
+	if (options->output_format & DIFF_FORMAT_CHECKDIFF)
+		count++;
+	if (options->output_format & DIFF_FORMAT_NO_OUTPUT)
+		count++;
+	if (count > 1)
+		die("--name-only, --name-status, --check and -s are mutually exclusive");
+
 	if ((options->find_copies_harder &&
 	     options->detect_rename != DIFF_DETECT_COPY) ||
 	    (0 <= options->rename_limit && !options->detect_rename))
Signature · 1 line
1.4.1.rc1.g8637
#16 lore raw

PATCH 7/7 Remove awkward compatibility warts

In reply to Timo Hirvonen
---
 builtin-diff-files.c |    7 -------
 builtin-diff.c       |    7 -------
 2 files changed, 0 insertions(+), 14 deletions(-)
builtin-diff-files.c +0 -7
index a655eea..3361898 100644
@@ -47,12 +47,5 @@ int cmd_diff_files(int argc, const char 
 	if (rev.pending.nr ||
 	    rev.min_age != -1 || rev.max_age != -1)
 		usage(diff_files_usage);
-	/*
-	 * Backward compatibility wart - "diff-files -s" used to
-	 * defeat the common diff option "-s" which asked for
-	 * DIFF_FORMAT_NO_OUTPUT.
-	 */
-	if (rev.diffopt.output_format == DIFF_FORMAT_NO_OUTPUT)
-		rev.diffopt.output_format = DIFF_FORMAT_RAW;
 	return run_diff_files(&rev, silent);
 }
builtin-diff.c +0 -7
index 47e0a37..076eb09 100644
@@ -56,13 +56,6 @@ static int builtin_diff_files(struct rev
 	if (revs->max_count < 0 &&
 	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
 		revs->combine_merges = revs->dense_combined_merges = 1;
-	/*
-	 * Backward compatibility wart - "diff-files -s" used to
-	 * defeat the common diff option "-s" which asked for
-	 * DIFF_FORMAT_NO_OUTPUT.
-	 */
-	if (revs->diffopt.output_format == DIFF_FORMAT_NO_OUTPUT)
-		revs->diffopt.output_format = DIFF_FORMAT_RAW;
 	return run_diff_files(revs, silent);
 }
 
Signature · 1 line
1.4.1.rc1.g8637
#17 lore raw
In reply to Timo Hirvonen
Quoted 7 lines · Timo Hirvonen

This patch series cleans up diff output format options.

This makes it possible to use any combination of --raw, -p, --stat and --summary options and they work as you would expect.

These patches passed all test and are for the next branch. Patches 6 and 7 are optional.

Thanks, very nicely done. Tentatively placed all of them in "pu"; the first "clean-up" is in "master".

Here are a few problems I have seen:

- "git show --stat HEAD" gives '---' marker as Johannes and you have already discussed (I do not mind this that much though);

- "--cc" seems to be quite broken. "git show v1.0.0" nor "git diff-tree --pretty --cc v1.0.0" does not give the log message, and gives something quite confused instead. I think it is showing "-m -p" followed by "--cc".

We may find more minor breakages, in addition to these, but I am reasonably sure we should be able to fix them in-tree.

#18 lore raw
Quoted 4 lines · Junio C Hamano

Here are a few problems I have seen:

- "git show --stat HEAD" gives '---' marker as Johannes and you have already discussed (I do not mind this that much though);

The patch I sent as a reply to 2/7 should fix this.

Quoted 4 lines

- "--cc" seems to be quite broken. "git show v1.0.0" nor "git diff-tree --pretty --cc v1.0.0" does not give the log message, and gives something quite confused instead. I think it is showing "-m -p" followed by "--cc".

Sorry about that. I don't understand the --cc stuff very well but I try to fix the bug.

Signature · 1 line
http://onion.dynserv.net/~timo/
#19 lore raw
In reply to Junio C Hamano
Quoted 5 lines · Junio C Hamano

Here are a few problems I have seen:

- "git show --stat HEAD" gives '---' marker as Johannes and you have already discussed (I do not mind this that much though);

Quoted 7 lines

- "--cc" seems to be quite broken. "git show v1.0.0" nor "git diff-tree --pretty --cc v1.0.0" does not give the log message, and gives something quite confused instead. I think it is showing "-m -p" followed by "--cc".

We may find more minor breakages, in addition to these, but I am reasonably sure we should be able to fix them in-tree.

Further impressions, while with a clean index and working tree.

First the good ones (improvements).

- "git diff-index --patch-with-raw HEAD" gives empty result; the traditional one shows one empty line.

- "git diff-tree -p --stat" and "git diff-tree --stat -p" works, as you planned.

- "git diff-tree --root --patch-with-raw --summary" works; the traditional one misses --summary.

- "git show --name-only HEAD" works; the traditional one always does --cc -p; the same for "git show -s HEAD".

Regressions, most of the minor.

- "git diff-index -p --stat HEAD" gives one empty line; the traditional one gives empty.

- "git diff-tree --patch-with-raw HEAD" for a non-merge commit misses the empty line between raw and patch.

- "git diff-tree --cc HEAD" for an evil merge (a merge whose result does not match either parents, e.g. v1.0.0) shows extra two-tree diffs (presumably HEAD^1..HEAD and HEAD^2..HEAD) before showing what is expected. The same for "git show".

- "git show --name-only HEAD" for an evil merge similarly shows extra two-tree diffs in --name-only format before showing what is expected. Presumably the same bug as the above.

- "git diff-tree -c HEAD" for an evil merge shows extra newline after the output.

- Neither "git diff-tree -m -s HEAD" for a merge, "git diff-tree -s HEAD" for a non-merge does not squelch the output; same for "git whatchanged".

- "git log --raw HEAD" descends into subdirectories. It instead should show the top-level tree differences.

- "git diff-tree --pretty --patch-with-stat HEAD" for a non-merge misses "---\n" before stat (I think you are aware of this).

- "git show --cc HEAD" for a merge should do "---\n", followed by a stat for diff between HEAD^1..HEAD, followed by dense combined-diff for HEAD.