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

[PATCH v2 19/22] git-remote-mediawiki: Don't use quotes for empty strings

From
Célestin Matte <celestin.matte@ensimag.fr>
Date
Jun 7, 2013, 21:42 UTC
Message-ID
<1370641344-4253-20-git-send-email-celestin.matte@ensimag.fr>
In-Reply-To
<1370641344-4253-1-git-send-email-celestin.matte@ensimag.fr>
Empty strings are replaced by an $EMPTY constant.
Signed-off-by: Célestin Matte <celestin.matte@ensimag.fr>
Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>
---
 contrib/mw-to-git/git-remote-mediawiki.perl |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 123730f..e6dc6db 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -41,6 +41,8 @@ Readonly my $NULL_SHA1 => '0000000000000000000000000000000000000000';
 # Used on Git's side to reflect empty edit messages on the wiki
 Readonly my $EMPTY_MESSAGE => '*Empty MediaWiki Message*';
 
+Readonly my $EMPTY => q{};
+
 if (@ARGV != 2) {
 	exit_error_usage();
 }
@@ -163,11 +165,11 @@ sub parse_commands {
 		mw_list($cmd[1]);
 	} elsif ($cmd[0] eq 'import') {
 		die("Invalid arguments for import\n")
-		    if ($cmd[1] eq "" || defined($cmd[2]));
+		    if ($cmd[1] eq $EMPTY || defined($cmd[2]));
 		mw_import($cmd[1]);
 	} elsif ($cmd[0] eq 'option') {
 		die("Too many arguments for option\n")
-		    if ($cmd[1] eq "" || $cmd[2] eq "" || defined($cmd[3]));
+		    if ($cmd[1] eq $EMPTY || $cmd[2] eq $EMPTY || defined($cmd[3]));
 		mw_option($cmd[1],$cmd[2]);
 	} elsif ($cmd[0] eq 'push') {
 		mw_push($cmd[1]);
@@ -558,7 +560,7 @@ sub mediawiki_clean {
 	# Mediawiki does not allow blank space at the end of a page and ends with a single \n.
 	# This function right trims a string and adds a \n at the end to follow this rule
 	$string =~ s/\s+$//;
-	if ($string eq "" && $page_created) {
+	if ($string eq $EMPTY && $page_created) {
 		# Creating empty pages is forbidden.
 		$string = $EMPTY_CONTENT;
 	}
@@ -569,7 +571,7 @@ sub mediawiki_clean {
 sub mediawiki_smudge {
 	my $string = shift;
 	if ($string eq $EMPTY_CONTENT) {
-		$string = "";
+		$string = $EMPTY;
 	}
 	# This \n is important. This is due to mediawiki's way to handle end of files.
 	return "${string}\n";
@@ -995,7 +997,7 @@ sub mw_upload_file {
 	} else {
 		# Don't let perl try to interpret file content as UTF-8 => use "raw"
 		my $content = run_git("cat-file blob ${new_sha1}", 'raw');
-		if ($content ne "") {
+		if ($content ne $EMPTY) {
 			mw_connect_maybe();
 			$mediawiki->{config}->{upload_url} =
 				"${url}/index.php/Special:Upload";
@@ -1037,7 +1039,7 @@ sub mw_push_file {
 	my $newrevid;
 
 	if ($summary eq $EMPTY_MESSAGE) {
-		$summary = '';
+		$summary = $EMPTY;
 	}
 
 	my $new_sha1 = $diff_info_split[3];
@@ -1048,7 +1050,7 @@ sub mw_push_file {
 
 	my ($title, $extension) = $complete_file_name =~ /^(.*)\.([^\.]*)$/;
 	if (!defined($extension)) {
-		$extension = "";
+		$extension = $EMPTY;
 	}
 	if ($extension eq 'mw') {
 		my $ns = get_mw_namespace_id_for_page($complete_file_name);
@@ -1116,7 +1118,7 @@ sub mw_push {
 		if ($force) {
 			print {*STDERR} "Warning: forced push not allowed on a MediaWiki.\n";
 		}
-		if ($local eq "") {
+		if ($local eq $EMPTY) {
 			print {*STDERR} "Cannot delete remote branch on a MediaWiki\n";
 			print {*STDOUT} "error ${remote} cannot delete\n";
 			next;
-- 
1.7.9.5
Previous: Célestin MatteNext: Célestin Matte
Message 37 of 41 in “git-remote-mediawiki: Follow perlcritic's recommandations”
  1. 00/22 git-remote-mediawiki: Follow perlcritic's recommandationsCélestin Matte, Jun 7, 2013
  2. 01/22 git-remote-mediawiki: Replace :utf8 by :encoding(UTF-8)Célestin Matte, Jun 7, 2013
  3. 02/22 git-remote-mediawiki: Use the Readonly module instead of the constant pragmaCélestin Matte, Jun 7, 2013
  4. Jeff KingJun 8, 2013
  5. Benoît PersonJun 8, 2013
  6. Célestin PerduJun 8, 2013
  7. Jeff KingJun 8, 2013
  8. Matthieu MoyJun 8, 2013
  9. 03/22 git-remote-mediawiki: Always end a subroutine with a returnCélestin Matte, Jun 7, 2013
  10. 04/22 git-remote-mediawiki: Move a variable declaration at the top of the codeCélestin Matte, Jun 7, 2013
  11. 05/22 git-remote-mediawiki: Change syntax of map callsCélestin Matte, Jun 7, 2013
  12. 06/22 git-remote-mediawiki: Rewrite unclear line of instructionsCélestin Matte, Jun 7, 2013
  13. 07/22 git-remote-mediawiki: Change style of some regular expressionsCélestin Matte, Jun 7, 2013
  14. Eric SunshineJun 8, 2013
  15. 08/22 git-remote-mediawiki: Add newline in the end of die() error messagesCélestin Matte, Jun 7, 2013
  16. 09/22 git-remote-mediawiki: Change the name of a variableCélestin Matte, Jun 7, 2013
  17. 10/22 git-remote-mediawiki: Turn double-negated expressions into simple expressionsCélestin Matte, Jun 7, 2013
  18. 11/22 git-remote-mediawiki: Remove unused variable $entryCélestin Matte, Jun 7, 2013
  19. 12/22 git-remote-mediawiki: Rename a variable ($last) which has the name of a keywordCélestin Matte, Jun 7, 2013
  20. 13/22 git-remote-mediawiki: Assign a variable as undef and make proper indentationCélestin Matte, Jun 7, 2013
  21. 14/22 git-remote-mediawiki: Check return value of open + remove import of unused open2Célestin Matte, Jun 7, 2013
  22. Eric SunshineJun 8, 2013
  23. Célestin MatteJun 8, 2013
  24. Matthieu MoyJun 8, 2013
  25. Célestin MatteJun 8, 2013
  26. Matthieu MoyJun 8, 2013
  27. Eric SunshineJun 9, 2013
  28. 15/22 git-remote-mediawiki: Put long code into a subroutineCélestin Matte, Jun 7, 2013
  29. Eric SunshineJun 8, 2013
  30. 16/22 git-remote-mediawiki: Modify strings for a better coding-styleCélestin Matte, Jun 7, 2013
  31. Eric SunshineJun 8, 2013
  32. Célestin MatteJun 8, 2013
  33. Eric SunshineJun 9, 2013
  34. 17/22 git-remote-mediawiki: Brace file handles for print for more clarityCélestin Matte, Jun 7, 2013
  35. Eric SunshineJun 8, 2013
  36. 18/22 git-remote-mediawiki: Replace "unless" statements with negated "if" statementsCélestin Matte, Jun 7, 2013
  37. 19/22 git-remote-mediawiki: Don't use quotes for empty stringsCélestin Matte, Jun 7, 2013
  38. 20/22 git-remote-mediawiki: Put non-trivial numeric values in constants.Célestin Matte, Jun 7, 2013
  39. 21/22 git-remote-mediawiki: Fix a typo ("mediwiki" instead of "mediawiki")Célestin Matte, Jun 7, 2013
  40. 22/22 git-remote-mediawiki: Clearly rewrite double dereferenceCélestin Matte, Jun 7, 2013
  41. Eric SunshineJun 7, 2013

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.