[PATCH 2/5] add--interactive: factor out regex error handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When perl complains about compiling a regex the user has
given us, we trim the error to get a nicer message. It's
only one line of code, but it's ugly and non-obvious, so
let's factor it into a reusable function.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
 git-add--interactive.perl |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index c5cd300..3e4c8a4 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1267,6 +1267,12 @@ sub display_hunks {
 	return $i;
 }
 
+sub trim_error {
+	local $_ = shift;
+	s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
+	return $_;
+}
+
 sub patch_update_file {
 	my $quit = 0;
 	my ($ix, $num);
@@ -1419,9 +1425,8 @@ sub patch_update_file {
 					$search_string = qr{$regex}m;
 				};
 				if ($@) {
-					my ($err,$exp) = ($@, $1);
-					$err =~ s/ at .*git-add--interactive line \d+, <STDIN> line \d+.*$//;
-					error_msg "Malformed search regexp $exp: $err\n";
+					my $exp = $1;
+					error_msg "Malformed search regexp $exp: " . trim_error($@) . "\n";
 					next;
 				}
 				my $iy = $ix;
-- 
1.7.5.4.31.ge4d5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]