git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v6 01/16] Git.pm: add subroutines for commenting lines

From
Vasco Almeida <vascomalmeida@sapo.pt>
Date
Dec 10, 2016, 10:08 UTC
Message-ID
<1481364496.1993.14.camel@sapo.pt>
In-Reply-To
<xmqqk2b8rbbb.fsf@gitster.mtv.corp.google.com>
A Sex, 09-12-2016 às 14:23 -0800, Junio C Hamano escreveu:
Show 7 quoted lines
> > This is exactly the same issue I fixed for rebase -i recently.
> 
> Yes, but the patch we see here punts "core.commentChar is not a
> single-byte single-letter--panic!" case differently.  I think you
> did "just take the first one" in "rebase -i", which I think is more
> in line with the rest of the system, and this addition to Git.pm
> should do the same, I think.

I hope the changes below are in line with the rest of the system. If so, I will send a new re-roll with them.

I wonder why this is important when Git errors out when core.commentChar is set to more than 1 characters or 0 characters. Is it just to be consistent with "rebase -i" changes introduced by Johannes Schindelin?

I am not sure what does "if (length($comment_line_char) != 1)" check. Whether it checks single-byte or single-letter or both...

-- >8 --
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 3a6d846..4e0ab5a 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -1072,7 +1072,7 @@ sub edit_hunk_manually {
 	print $fh @$oldtext;
 	my $is_reverse = $patch_mode_flavour{IS_REVERSE};
 	my ($remove_plus, $remove_minus) = $is_reverse ? ('-', '+') :
('+', '-');
-	my $comment_line_char = Git::config("core.commentchar") ||
'#';
+	my $comment_line_char = Git::get_comment_line_char;
 	print $fh Git::comment_lines sprintf(__ <<EOF, $remove_minus,
$remove_plus, $comment_line_char),
 ---
 To remove '%s' lines, make them ' ' lines (context).
diff --git a/perl/Git.pm b/perl/Git.pm
index 69cd1dd..3211650 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1451,6 +1451,23 @@ sub prefix_lines {
 	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');
+	if (length($comment_line_char) != 1) {
+		# use first character
+		$comment_line_char = substr($comment_line_char, 0, 1);
+	}
+	return $comment_line_char;
+}
+
 =item comment_lines ( STRING [, STRING... ])
 
 Comments lines following core.commentchar configuration.
@@ -1458,7 +1475,7 @@ Comments lines following core.commentchar
configuration.
 =cut
 
 sub comment_lines {
-	my $comment_line_char = config("core.commentchar") || '#';
+	my $comment_line_char = get_comment_line_char;
 	return prefix_lines("$comment_line_char ", @_);
 }
 
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 26 in “Mark strings in Perl scripts for translation”
  1. 00/16 Mark strings in Perl scripts for translationVasco Almeida, Nov 11, 2016
  2. 01/16 Git.pm: add subroutines for commenting linesVasco Almeida, Nov 11, 2016
  3. Vasco AlmeidaNov 22, 2016
  4. Junio C HamanoNov 22, 2016
  5. Vasco AlmeidaDec 9, 2016
  6. Johannes SchindelinDec 9, 2016
  7. Junio C HamanoDec 9, 2016
  8. Vasco AlmeidaDec 10, 2016
  9. Junio C HamanoDec 10, 2016
  10. Vasco AlmeidaDec 13, 2016
  11. Junio C HamanoDec 13, 2016
  12. 05/16 i18n: clean.c: match string with git-add--interactive.perlVasco Almeida, Nov 11, 2016
  13. 07/16 i18n: add--interactive: mark patch prompt for translationVasco Almeida, Nov 11, 2016
  14. 11/16 i18n: add--interactive: mark status words for translationVasco Almeida, Nov 11, 2016
  15. 12/16 i18n: send-email: mark strings for translationVasco Almeida, Nov 11, 2016
  16. 13/16 i18n: send-email: mark warnings and errors for translationVasco Almeida, Nov 11, 2016
  17. 15/16 i18n: send-email: mark composing message for translationVasco Almeida, Nov 11, 2016
  18. 08/16 i18n: add--interactive: i18n of help_patch_cmdVasco Almeida, Nov 11, 2016
  19. 14/16 i18n: send-email: mark string with interpolation for translationVasco Almeida, Nov 11, 2016
  20. 16/16 i18n: difftool: mark warnings for translationVasco Almeida, Nov 11, 2016
  21. 10/16 i18n: add--interactive: remove %patch_modes entriesVasco Almeida, Nov 11, 2016
  22. 09/16 i18n: add--interactive: mark edit_hunk_manually message for translationVasco Almeida, Nov 11, 2016
  23. 06/16 i18n: add--interactive: mark plural stringsVasco Almeida, Nov 11, 2016
  24. 04/16 i18n: add--interactive: mark strings with interpolation for translationVasco Almeida, Nov 11, 2016
  25. 02/16 i18n: add--interactive: mark strings for translationVasco Almeida, Nov 11, 2016
  26. 03/16 i18n: add--interactive: mark simple here-documents for translationVasco Almeida, Nov 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.