Git.pm: add subroutines for commenting lines
Add subroutines prefix_lines and comment_lines. Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Vasco Almeida committed
Dec 14, 2016 at 11:54 UTC
2db87101fc3b221b1c015e763d80ee82681d8753
1 file changed
+38
perl/Git.pm
+38
@@ -1421,6 +1421,44 @@ sub END {
1421
1422
} # %TEMP_* Lexical Context
1423
1424
+=item prefix_lines ( PREFIX, STRING [, STRING... ])
1425
+
1426
+Prefixes lines in C<STRING> with C<PREFIX>.
1427
+
1428
+=cut
1429
+
1430
+sub prefix_lines {
1431
+ my $prefix = shift;
1432
+ my $string = join("\n", @_);
1433
+ $string =~ s/^/$prefix/mg;
1434
+ return $string;
1435
+}
1436
+
1437
+=item get_comment_line_char ( )
1438
+
1439
+Gets the core.commentchar configuration value.
1440
+The value falls-back to '#' if core.commentchar is set to 'auto'.
1441
+
1442
+=cut
1443
+
1444
+sub get_comment_line_char {
1445
+ my $comment_line_char = config("core.commentchar") || '#';
1446
+ $comment_line_char = '#' if ($comment_line_char eq 'auto');
1447
+ $comment_line_char = '#' if (length($comment_line_char) != 1);
1448
+ return $comment_line_char;
1449
+}
1450
+
1451
+=item comment_lines ( STRING [, STRING... ])
1452
+
1453
+Comments lines following core.commentchar configuration.
1454
+
1455
+=cut
1456
+
1457
+sub comment_lines {
1458
+ my $comment_line_char = get_comment_line_char;
1459
+ return prefix_lines("$comment_line_char ", @_);
1460
+}
1461
+
1462
=back
1463
1464
=head1 ERROR HANDLING