]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Git.pm: add subroutines for commenting lines
authorVasco Almeida <vascomalmeida@sapo.pt>
Wed, 14 Dec 2016 12:54:24 +0000 (11:54 -0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 Dec 2016 19:00:04 +0000 (11:00 -0800)
Add subroutines prefix_lines and comment_lines.

Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
perl/Git.pm

index ce7e4e8da3947bb2c527c49d6d09e1e49b0392c3..f699fee9a17282f20ddcc811bc676a8217c7d558 100644 (file)
@@ -1421,6 +1421,44 @@ sub END {
 
 } # %TEMP_* Lexical Context
 
+=item prefix_lines ( PREFIX, STRING [, STRING... ])
+
+Prefixes lines in C<STRING> with C<PREFIX>.
+
+=cut
+
+sub prefix_lines {
+       my $prefix = shift;
+       my $string = join("\n", @_);
+       $string =~ s/^/$prefix/mg;
+       return $string;
+}
+
+=item get_comment_line_char ( )
+
+Gets the core.commentchar configuration value.
+The value falls-back to '#' if core.commentchar is set to 'auto'.
+
+=cut
+
+sub get_comment_line_char {
+       my $comment_line_char = config("core.commentchar") || '#';
+       $comment_line_char = '#' if ($comment_line_char eq 'auto');
+       $comment_line_char = '#' if (length($comment_line_char) != 1);
+       return $comment_line_char;
+}
+
+=item comment_lines ( STRING [, STRING... ])
+
+Comments lines following core.commentchar configuration.
+
+=cut
+
+sub comment_lines {
+       my $comment_line_char = get_comment_line_char;
+       return prefix_lines("$comment_line_char ", @_);
+}
+
 =back
 
 =head1 ERROR HANDLING