Re: [PATCH v5 1/4] add -p: select individual hunk lines
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 26, 2018, 19:36 UTC
- Message-ID
- <xmqqin51pz5u.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20180726155854.20832-2-phillip.wood@talktalk.net>
Phillip Wood <phillip.wood@talktalk.net> writes:
Show 6 quoted lines
> +sub label_hunk_lines {
> + my $hunk = shift;
> + my $text = $hunk->{TEXT};
> + my (@line_flags, @lines);
> + my ($block, $label, $last_mode) = (0, 0, '');
> + for my $line (1..$#{$text}) {$text is a ref to an array so @$text is the whole thing, $#{$text} is the index of the last item in that array, and $text->[0] is the first element of that array. This for loop runs with $line == 1 thru $line == $#{$text}, so we are somehow excluding the very first element?
Show 10 quoted lines
> + $line_flags[$line] = 0;
> + my $mode = substr($text->[$line], 0, 1);
> + if ($mode eq '\\') {
> + $line_flags[$line - 1] |= NO_NEWLINE;
> + }
> + if ($mode eq '-' or $mode eq '+') {
> + $lines[++$label] = $line;
> + }
> + }
> + if ($label > 1) {