[PATCH 3/4] grep: move code to print hunk markers after heading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit does not have any effect on the output of the program.
The purpose is to distinguish in the code between two kinds of hunk
separators: those that occur before the heading and those that occur
after.  This step is necessary for the next commit, which will modify
only the latter tyep of hunk separators.

Signed-off-by: Mark Lodato <lodatom@xxxxxxxxx>
---
 grep.c |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/grep.c b/grep.c
index 190139c..14e0480 100644
--- a/grep.c
+++ b/grep.c
@@ -739,25 +739,26 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
 {
 	int rest = eol - bol;
 	char *line_color = NULL;
+	int show_hunk = (opt->pre_context || opt->post_context ||
+			 opt->funcbody);
 
-	if (opt->file_break && opt->last_shown == 0) {
-		if (opt->show_hunk_mark)
-			opt->output(opt, "\n", 1);
-	} else if (opt->pre_context || opt->post_context || opt->funcbody) {
-		if (opt->last_shown == 0) {
-			if (opt->show_hunk_mark) {
-				output_color(opt, "--", 2, opt->color_sep);
-				opt->output(opt, "\n", 1);
-			}
-		} else if (lno > opt->last_shown + 1) {
+	if (opt->show_hunk_mark && opt->last_shown == 0 &&
+	    (opt->file_break || (opt->heading && show_hunk))) {
+		if (opt->heading && !opt->file_break)
 			output_color(opt, "--", 2, opt->color_sep);
-			opt->output(opt, "\n", 1);
-		}
+		opt->output(opt, "\n", 1);
+		show_hunk = 0;
 	}
 	if (opt->heading && opt->last_shown == 0) {
 		output_color(opt, name, strlen(name), opt->color_filename);
 		opt->output(opt, "\n", 1);
 	}
+	if (show_hunk &&
+	    ((opt->last_shown == 0 && opt->show_hunk_mark) ||
+	     (opt->last_shown != 0 && lno > opt->last_shown + 1))) {
+		output_color(opt, "--", 2, opt->color_sep);
+		opt->output(opt, "\n", 1);
+	}
 	opt->last_shown = lno;
 
 	if (!opt->heading && opt->pathname) {
-- 
1.7.9.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]