git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] grep: add more information to hunk separators
@ 2012-03-26  2:41 Mark Lodato
  2012-03-26  2:41 ` [PATCH 1/4] grep doc: add --break / --heading / -W to synopsis Mark Lodato
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Mark Lodato @ 2012-03-26  2:41 UTC (permalink / raw)
  To: git; +Cc: Mark Lodato

This patch series adds a new `grep --hunk-heading' option that moves the
filename and line number to the hunk separator lines ("--") rather than at the
beginning of each matching (or context) line.  In my opinion, this makes the
output easier to read, especially when combined with `--heading'.

I am not sure that "hunk-heading" is the best term, so I welcome ideas on
better names.

Here's an example:

    # Current behavior:
    $ git grep -p -C1 -n list_common -- git.c
    git.c=531=int main(int argc, const char **argv)
    --
    git.c-570-              printf("usage: %s\n\n", git_usage_string);
    git.c:571:              list_common_cmds_help();
    git.c-572-              printf("\n%s\n", git_more_info_string);

    # New option:
    $ git grep -p -C1 --hunk-heading list_common -- git.c
    -- git.c:531 --
    int main(int argc, char argv)
    -- git.c:570 --
                    printf("usage: %s\n\n", git_usage_string);
                    list_common_cmds_help();
                    printf("\n%s\n", git_more_info_string);

    # New option with --heading:
    $ git grep -p -C1 --hunk-heading --heading list_common -- git.c
    git.c
    -- 531 --
    int main(int argc, char argv)
    -- 570 --
                    printf("usage: %s\n\n", git_usage_string);
                    list_common_cmds_help();
                    printf("\n%s\n", git_more_info_string);

Originally, I had envisioned also moving the function name (`-p') to the hunk
header, similar to the diff context line.  For example:

    -- git.c:570 -- int main(int argc, char argv)
                    printf("usage: %s\n\n", git_usage_string);
                    list_common_cmds_help();
                    printf("\n%s\n", git_more_info_string);

After implementing this feature, I was not happy with the result and
subsequently removed it.  To me, the output was too cluttered and the line
number was ambigous.  For example, in the above, it is not obvious to me that
line 570 is the "printf" line and not the "int main" line.  Still, if you
would like to see the patch to implement this feature, please let me know.


Mark Lodato (4):
  grep doc: add --break / --heading / -W to synopsis
  add tests for grep --heading with context
  grep: move code to print hunk markers after heading
  grep: add --hunk-heading option

 Documentation/config.txt     |    3 +
 Documentation/git-grep.txt   |   10 +++
 builtin/grep.c               |   10 ++-
 grep.c                       |   49 ++++++++----
 grep.h                       |    1 +
 t/t7810-grep.sh              |   37 +++++++++
 t/t7812-grep-hunk-heading.sh |  181 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 276 insertions(+), 15 deletions(-)
 create mode 100755 t/t7812-grep-hunk-heading.sh

-- 
1.7.9.2

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-03-27  5:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/4] grep: move code to print hunk markers after heading Mark Lodato
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).