From: Mark Lodato <lodatom@gmail.com>
To: git@vger.kernel.org
Cc: Mark Lodato <lodatom@gmail.com>
Subject: [PATCH 3/4] grep: move code to print hunk markers after heading
Date: Sun, 25 Mar 2012 22:41:44 -0400 [thread overview]
Message-ID: <1332729705-9283-4-git-send-email-lodatom@gmail.com> (raw)
In-Reply-To: <1332729705-9283-1-git-send-email-lodatom@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2012-03-26 2:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-26 2:41 [PATCH 0/4] grep: add more information to hunk separators Mark Lodato
2012-03-26 2:41 ` [PATCH 1/4] grep doc: add --break / --heading / -W to synopsis Mark Lodato
2012-03-26 2:41 ` [PATCH 2/4] add tests for grep --heading with context Mark Lodato
2012-03-26 2:41 ` Mark Lodato [this message]
2012-03-26 2:41 ` [PATCH 4/4] grep: add --hunk-heading option Mark Lodato
2012-03-26 5:14 ` [PATCH 0/4] grep: add more information to hunk separators Junio C Hamano
2012-03-26 16:16 ` René Scharfe
2012-03-26 18:05 ` Junio C Hamano
2012-03-26 18:48 ` Bert Wesarg
2012-03-26 16:16 ` René Scharfe
2012-03-26 18:01 ` Junio C Hamano
2012-03-26 21:12 ` René Scharfe
2012-03-26 21:19 ` Junio C Hamano
2012-03-27 5:31 ` [PATCH 5/4] move sane_truncate_line to utf8_truncate_line Mark Lodato
2012-03-27 5:31 ` [PATCH 6/4] add grep.hunkHeadingFunction option Mark Lodato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1332729705-9283-4-git-send-email-lodatom@gmail.com \
--to=lodatom@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.