From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] git-add--interactive: Preserve diff heading when splitting hunks
Date: Sun, 11 May 2014 10:52:45 -0700 [thread overview]
Message-ID: <xmqqfvkgurrm.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1399824596-4670-1-git-send-email-avarab@gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Sun, 11 May 2014 16:09:56 +0000")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Change the display of hunks in hunk splitting mode to preserve the diff
> heading, which hasn't been done ever since the hunk splitting was
> initially added in v1.4.4.2-270-g835b2ae.
>
> Splitting the first hunk of this patch will now result in:
>
> Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? s
> Split into 2 hunks.
> @@ -792,7 +792,7 @@ sub hunk_splittable {
> [...]
>
> Instead of:
>
> Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? s
> Split into 2 hunks.
> @@ -792,7 +792,7 @@
> [...]
>
> This makes it easier to use the tool when you're splitting some giant
> hunk and can't remember in which function you are anymore.
Makes sense to me.
>
> The diff is somewhat larger than I initially expected because in order
> to display the headings in the same color scheme as the output from
> git-diff(1) itself I had to split up the code that would previously
> color diff output that previously consisted entirely of the fraginfo,
> but now consists of the fraginfo and the diff heading (the latter of
> which isn't colored).
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> git-add--interactive.perl | 40 ++++++++++++++++++++++++----------------
> 1 file changed, 24 insertions(+), 16 deletions(-)
>
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index 1fadd69..ed1e564 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -792,11 +792,11 @@ sub hunk_splittable {
>
> sub parse_hunk_header {
> my ($line) = @_;
> - my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
> - $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
> + my ($o_ofs, $o_cnt, $n_ofs, $n_cnt, $heading) =
> + $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)/;
> $o_cnt = 1 unless defined $o_cnt;
> $n_cnt = 1 unless defined $n_cnt;
> - return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
> + return ($o_ofs, $o_cnt, $n_ofs, $n_cnt, $heading);
> }
>
> sub split_hunk {
> @@ -808,8 +808,7 @@ sub split_hunk {
> # If there are context lines in the middle of a hunk,
> # it can be split, but we would need to take care of
> # overlaps later.
> -
> - my ($o_ofs, undef, $n_ofs) = parse_hunk_header($text->[0]);
> + my ($o_ofs, undef, $n_ofs, undef, $heading) = parse_hunk_header($text->[0]);
> my $hunk_start = 1;
>
> OUTER:
> @@ -886,17 +885,26 @@ sub split_hunk {
> my $o_cnt = $hunk->{OCNT};
> my $n_cnt = $hunk->{NCNT};
>
> - my $head = ("@@ -$o_ofs" .
> - (($o_cnt != 1) ? ",$o_cnt" : '') .
> - " +$n_ofs" .
> - (($n_cnt != 1) ? ",$n_cnt" : '') .
> - " @@\n");
> - my $display_head = $head;
> - unshift @{$hunk->{TEXT}}, $head;
> - if ($diff_use_color) {
> - $display_head = colored($fraginfo_color, $head);
> - }
> - unshift @{$hunk->{DISPLAY}}, $display_head;
> + my $fraginfo = join(
> + "",
> + "@@ -$o_ofs",
> + (($o_cnt != 1) ? ",$o_cnt" : ''),
> + " +$n_ofs",
> + (($n_cnt != 1) ? ",$n_cnt" : ''),
> + " @@"
> + );
> + unshift @{$hunk->{TEXT}}, join(
> + "",
> + $fraginfo,
> + $heading,
> + "\n"
> + );
> + unshift @{$hunk->{DISPLAY}}, join(
> + "",
> + $diff_use_color ? colored($fraginfo_color, $fraginfo) : $fraginfo,
> + $heading,
> + "\n"
> + );
> }
> return @split;
> }
next prev parent reply other threads:[~2014-05-11 17:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-11 16:09 [PATCH] git-add--interactive: Preserve diff heading when splitting hunks Ævar Arnfjörð Bjarmason
2014-05-11 17:52 ` Junio C Hamano [this message]
2014-05-12 18:39 ` Jeff King
2014-05-12 19:42 ` Ævar Arnfjörð Bjarmason
2014-05-12 20:09 ` Jeff King
2014-05-12 21:07 ` Junio C Hamano
2014-05-12 21:12 ` Jeff King
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=xmqqfvkgurrm.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=avarab@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.