From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Subject: [PATCH v3 4/8] gitweb: Extract print_sidebyside_diff_lines() Date: Wed, 4 Apr 2012 21:57:09 +0200 Message-ID: <1333569433-3245-5-git-send-email-michal.kiedrowicz@gmail.com> References: <1333569433-3245-1-git-send-email-michal.kiedrowicz@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Jakub Narebski , =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Wed Apr 04 21:57:37 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SFWKm-0001cc-7t for gcvg-git-2@plane.gmane.org; Wed, 04 Apr 2012 21:57:36 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932769Ab2DDT5e convert rfc822-to-quoted-printable (ORCPT ); Wed, 4 Apr 2012 15:57:34 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:60997 "EHLO mail-wi0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932624Ab2DDT5b (ORCPT ); Wed, 4 Apr 2012 15:57:31 -0400 Received: by wibhr17 with SMTP id hr17so797974wib.1 for ; Wed, 04 Apr 2012 12:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=5tukVHTKCc2wUHSdWCX3FTkHEU3D8i3EZeCFDZpcpbU=; b=xx7VR/nSUrPqfGwFr3vdgDdsG3qicI6yVJE/sGlSKPghMv4EPRprPE56FtHBniTuUO zVm2hLqAxozchZFn64MIlC2gqsLIMWaqUG2djcgL/CdC0dq+YJmqIdXLAVUaouPJelkT Aub2W4jbFIDoIqolKu/hbAxVuEn78nqvY4+2blYK71C/xk+GrNnPP+boWa7FAkWZg7ll H8KjUUJcZ7+FFfqPY/U+JenvMEIEoXjeRMryCqbUDmCh+y7uVOCaEkoYxYE6YvB1gn0x TvfF0jsw/5zpLQZTFfrZhb+X2iDfkXkhweAQOZWLNDYTc0yk102+DLAQvyaHpxqjCJBW 73KA== Received: by 10.216.135.103 with SMTP id t81mr2221734wei.113.1333569450505; Wed, 04 Apr 2012 12:57:30 -0700 (PDT) Received: from localhost (77-177-78-94.net.stream.pl. [94.78.177.77]) by mx.google.com with ESMTPS id l5sm7353317wia.11.2012.04.04.12.57.28 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 Apr 2012 12:57:29 -0700 (PDT) X-Mailer: git-send-email 1.7.8.4 In-Reply-To: <1333569433-3245-1-git-send-email-michal.kiedrowicz@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Currently, print_sidebyside_diff_chunk() does two things: it accumulates diff lines and prints them. Accumulation may be used to perform additional operations on diff lines, so it makes sense to spli= t these two things. Thus, the code that prints diff lines in a side-by-s= ide manner is moved out of print_sidebyside_diff_chunk() to a separate subroutine. The outcome of this patch is that print_sidebyside_diff_chunk() is now much shorter and easier to read. This is a preparation patch for diff refinement highlightning. It shou= ld not change the gitweb output, but it slightly changes its behavior. Before this commit, context is printed on the class change. Now, it's printed just before printing added and removed lines, and at the end of chunk. Signed-off-by: Micha=C5=82 Kiedrowicz Acked-by: Jakub Nar=C4=99bski --- gitweb/gitweb.perl | 97 ++++++++++++++++++++++++++++----------------= -------- 1 files changed, 52 insertions(+), 45 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index d5f802f..56721a3 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5000,6 +5000,53 @@ sub git_difftree_body { print "\n"; } =20 +# Print context lines and then rem/add lines in a side-by-side manner. +sub print_sidebyside_diff_lines { + my ($ctx, $rem, $add) =3D @_; + + # print context block before add/rem block + if (@$ctx) { + print join '', + '
', + '
', + @$ctx, + '
', + '
', + @$ctx, + '
', + '
'; + } + + if (!@$add) { + # pure removal + print join '', + '
', + '
', + @$rem, + '
', + '
'; + } elsif (!@$rem) { + # pure addition + print join '', + '
', + '
', + @$add, + '
', + '
'; + } else { + # assume that it is change + print join '', + '
', + '
', + @$rem, + '
', + '
', + @$add, + '
', + '
'; + } +} + sub print_sidebyside_diff_chunk { my @chunk =3D @_; my (@ctx, @rem, @add); @@ -5026,51 +5073,11 @@ sub print_sidebyside_diff_chunk { next; } =20 - ## print from accumulator when type of class of lines change - # empty contents block on start rem/add block, or end of chunk - if (@ctx && (!$class || $class eq 'rem' || $class eq 'add')) { - print join '', - '
', - '
', - @ctx, - '
', - '
', - @ctx, - '
', - '
'; - @ctx =3D (); - } - # empty add/rem block on start context block, or end of chunk - if ((@rem || @add) && (!$class || $class eq 'ctx')) { - if (!@add) { - # pure removal - print join '', - '
', - '
', - @rem, - '
', - '
'; - } elsif (!@rem) { - # pure addition - print join '', - '
', - '
', - @add, - '
', - '
'; - } else { - # assume that it is change - print join '', - '
', - '
', - @rem, - '
', - '
', - @add, - '
', - '
'; - } - @rem =3D @add =3D (); + ## print from accumulator when have some add/rem lines or end + # of chunk (flush context lines) + if (((@rem || @add) && $class eq 'ctx') || !$class) { + print_sidebyside_diff_lines(\@ctx, \@rem, \@add); + @ctx =3D @rem =3D @add =3D (); } =20 ## adding lines to accumulator --=20 1.7.8.4