{"thread":{"id":"34160","subject":"[PATCH V3 0/4] git-remote-mediawiki: new tool to preview local changes without pushing","startedAt":"2013-06-16T02:31:29Z","lastAt":"2013-06-18T10:54:52Z","messageCount":13,"participants":["benoit.person@ensimag.fr","Ramkumar Ramachandra","Matthieu Moy","Benoît Person"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"220973","messageId":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","threadId":"34160","inReplyTo":null,"subject":"[PATCH V3 0/4] git-remote-mediawiki: new tool to preview local changes without pushing","fromName":"","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T02:31:29Z","receivedAt":"2013-06-16T02:31:29Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"From: Benoit Person <benoit.person@ensimag.fr>\n\nThe #7 issue on git-mediawiki's issue tracker [1] states that the ability to\npreview content without pushing would be a nice thing to have.\n\nchanges from V2:\n  - Add a way to test, without installation, code that uses GitMediawiki.pm.\n  - Move more constants to GitMediawiki.pm\n  - Remove the encapsulation of Git::config calls into a git_cmd_try one.\n  - Remove the --blob option, distinction between files and blobs is now \n    automatic.\n  - Add a --verbose option to output more information on what's going on.\n  - Rewrote the doc and the commit message.\n  - Rewrote of the template retrieving code (see 'get_template' sub).\n  - Use a configuration variable to define the content ID search in the\n    template. Default value set as 'bodyContent' since it seems more standard\n    than 'mw-content-text'.\n  - Final content is now saved as utf-8 to solve encoding issues.\n  - Perlcritic changes: \n    - Update for loops style to a more perlish one.\n    - All 'print's specify their output streams.\n    --> Same useless warnings left in git-remote-mediawiki.perl after célestin's \n        work and git-mw.perl after this patch :) .\n\nchanges from V1:\n  - add new package GitMediawiki\n    - move some of git-remote-mediawiki functions into the package\n    - update git-remote-mediawiki to use those \"moved\" functions\n    - add a hacky-way to install it in the Makefile\n    - use it in the new git mw tool\n  - add a way to give to the preview tool blobs as argument\n  - add a fallback when the upstream's branch remote is not a mediawiki remote\n  - update the `autoload` option to use `git web--browse` and not `xdg-open`\n  - update the way we find the upstream's branch remote name\n\nThis serie is based on the 'master' branch merged with célestin's patch series.\n\n[1] https://github.com/moy/Git-Mediawiki/issues/7\n\nBenoit Person (4):\n  git-mw: Introduction of GitMediawiki.pm\n  git-mw: Move some functions from git-remote-mediawiki.perl to\n    GitMediawiki.pm\n  git-mw: Adding git-mw command\n  git-mw: Add preview subcommand into git mw.\n\n contrib/mw-to-git/GitMediawiki.pm           | 100 ++++++++\n contrib/mw-to-git/Makefile                  |  29 ++-\n contrib/mw-to-git/git-mw.perl               | 347 ++++++++++++++++++++++++++++\n contrib/mw-to-git/git-remote-mediawiki.perl |  85 ++-----\n 4 files changed, 485 insertions(+), 76 deletions(-)\n create mode 100644 contrib/mw-to-git/GitMediawiki.pm\n create mode 100644 contrib/mw-to-git/git-mw.perl\n\n-- \n1.8.3.GIT\n"},{"id":"220974","messageId":"1371349893-7789-2-git-send-email-benoit.person@ensimag.fr","threadId":"34160","inReplyTo":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","subject":"[PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T02:31:30Z","receivedAt":"2013-06-16T02:31:30Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"From: Benoit Person <benoit.person@ensimag.fr>\n\nGitMediawiki.pm enable code factoring between several scripts in mw-to-git.\n\nTo make it usable in scripts (ie: accessible in @INC) it adds two targets\n(copy_pm & install_pm) into the Makefile, one for tests and one for\ninstallation.\n\nSigned-off-by: Benoit Person <benoit.person@ensimag.fr>\nSigned-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>\n\n---\n\nchanges from the V2:\n  - Add a way to test, without installation, code that uses GitMediawiki.pm.\n\n contrib/mw-to-git/GitMediawiki.pm | 24 ++++++++++++++++++++++++\n contrib/mw-to-git/Makefile        | 26 +++++++++++++++++++++++---\n 2 files changed, 47 insertions(+), 3 deletions(-)\n create mode 100644 contrib/mw-to-git/GitMediawiki.pm\n\ndiff --git a/contrib/mw-to-git/GitMediawiki.pm b/contrib/mw-to-git/GitMediawiki.pm\nnew file mode 100644\nindex 0000000..8a0ffc7\n--- /dev/null\n+++ b/contrib/mw-to-git/GitMediawiki.pm\n@@ -0,0 +1,24 @@\n+package GitMediawiki;\n+\n+use 5.008;\n+use strict;\n+use Git;\n+\n+BEGIN {\n+\n+our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);\n+\n+# Totally unstable API.\n+$VERSION = '0.01';\n+\n+require Exporter;\n+\n+@ISA = qw(Exporter);\n+\n+@EXPORT = ();\n+\n+# Methods which can be called as standalone functions as well:\n+@EXPORT_OK = ();\n+}\n+\n+1; # Famous last words\n\\ No newline at end of file\ndiff --git a/contrib/mw-to-git/Makefile b/contrib/mw-to-git/Makefile\nindex 1fb2424..b0c7cf2 100644\n--- a/contrib/mw-to-git/Makefile\n+++ b/contrib/mw-to-git/Makefile\n@@ -4,16 +4,36 @@\n #\n ## Build git-remote-mediawiki\n \n+GIT_MEDIAWIKI_PM=GitMediawiki.pm\n SCRIPT_PERL=git-remote-mediawiki.perl\n GIT_ROOT_DIR=../..\n HERE=contrib/mw-to-git/\n \n SCRIPT_PERL_FULL=$(patsubst %,$(HERE)/%,$(SCRIPT_PERL))\n+INSTLIBDIR=$(shell $(MAKE) -C $(GIT_ROOT_DIR)/perl \\\n+                -s --no-print-directory instlibdir)\n \n all: build\n \n-build install clean:\n+copy_pm:\n+\tcp $(GIT_MEDIAWIKI_PM) $(GIT_ROOT_DIR)/perl/blib/lib/\n+\n+install_pm:\n+\tcp $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)\n+\n+build: copy_pm\n+\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n+                build-perl-script\n+\n+install: install_pm\n \t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n-                $@-perl-script\n+                install-perl-script\n+\n+clean:\n+\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n+                clean-perl-script\n+\trm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM) \\\n+       $(GIT_ROOT_DIR)/perl/blib/lib/$(GIT_MEDIAWIKI_PM)\n+\n perlcritic:\n-\tperlcritic -2 *.perl\n+\tperlcritic -2 *.perl\n\\ No newline at end of file\n-- \n1.8.3.GIT\n"},{"id":"220976","messageId":"1371349893-7789-3-git-send-email-benoit.person@ensimag.fr","threadId":"34160","inReplyTo":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","subject":"[PATCH V3 2/4] git-mw: Move some functions from git-remote-mediawiki.perl to GitMediawiki.pm","fromName":"","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T02:31:31Z","receivedAt":"2013-06-16T02:31:31Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"From: Benoit Person <benoit.person@ensimag.fr>\n\nMove and rename subs 'mediawiki_clean_filename' into 'clean_filename',\n'mediawiki_smudge_filename' into 'smudge_filename' and\n'mw_connect_maybe' into 'connect_maybe' since we have a cleaner namespace in\na perl module.\nMove constants 'EMPTY', 'SLASH_REPLACEMENT' and 'HTTP_CODE_OK'.\nRemove side effects in those functions to provide a cleaner API.\nUpdate git-remote-mediawiki for those changes.\n\nSigned-off-by: Benoit Person <benoit.person@ensimag.fr>\nSigned-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>\n\n---\n\nchanges from the V2:\n  - Move more constants to GitMediawiki.pm.\n  - Remove the encapsulation of Git::config calls into a git_cmd_try one.\n\n contrib/mw-to-git/GitMediawiki.pm           | 77 +++++++++++++++++++++++++-\n contrib/mw-to-git/git-remote-mediawiki.perl | 85 +++++------------------------\n 2 files changed, 89 insertions(+), 73 deletions(-)\n\ndiff --git a/contrib/mw-to-git/GitMediawiki.pm b/contrib/mw-to-git/GitMediawiki.pm\nindex 8a0ffc7..beae6d0 100644\n--- a/contrib/mw-to-git/GitMediawiki.pm\n+++ b/contrib/mw-to-git/GitMediawiki.pm\n@@ -18,7 +18,82 @@ require Exporter;\n @EXPORT = ();\n \n # Methods which can be called as standalone functions as well:\n-@EXPORT_OK = ();\n+@EXPORT_OK = qw(clean_filename smudge_filename connect_maybe\n+\t\t\t\tEMPTY HTTP_CODE_OK);\n+}\n+\n+# Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced\n+use constant SLASH_REPLACEMENT => '%2F';\n+\n+# Used to test for empty strings\n+use constant EMPTY => q{};\n+\n+# HTTP codes\n+use constant HTTP_CODE_OK => 200;\n+\n+sub clean_filename {\n+\tmy $filename = shift;\n+\t$filename =~ s{@{[SLASH_REPLACEMENT]}}{/}g;\n+\t# [, ], |, {, and } are forbidden by MediaWiki, even URL-encoded.\n+\t# Do a variant of URL-encoding, i.e. looks like URL-encoding,\n+\t# but with _ added to prevent MediaWiki from thinking this is\n+\t# an actual special character.\n+\t$filename =~ s/[\\[\\]\\{\\}\\|]/sprintf(\"_%%_%x\", ord($&))/ge;\n+\t# If we use the uri escape before\n+\t# we should unescape here, before anything\n+\n+\treturn $filename;\n+}\n+\n+sub smudge_filename {\n+\tmy $filename = shift;\n+\t$filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;\n+\t$filename =~ s/ /_/g;\n+\t# Decode forbidden characters encoded in clean_filename\n+\t$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf('%c', hex($1))/ge;\n+\treturn $filename;\n+}\n+\n+sub connect_maybe {\n+\tmy $wiki = shift;\n+\tif ($wiki) {\n+\t\treturn $wiki;\n+\t}\n+\n+\tmy $remote_name = shift;\n+\tmy $remote_url = shift;\n+\tmy ($wiki_login, $wiki_password, $wiki_domain);\n+\n+\t$wiki_login = Git::config(\"remote.${remote_name}.mwLogin\");\n+\t$wiki_password = Git::config(\"remote.${remote_name}.mwPassword\");\n+\t$wiki_domain = Git::config(\"remote.${remote_name}.mwDomain\");\n+\n+\t$wiki = MediaWiki::API->new;\n+\t$wiki->{config}->{api_url} = \"${remote_url}/api.php\";\n+\tif ($wiki_login) {\n+\t\tmy %credential = (\n+\t\t\t'url' => $remote_url,\n+\t\t\t'username' => $wiki_login,\n+\t\t\t'password' => $wiki_password\n+\t\t);\n+\t\tGit::credential(\\%credential);\n+\t\tmy $request = {lgname => $credential{username},\n+\t\t\t       lgpassword => $credential{password},\n+\t\t\t       lgdomain => $wiki_domain};\n+\t\tif ($wiki->login($request)) {\n+\t\t\tGit::credential(\\%credential, 'approve');\n+\t\t\tprint {*STDERR} qq(Logged in mediawiki user \"$credential{username}\".\\n);\n+\t\t} else {\n+\t\t\tprint {*STDERR} qq(Failed to log in mediawiki user \"$credential{username}\" on ${remote_url}\\n);\n+\t\t\tprint {*STDERR} '  (error ' .\n+\t\t\t\t$wiki->{error}->{code} . ': ' .\n+\t\t\t\t$wiki->{error}->{details} . \")\\n\";\n+\t\t\tGit::credential(\\%credential, 'reject');\n+\t\t\texit 1;\n+\t\t}\n+\t}\n+\n+\treturn $wiki;\n }\n \n 1; # Famous last words\n\\ No newline at end of file\ndiff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl\nindex 9ff45fd..3b6422b 100755\n--- a/contrib/mw-to-git/git-remote-mediawiki.perl\n+++ b/contrib/mw-to-git/git-remote-mediawiki.perl\n@@ -14,6 +14,8 @@\n use strict;\n use MediaWiki::API;\n use Git;\n+use GitMediawiki qw(clean_filename smudge_filename connect_maybe\n+\t\t\t\t\tEMPTY HTTP_CODE_OK);\n use DateTime::Format::ISO8601;\n use warnings;\n \n@@ -23,9 +25,6 @@ binmode STDOUT, ':encoding(UTF-8)';\n \n use URI::Escape;\n \n-# Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced\n-use constant SLASH_REPLACEMENT => '%2F';\n-\n # It's not always possible to delete pages (may require some\n # privileges). Deleted pages are replaced with this content.\n use constant DELETED_CONTENT => \"[[Category:Deleted]]\\n\";\n@@ -40,8 +39,6 @@ use constant NULL_SHA1 => '0000000000000000000000000000000000000000';\n # Used on Git's side to reflect empty edit messages on the wiki\n use constant EMPTY_MESSAGE => '*Empty MediaWiki Message*';\n \n-use constant EMPTY => q{};\n-\n # Number of pages taken into account at once in submodule get_mw_page_list\n use constant SLICE_SIZE => 50;\n \n@@ -50,8 +47,6 @@ use constant SLICE_SIZE => 50;\n # the number of links to be returned (500 links max).\n use constant BATCH_SIZE => 10;\n \n-use constant HTTP_CODE_OK => 200;\n-\n my $remotename = $ARGV[0];\n my $url = $ARGV[1];\n \n@@ -184,37 +179,6 @@ sub parse_command {\n # MediaWiki API instance, created lazily.\n my $mediawiki;\n \n-sub mw_connect_maybe {\n-\tif ($mediawiki) {\n-\t\treturn;\n-\t}\n-\t$mediawiki = MediaWiki::API->new;\n-\t$mediawiki->{config}->{api_url} = \"${url}/api.php\";\n-\tif ($wiki_login) {\n-\t\tmy %credential = (\n-\t\t\t'url' => $url,\n-\t\t\t'username' => $wiki_login,\n-\t\t\t'password' => $wiki_passwd\n-\t\t);\n-\t\tGit::credential(\\%credential);\n-\t\tmy $request = {lgname => $credential{username},\n-\t\t\t       lgpassword => $credential{password},\n-\t\t\t       lgdomain => $wiki_domain};\n-\t\tif ($mediawiki->login($request)) {\n-\t\t\tGit::credential(\\%credential, 'approve');\n-\t\t\tprint {*STDERR} qq(Logged in mediawiki user \"$credential{username}\".\\n);\n-\t\t} else {\n-\t\t\tprint {*STDERR} qq(Failed to log in mediawiki user \"$credential{username}\" on ${url}\\n);\n-\t\t\tprint {*STDERR} '  (error ' .\n-\t\t\t\t$mediawiki->{error}->{code} . ': ' .\n-\t\t\t\t$mediawiki->{error}->{details} . \")\\n\";\n-\t\t\tGit::credential(\\%credential, 'reject');\n-\t\t\texit 1;\n-\t\t}\n-\t}\n-\treturn;\n-}\n-\n sub fatal_mw_error {\n \tmy $action = shift;\n \tprint STDERR \"fatal: could not $action.\\n\";\n@@ -324,7 +288,7 @@ sub get_mw_first_pages {\n \n # Get the list of pages to be fetched according to configuration.\n sub get_mw_pages {\n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \tprint {*STDERR} \"Listing pages on remote wiki...\\n\";\n \n@@ -514,7 +478,7 @@ sub get_last_local_revision {\n # avoid a loop onto all tracked pages. This is useful for the fetch-by-rev\n # option.\n sub get_last_global_remote_rev {\n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \tmy $query = {\n \t\taction => 'query',\n@@ -530,7 +494,7 @@ sub get_last_global_remote_rev {\n # Get the last remote revision concerning the tracked pages and the tracked\n # categories.\n sub get_last_remote_revision {\n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \tmy %pages_hash = get_mw_pages();\n \tmy @pages = values(%pages_hash);\n@@ -586,29 +550,6 @@ sub mediawiki_smudge {\n \treturn \"${string}\\n\";\n }\n \n-sub mediawiki_clean_filename {\n-\tmy $filename = shift;\n-\t$filename =~ s{@{[SLASH_REPLACEMENT]}}{/}g;\n-\t# [, ], |, {, and } are forbidden by MediaWiki, even URL-encoded.\n-\t# Do a variant of URL-encoding, i.e. looks like URL-encoding,\n-\t# but with _ added to prevent MediaWiki from thinking this is\n-\t# an actual special character.\n-\t$filename =~ s/[\\[\\]\\{\\}\\|]/sprintf(\"_%%_%x\", ord($&))/ge;\n-\t# If we use the uri escape before\n-\t# we should unescape here, before anything\n-\n-\treturn $filename;\n-}\n-\n-sub mediawiki_smudge_filename {\n-\tmy $filename = shift;\n-\t$filename =~ s{/}{@{[SLASH_REPLACEMENT]}}g;\n-\t$filename =~ s/ /_/g;\n-\t# Decode forbidden characters encoded in mediawiki_clean_filename\n-\t$filename =~ s/_%_([0-9a-fA-F][0-9a-fA-F])/sprintf('%c', hex($1))/ge;\n-\treturn $filename;\n-}\n-\n sub literal_data {\n \tmy ($content) = @_;\n \tprint {*STDOUT} 'data ', bytes::length($content), \"\\n\", $content;\n@@ -816,7 +757,7 @@ sub mw_import_ref {\n \t\treturn;\n \t}\n \n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \tprint {*STDERR} \"Searching revisions...\\n\";\n \tmy $last_local = get_last_local_revision();\n@@ -930,7 +871,7 @@ sub mw_import_revids {\n \t\tmy %commit;\n \t\t$commit{author} = $rev->{user} || 'Anonymous';\n \t\t$commit{comment} = $rev->{comment} || EMPTY_MESSAGE;\n-\t\t$commit{title} = mediawiki_smudge_filename($page_title);\n+\t\t$commit{title} = smudge_filename($page_title);\n \t\t$commit{mw_revision} = $rev->{revid};\n \t\t$commit{content} = mediawiki_smudge($rev->{'*'});\n \n@@ -991,7 +932,7 @@ sub mw_upload_file {\n \t}\n \t# Deleting and uploading a file requires a priviledged user\n \tif ($file_deleted) {\n-\t\tmw_connect_maybe();\n+\t\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \t\tmy $query = {\n \t\t\taction => 'delete',\n \t\t\ttitle => $path,\n@@ -1007,7 +948,7 @@ sub mw_upload_file {\n \t\t# Don't let perl try to interpret file content as UTF-8 => use \"raw\"\n \t\tmy $content = run_git(\"cat-file blob ${new_sha1}\", 'raw');\n \t\tif ($content ne EMPTY) {\n-\t\t\tmw_connect_maybe();\n+\t\t\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \t\t\t$mediawiki->{config}->{upload_url} =\n \t\t\t\t\"${url}/index.php/Special:Upload\";\n \t\t\t$mediawiki->edit({\n@@ -1055,7 +996,7 @@ sub mw_push_file {\n \tmy $old_sha1 = $diff_info_split[2];\n \tmy $page_created = ($old_sha1 eq NULL_SHA1);\n \tmy $page_deleted = ($new_sha1 eq NULL_SHA1);\n-\t$complete_file_name = mediawiki_clean_filename($complete_file_name);\n+\t$complete_file_name = clean_filename($complete_file_name);\n \n \tmy ($title, $extension) = $complete_file_name =~ /^(.*)\\.([^\\.]*)$/;\n \tif (!defined($extension)) {\n@@ -1078,7 +1019,7 @@ sub mw_push_file {\n \t\t\t$file_content = run_git(\"cat-file blob ${new_sha1}\");\n \t\t}\n \n-\t\tmw_connect_maybe();\n+\t\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \t\tmy $result = $mediawiki->edit( {\n \t\t\taction => 'edit',\n@@ -1264,7 +1205,7 @@ sub mw_push_revision {\n }\n \n sub get_allowed_file_extensions {\n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \n \tmy $query = {\n \t\taction => 'query',\n@@ -1288,7 +1229,7 @@ my %cached_mw_namespace_id;\n # Return MediaWiki id for a canonical namespace name.\n # Ex.: \"File\", \"Project\".\n sub get_mw_namespace_id {\n-\tmw_connect_maybe();\n+\t$mediawiki = connect_maybe($mediawiki, $remotename, $url);\n \tmy $name = shift;\n \n \tif (!exists $namespace_id{$name}) {\n-- \n1.8.3.GIT\n"},{"id":"220975","messageId":"1371349893-7789-4-git-send-email-benoit.person@ensimag.fr","threadId":"34160","inReplyTo":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","subject":"[PATCH V3 3/4] git-mw: Adding git-mw command","fromName":"","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T02:31:32Z","receivedAt":"2013-06-16T02:31:32Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"From: Benoit Person <benoit.person@ensimag.fr>\n\nAdd the new git-mw command, with its 'help' subcommand as an example. Argument\nparsing and subcommand choice is based on git-svn.perl.\nUpdate Makefile to build, install and clean both scripts now (git-mw.perl and\ngit-remote-mediawiki.perl).\n\nSigned-off-by: Benoit Person <benoit.person@ensimag.fr>\nSigned-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>\n\n---\n\nchanges from V2:\n  - Perlcritic changes: \n    - Update for loops style to a more perlish one.\n    - All 'print's specify their output streams.\n\n contrib/mw-to-git/Makefile    |  7 ++++---\n contrib/mw-to-git/git-mw.perl | 46 +++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+), 3 deletions(-)\n create mode 100644 contrib/mw-to-git/git-mw.perl\n\ndiff --git a/contrib/mw-to-git/Makefile b/contrib/mw-to-git/Makefile\nindex b0c7cf2..fe02c7e 100644\n--- a/contrib/mw-to-git/Makefile\n+++ b/contrib/mw-to-git/Makefile\n@@ -6,6 +6,7 @@\n \n GIT_MEDIAWIKI_PM=GitMediawiki.pm\n SCRIPT_PERL=git-remote-mediawiki.perl\n+SCRIPT_PERL+=git-mw.perl\n GIT_ROOT_DIR=../..\n HERE=contrib/mw-to-git/\n \n@@ -22,15 +23,15 @@ install_pm:\n \tcp $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)\n \n build: copy_pm\n-\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n+\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=\"$(SCRIPT_PERL_FULL)\" \\\n                 build-perl-script\n \n install: install_pm\n-\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n+\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=\"$(SCRIPT_PERL_FULL)\" \\\n                 install-perl-script\n \n clean:\n-\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \\\n+\t$(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=\"$(SCRIPT_PERL_FULL)\" \\\n                 clean-perl-script\n \trm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM) \\\n        $(GIT_ROOT_DIR)/perl/blib/lib/$(GIT_MEDIAWIKI_PM)\ndiff --git a/contrib/mw-to-git/git-mw.perl b/contrib/mw-to-git/git-mw.perl\nnew file mode 100644\nindex 0000000..320c00e\n--- /dev/null\n+++ b/contrib/mw-to-git/git-mw.perl\n@@ -0,0 +1,46 @@\n+#!/usr/bin/perl\n+\n+# Copyright (C) 2013\n+#     Benoit Person <benoit.person@ensimag.imag.fr>\n+#     Celestin Matte <celestin.matte@ensimag.imag.fr>\n+# License: GPL v2 or later\n+\n+# Set of tools for git repo with a mediawiki remote.\n+# Documentation & bugtracker: https://github.com/moy/Git-Mediawiki/\n+\n+use strict;\n+use warnings;\n+\n+use Getopt::Long;\n+\n+my %commands = (\n+\t'help' =>\n+\t\t[\\&help, {}, \\&help]\n+);\n+\n+# Search for sub-command\n+my $cmd = $commands{'help'};\n+for (0..@ARGV) {\n+\tif (defined $commands{$ARGV[$_]}) {\n+\t\t$cmd = $commands{$ARGV[$_]};\n+\t\tsplice @ARGV, $_, 1;\n+\t\tlast;\n+\t}\n+};\n+GetOptions( %{$cmd->[1]},\n+\t'help|h' => \\&{$cmd->[2]});\n+\n+# Launch command\n+&{$cmd->[0]};\n+\n+############################## Help Functions ##################################\n+\n+sub help {\n+\tprint {*STDOUT} <<'END';\n+usage: git mw <command> <args>\n+\n+git mw commands are:\n+    help        Display help information about git mw\n+END\n+\texit;\n+}\n\\ No newline at end of file\n-- \n1.8.3.GIT\n"},{"id":"220977","messageId":"1371349893-7789-5-git-send-email-benoit.person@ensimag.fr","threadId":"34160","inReplyTo":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","subject":"[PATCH V3 4/4] git-mw: Add preview subcommand into git mw.","fromName":"","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T02:31:33Z","receivedAt":"2013-06-16T02:31:33Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"From: Benoit Person <benoit.person@ensimag.fr>\n\nAdd the subcommand to 'git-mw.perl'.\nAdd a new constant in GitMediawiki.pm 'HTTP_CODE_PAGE_NOT_FOUND'.\n\nSigned-off-by: Benoit Person <benoit.person@ensimag.fr>\nSigned-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>\n\n---\n\nchanges from V2:\n  - Remove the --blob option, distinction between files and blobs is now \n    automatic.\n  - Add a --verbose option to output more information on what's going on.\n  - Rewrote the doc and the commit message.\n  - Rewrote of the template retrieving code (see 'get_template' sub).\n  - Use a configuration variable to define the content ID search in the\n    template. Default value set as 'bodyContent' since it seems more standard\n    than 'mw-content-text'.\n  - Final content is now saved as utf-8 to solve encoding issues.\n  - Perlcritic changes:\n    - All 'print's specify their output streams.\n    --> Same useless warnings left in git-remote-mediawiki.perl after célestin's \n        work and git-mw.perl after this patch :) .\n\n contrib/mw-to-git/GitMediawiki.pm |   3 +-\n contrib/mw-to-git/git-mw.perl     | 303 +++++++++++++++++++++++++++++++++++++-\n 2 files changed, 304 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/mw-to-git/GitMediawiki.pm b/contrib/mw-to-git/GitMediawiki.pm\nindex beae6d0..d1f2c41 100644\n--- a/contrib/mw-to-git/GitMediawiki.pm\n+++ b/contrib/mw-to-git/GitMediawiki.pm\n@@ -19,7 +19,7 @@ require Exporter;\n \n # Methods which can be called as standalone functions as well:\n @EXPORT_OK = qw(clean_filename smudge_filename connect_maybe\n-\t\t\t\tEMPTY HTTP_CODE_OK);\n+\t\t\t\tEMPTY HTTP_CODE_OK HTTP_CODE_PAGE_NOT_FOUND);\n }\n \n # Mediawiki filenames can contain forward slashes. This variable decides by which pattern they should be replaced\n@@ -30,6 +30,7 @@ use constant EMPTY => q{};\n \n # HTTP codes\n use constant HTTP_CODE_OK => 200;\n+use constant HTTP_CODE_PAGE_NOT_FOUND => 404;\n \n sub clean_filename {\n \tmy $filename = shift;\ndiff --git a/contrib/mw-to-git/git-mw.perl b/contrib/mw-to-git/git-mw.perl\nindex 320c00e..0b83108 100644\n--- a/contrib/mw-to-git/git-mw.perl\n+++ b/contrib/mw-to-git/git-mw.perl\n@@ -12,10 +12,41 @@ use strict;\n use warnings;\n \n use Getopt::Long;\n+use URI::URL qw(url);\n+use LWP::UserAgent;\n+use HTML::TreeBuilder;\n+\n+use Git;\n+use MediaWiki::API;\n+use GitMediawiki qw(smudge_filename connect_maybe\n+\t\t\t\t\tEMPTY HTTP_CODE_PAGE_NOT_FOUND);\n+\n+# By default, use UTF-8 to communicate with Git and the user\n+binmode STDERR, ':encoding(UTF-8)';\n+binmode STDOUT, ':encoding(UTF-8)';\n+\n+#preview parameters\n+my $file_name = EMPTY;\n+my $remote_name = EMPTY;\n+my $preview_file_name = EMPTY;\n+my $autoload = 0;\n+my $verbose = 0;\n+sub file {\n+\t$file_name = shift;\n+\treturn $file_name;\n+}\n \n my %commands = (\n \t'help' =>\n-\t\t[\\&help, {}, \\&help]\n+\t\t[\\&help, {}, \\&help],\n+\t'preview' =>\n+\t\t[\\&preview, {\n+\t\t\t'<>' => \\&file,\n+\t\t\t'output|o=s' => \\$preview_file_name,\n+\t\t\t'remote|r=s' => \\$remote_name,\n+\t\t\t'autoload|a' => \\$autoload,\n+\t\t\t'verbose|v'  => \\$verbose\n+\t\t}, \\&preview_help]\n );\n \n # Search for sub-command\n@@ -33,6 +64,275 @@ GetOptions( %{$cmd->[1]},\n # Launch command\n &{$cmd->[0]};\n \n+############################# Preview Functions ################################\n+\n+# @TODO : add documentation for verbose option\n+sub preview_help {\n+\tprint {*STDOUT} <<'END';\n+USAGE: git mw preview [--remote|-r <remote name>] [--autoload|-a]\n+                      [--output|-o <output filename>] [--verbose|-v]\n+                      <blob> | <filename>\n+\n+DESCRIPTION:\n+Preview is an utiliy to preview local content of a mediawiki repo as if it was\n+pushed on the remote.\n+\n+For that, preview searches for the remote name of the current branch's upstream\n+if --remote is not set. If that remote is not found or if it is not a mediawiki,\n+it lists all mediawiki remotes configured and asks you to replay your command\n+with the --remote option set properly.\n+\n+Then, it searches for a file named 'filename'. If it's not found in the current\n+dir, it will assume it's a blob.\n+\n+The content retrieved in the file (or in the blob) will then be parsed by the\n+distant mediawiki and combined with a template retrieved from the mediawiki.\n+\n+Finally, preview will save the HTML result in a file. and autoload it in your\n+default web browser if the option --autoload is present.\n+\n+OPTIONS:\n+\t-r <remote name>, --remote <remote name>\n+\t\tIf the remote is a mediawiki, the template and the parse engine used for\n+\t\tthe preview will be those of that remote.\n+\t\tIf not, a list of valid remotes will be shown.\n+\n+\t-a, --autoload\n+\t\tTry to load the HTML output in a new tab (or new window) of your default\n+\t\tweb browser.\n+\n+\t-o <output filename>, --output <output filename>\n+\t\tChange the HTML output filename. Default filename is based on the input\n+\t\tfilename with its extension replaced by '.html'.\n+\n+\t-v, --verbose\n+\t\tShow more information on what's going on under the hood.\n+END\n+\texit;\n+}\n+\n+sub preview {\n+\tmy $wiki;\n+\tmy ($remote_url, $wiki_page_name);\n+\tmy ($content, $content_tree, $template, $html_tree, $mw_content_text);\n+\tmy $file_content;\n+\tmy $template_content_id = 'bodyContent';\n+\n+\t# file_name argumeent is mandatory\n+\tif (!defined $file_name) {\n+\t\tdie \"File not set, see `git mw help` \\n\";\n+\t}\n+\n+\tv_print(\"### SELECTING REMOTE ###\\n\");\n+\n+\tif ($remote_name eq EMPTY) {\n+\t\t# Search current branch upstream branch remote\n+\t\tmy $current_branch = git_cmd_try {\n+\t\t\tGit::command_oneline('symbolic-ref', '--short', 'HEAD') }\n+\t\t\t\"%s failed w/ code %d\";\n+\t\t$remote_name = Git::config(\"branch.${current_branch}.remote\");\n+\n+\t\tif ($remote_name) {\n+\t\t\t$remote_url = mediawiki_remote_url_maybe($remote_name);\n+\t\t}\n+\n+\t\t# Search all possibles mediawiki remotes\n+\t\tif (! $remote_url) {\n+\t\t\tmy @remotes = git_cmd_try {\n+\t\t\t\tGit::command('remote'); }\n+\t\t\t\t\"%s failed w/ code %d\";\n+\n+\t\t\tmy @valid_remotes = ();\n+\t\t\tforeach my $remote (@remotes) {\n+\t\t\t\t$remote_url = mediawiki_remote_url_maybe($remote);\n+\t\t\t\tif ($remote_url) {\n+\t\t\t\t\tpush(@valid_remotes, $remote);\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\tif ($#valid_remotes == 0) {\n+\t\t\t\tprint {*STDERR} \"Can not find any mediawiki remote in this repo. \\n\";\n+\t\t\t\texit 1;\n+\t\t\t} else {\n+\t\t\t\tprint {*STDERR} \"There are multiple mediawiki remotes, which of:\\n\";\n+\t\t\t\tforeach my $remote (@remotes) {\n+\t\t\t\t\tprint {*STDERR} \"\\t${remote}\\n\";\n+\t\t\t\t}\n+\t\t\t\tprint {*STDERR} \"do you want ? Use the -r option to specify the remote\\n\";\n+\t\t\t}\n+\n+\t\t\texit 0;\n+\t\t}\n+\t} else {\n+\t\t# Check remote name\n+\t\tmy @remotes = git_cmd_try {\n+\t\t\tGit::command('remote') }\n+\t\t\t\"%s failed w/ code %d\";\n+\t\tmy $found_remote = 0;\n+\t\tforeach my $remote (@remotes) {\n+\t\t\tif ($remote eq $remote_name) {\n+\t\t\t\t$found_remote = 1;\n+\t\t\t\tlast;\n+\t\t\t}\n+\t\t}\n+\t\tif (!$found_remote) {\n+\t\t\tdie \"${remote_name} is not a remote\\n\";\n+\t\t}\n+\n+\t\t# Find remote url\n+\t\t$remote_url = mediawiki_remote_url_maybe($remote_name);\n+\t\tif (! $remote_url) {\n+\t\t\tdie \"the remote you selected is not a mediawiki remote\\n\";\n+\t\t}\n+\t}\n+\tv_print(\"selected remote:\\n\\tname: ${remote_name}\\n\\turl: ${remote_url}\\n\");\n+\n+\t# Create and connect to the wiki if necessary\n+\t$wiki = connect_maybe($wiki, $remote_name, $remote_url);\n+\n+\t# Read file content\n+\tif (! -e $file_name) {\n+\t\t$file_content = git_cmd_try {\n+\t\t\tGit::command('cat-file', 'blob', $file_name); }\n+\t\t\t\"%s failed w/ code %d\";\n+\n+\t\tif ($file_name =~ /(.+):(.+)/) {\n+\t\t\t$file_name = $2;\n+\t\t}\n+\t} else {\n+\t\topen my $read_fh, \"<\", $file_name\n+\t\t\tor die \"could not open ${file_name}: $!\\n\";\n+\t\t$file_content = do { local $/ = undef; <$read_fh> };\n+\t\tclose $read_fh\n+\t\t\tor die \"unable to close: $!\\n\";\n+\t}\n+\n+\t# Transform file_name into a mediawiki page name\n+\t$wiki_page_name = smudge_filename($file_name);\n+\t$wiki_page_name =~ s/\\.[^.]+$//;\n+\n+\t# Default preview_file_name is file_name with .html ext\n+\tif ($preview_file_name eq EMPTY) {\n+\t\t$preview_file_name = $file_name;\n+\t\t$preview_file_name =~ s/\\.[^.]+$/.html/;\n+\t}\n+\n+\tv_print(\"### Retrieving template\\n\");\n+\t$template = get_template($remote_url, $wiki_page_name);\n+\n+\tv_print(\"### Parsing & merging contents\\n\");\n+\t# Parsing template page\n+\t$html_tree = HTML::TreeBuilder->new;\n+\t$html_tree->parse($template);\n+\n+\t# Load new content\n+\t$content = $wiki->api({\n+\t\taction => 'parse',\n+\t\ttext => $file_content,\n+\t\ttitle => $wiki_page_name\n+\t}, {\n+\t\tskip_encoding => 1\n+\t}) or die \"No response from distant mediawiki\\n\";\n+\t$content = $content->{'parse'}->{'text'}->{'*'};\n+\t$content_tree = HTML::TreeBuilder->new;\n+\t$content_tree->parse($content);\n+\n+\t# Replace old content with new one\n+\t$template_content_id = Git::config('mediawiki.IDContent')\n+\t\t|| $template_content_id;\n+\tv_print(\"Using '${template_content_id}' as the content ID\\n\");\n+\t$mw_content_text = $html_tree->look_down('id', $template_content_id);\n+\tif (!defined $mw_content_text) {\n+\t\tprint {*STDERR} <<\"CONFIG\";\n+Could not combine the new parsed content with the template. You might want to\n+configure `mediawiki.IDContent` in your config:\n+\tgit config --add mediawiki.IDContent <your_template_content_element_id>\n+CONFIG\n+\t}\n+\t$mw_content_text->delete_content();\n+\t$mw_content_text->push_content($content_tree);\n+\n+\t# Transform relative links into absolute ones\n+\tfor (@{ $html_tree->extract_links() }) {\n+\t\tmy ($link, $element, $attr) = @{ $_ };\n+\t\tmy $url = url($link)->canonical;\n+\t\t$element->attr($attr, URI->new_abs($url, $remote_url));\n+\t}\n+\n+\t# Save the preview file\n+\topen(my $save_fh, '>:encoding(UTF-8)', $preview_file_name)\n+\t\tor die \"Could not open: $!\\n\";\n+\tprint {$save_fh} $html_tree->as_HTML;\n+\tclose($save_fh)\n+\t\tor die \"Could not close: $!\\n\";\n+\n+\t# Auto-loading in browser\n+\tv_print(\"### Results\\n\");\n+\tif ($autoload) {\n+\t\tv_print(\"Launching browser w/ file: ${preview_file_name}\");\n+\t\tsystem('git', 'web--browse', $preview_file_name);\n+\t} else {\n+\t\tprint {*STDERR} \"Preview file saved as: ${preview_file_name}\\n\";\n+\t}\n+\n+\texit;\n+}\n+\n+sub mediawiki_remote_url_maybe {\n+\tmy $remote = shift;\n+\n+\t# Find remote url\n+\tmy $remote_url = Git::config(\"remote.${remote}.url\");\n+\tif ($remote_url =~ s/mediawiki::(.*)/$1/) {\n+\t\treturn url($remote_url)->canonical;\n+\t}\n+\n+\treturn;\n+}\n+\n+sub get_template {\n+\tmy $url = shift;\n+\tmy $page_name = shift;\n+\tmy ($req, $res, $code, $url_after);\n+\n+\t$req = LWP::UserAgent->new;\n+\tif ($verbose) {\n+\t\t$req->show_progress(1);\n+\t}\n+\n+\t$res = $req->get(\"${url}/index.php?title=${page_name}\");\n+\tif (!$res->is_success) {\n+\t\t$code = $res->code;\n+\t\t$url_after = $res->request()->uri(); # resolve all redirections\n+\t\tif ($code == HTTP_CODE_PAGE_NOT_FOUND) {\n+\t\t\tif ($verbose) {\n+\t\t\t\tprint {*STDERR} <<\"WARNING\";\n+Warning: Failed to retrieve '$page_name'. Create it on the mediawiki if you want\n+all the links to work properly.\n+Trying to use the mediawiki homepage as a fallback template ...\n+WARNING\n+\t\t\t}\n+\n+\t\t\t# LWP automatically redirects GET request\n+\t\t\t$res = $req->get(\"${url}/index.php\");\n+\t\t\tif (!$res->is_success) {\n+\t\t\t\t$url_after = $res->request()->uri(); # resolve all redirections\n+\t\t\t\tdie \"Failed to get homepage @ ${url_after} w/ code ${code}\\n\";\n+\t\t\t}\n+\t\t} else {\n+\t\t\tdie \"Failed to get '${page_name}' @ ${url_after} w/ code ${code}\\n\";\n+\t\t}\n+\t}\n+\n+\treturn $res->decoded_content;\n+}\n+\n+sub v_print {\n+\tif ($verbose) {\n+\t\tprint {*STDERR} @_;\n+\t}\n+}\n+\n ############################## Help Functions ##################################\n \n sub help {\n@@ -41,6 +341,7 @@ usage: git mw <command> <args>\n \n git mw commands are:\n     help        Display help information about git mw\n+    preview \tParse and render local file into HTML\n END\n \texit;\n }\n\\ No newline at end of file\n-- \n1.8.3.GIT\n"},{"id":"220993","messageId":"CALkWK0mrmcDP6JpHwzLdE7Vbp=YtpBpJ47u-py+BgZVeac3o1g@mail.gmail.com","threadId":"34160","inReplyTo":"1371349893-7789-1-git-send-email-benoit.person@ensimag.fr","subject":"Re: [PATCH V3 0/4] git-remote-mediawiki: new tool to preview local changes without pushing","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-06-16T09:00:37Z","receivedAt":"2013-06-16T09:00:37Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"<benoit.person@ensimag.fr> wrote:\n> Subject: [PATCH V3 0/4] git-remote-mediawiki: new tool to preview local changes without pushing\n\nQuick tip: use git format-patch -v3.  The uppercase 'V' indicates that\nyou probably typed it out yourself, or used --subject-prefix=\"PATCH\nV3\".\n"},{"id":"221015","messageId":"vpqobb5g679.fsf@anie.imag.fr","threadId":"34160","inReplyTo":"1371349893-7789-2-git-send-email-benoit.person@ensimag.fr","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-16T20:18:34Z","receivedAt":"2013-06-16T20:18:34Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"benoit.person@ensimag.fr writes:\n\n> changes from the V2:\n>   - Add a way to test, without installation, code that uses GitMediawiki.pm.\n\nThis still needs to be documented, even very quickly, somewhere in the\ncode (e.g a comment in the Makefile).\n\n> -build install clean:\n> +copy_pm:\n> +\tcp $(GIT_MEDIAWIKI_PM) $(GIT_ROOT_DIR)/perl/blib/lib/\n\nI already commented on this:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/227711/focus=227721\n\nAlso, it seems to be only part of the solution. With your change, from\ncontrib/mw-to-git/ and after running only \"make\",\n\n./git-mw takes the installed version of GitMediawiki.pm in priority\n\n../../bin-wrappers/git takes the installed version of git-mw only (i.e.\ndoes not know \"git mw\" if \"make install\" hasn't been ran).\n\n>  perlcritic:\n> -\tperlcritic -2 *.perl\n> +\tperlcritic -2 *.perl\n> \\ No newline at end of file\n\nPlease, avoid these whitespace-only changes. They create noise during\nreview, and more potential conflicts.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"221018","messageId":"vpqr4g1eqnd.fsf@anie.imag.fr","threadId":"34160","inReplyTo":"1371349893-7789-5-git-send-email-benoit.person@ensimag.fr","subject":"Re: [PATCH V3 4/4] git-mw: Add preview subcommand into git mw.","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-16T20:39:50Z","receivedAt":"2013-06-16T20:39:50Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"[ Just a quick look, no time for a detailed review ]\n\nbenoit.person@ensimag.fr writes:\n\n> From: Benoit Person <benoit.person@ensimag.fr>\n>\n> Add the subcommand to 'git-mw.perl'.\n\nThat's already said in the Subject field.\n\n> Add a new constant in GitMediawiki.pm 'HTTP_CODE_PAGE_NOT_FOUND'.\n\nAnd this brings zero information compared to\n\n> --- a/contrib/mw-to-git/GitMediawiki.pm\n> +++ b/contrib/mw-to-git/GitMediawiki.pm\n> -\t\t\t\tEMPTY HTTP_CODE_OK);\n> +\t\t\t\tEMPTY HTTP_CODE_OK HTTP_CODE_PAGE_NOT_FOUND);\n\nI'd say your commit messages looks like a GNU-style changelog entry,\nwhich I do not consider a compliment ;-).\n\nStill, after removing rendundant information, you may notice that the\nreader has no idea what \"preview\" is or does, and *why* it is a good\nthing to have it. How about:\n\n\"\nIn the current state, a user of git-remote-mediawiki can edit the markup\ntext locally, but has to push to the remote wiki to see how the page is\nrendered. Add a new \"git mw preview\" command that allows rendering the\nmarkup text on the remote wiki without actually doing any change on the\nwiki.\n\nThis uses MediaWiki's API to render the markup, and inserts the result\nin an actual HTML page from the wiki so that CSS be rendered properly.\n\"\n\n?\n\n(The first paragraph answers \"*why* did you do this?\" and the second\n\"*why* did you do it this way?\")\n\n(did I put enough emphasis on the \"why\"? ;-) )\n\n> +\t# file_name argumeent is mandatory\n\nargumeent -> argument\n\n> +\tif (!defined $file_name) {\n> +\t\tdie \"File not set, see `git mw help` \\n\";\n\nPerhaps \"missing file argument\"?\n\n> +\t\t# Search all possibles mediawiki remotes\n> +\t\tif (! $remote_url) {\n\nThe \"why\" thing about commit message also applies to comments: when you\nstart saying what you're doing in a comment, it usually means your code\nshould be refactored.\n\nWouldn't it better to add a function here? The name of the function\nwould probably carry the same information as the comment.\n\n> +\t\t\t\tprint {*STDERR} \"do you want ? Use the -r option to specify the remote\\n\";\n\nMissing period (.).\n\n> +\t}) or die \"No response from distant mediawiki\\n\";\n\ndistant -> remote.\n\n> +\t$template_content_id = Git::config('mediawiki.IDContent')\n> +\t\t|| $template_content_id;\n\nIt would be cool to have also remote.<name>.IDContent or something like\nthis in case you have several remotes with different div ids. But this\ncan be added later.\n\n> @@ -41,6 +341,7 @@ usage: git mw <command> <args>\n>  \n>  git mw commands are:\n>      help        Display help information about git mw\n> +    preview \tParse and render local file into HTML\n\nSpace/tab mix after preview.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"221021","messageId":"CAETqRChcu+N-2uNzL9_J6abR5fnduT5UVRif5NTQYOoxPTiRTw@mail.gmail.com","threadId":"34160","inReplyTo":"vpqobb5g679.fsf@anie.imag.fr","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Benoît Person","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-16T23:41:22Z","receivedAt":"2013-06-16T23:41:22Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"On 16 June 2013 22:18, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n> benoit.person@ensimag.fr writes:\n>\n>> changes from the V2:\n>>   - Add a way to test, without installation, code that uses GitMediawiki.pm.\n>\n> This still needs to be documented, even very quickly, somewhere in the\n> code (e.g a comment in the Makefile).\nWell, I think I will have to re-read some docs (and some earlier\nreviews) about what to write in commit messages, in the emails, in the\ncode as comments and in the documentation ... I am just totally lost\nright now :/ .\n\n>> -build install clean:\n>> +copy_pm:\n>> +     cp $(GIT_MEDIAWIKI_PM) $(GIT_ROOT_DIR)/perl/blib/lib/\n>\n> I already commented on this:\n>\n> http://thread.gmane.org/gmane.comp.version-control.git/227711/focus=227721\nOops, I forgot that one, so sorry :/ .\n\n> Also, it seems to be only part of the solution. With your change, from\n> contrib/mw-to-git/ and after running only \"make\",\n>\n> ./git-mw takes the installed version of GitMediawiki.pm in priority\n>\n> ../../bin-wrappers/git takes the installed version of git-mw only (i.e.\n> does not know \"git mw\" if \"make install\" hasn't been ran).\nSame thing as the documentation point, I think I am a bit lost in that\nwhole thing. I will re-look into it for the next version :/ .\n\n>>  perlcritic:\n>> -     perlcritic -2 *.perl\n>> +     perlcritic -2 *.perl\n>> \\ No newline at end of file\n>\n> Please, avoid these whitespace-only changes. They create noise during\n> review, and more potential conflicts.\nFor that one, I don't know why git assumes there is a change in it :\nfrom what I see there is absolutely no whitespaces changes but maybe\nmy editor added some weird character somewhere ? I will look into that\nfor the next version ...\n\nThank you,\n\nBenoit Person\n"},{"id":"221037","messageId":"vpq8v299pn6.fsf@anie.imag.fr","threadId":"34160","inReplyTo":"CAETqRChcu+N-2uNzL9_J6abR5fnduT5UVRif5NTQYOoxPTiRTw@mail.gmail.com","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-17T07:12:45Z","receivedAt":"2013-06-17T07:12:45Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Benoît Person <benoit.person@ensimag.fr> writes:\n\n> On 16 June 2013 22:18, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n>> benoit.person@ensimag.fr writes:\n>>\n>>> changes from the V2:\n>>>   - Add a way to test, without installation, code that uses GitMediawiki.pm.\n>>\n>> This still needs to be documented, even very quickly, somewhere in the\n>> code (e.g a comment in the Makefile).\n> Well, I think I will have to re-read some docs (and some earlier\n> reviews) about what to write in commit messages, in the emails, in the\n> code as comments and in the documentation ... I am just totally lost\n> right now :/ .\n\nDon't worry, reviews are meant to improve your code (present and\nfuture), not to blame you ;-).\n\nJust think about what you expect as a user or developer. Would you run\n\"git log Makefile\" or \"git blame Makefile\" to know how to use the\nMakefile? Commit messages are primarily meant for reviewers (\"here's\nsome code, and here's why it's good and why you should merge it\"), and\ncan be very useful when bisecting a regression or blaming a source file.\n\nRight now, git-remote-mediawiki has only little doc, and the user manual\nis hosted on a GitHub wiki, not in the source. So there's no ideal place \nto say how to use the tool as a developer, but a comment in the Makefile\nshould be OK.\n\n>> Also, it seems to be only part of the solution. With your change, from\n>> contrib/mw-to-git/ and after running only \"make\",\n>>\n>> ./git-mw takes the installed version of GitMediawiki.pm in priority\n>>\n>> ../../bin-wrappers/git takes the installed version of git-mw only (i.e.\n>> does not know \"git mw\" if \"make install\" hasn't been ran).\n> Same thing as the documentation point, I think I am a bit lost in that\n> whole thing. I will re-look into it for the next version :/ .\n\nIn short, the include path should contain both the *.pm file and the\ngit-<foo> ones.\n\n>>>  perlcritic:\n>>> -     perlcritic -2 *.perl\n>>> +     perlcritic -2 *.perl\n>>> \\ No newline at end of file\n>>\n>> Please, avoid these whitespace-only changes. They create noise during\n>> review, and more potential conflicts.\n> For that one, I don't know why git assumes there is a change in it :\n\nI think you removed a newline from the end of the file. It's usually\nconsidered good practice to have this trailing newline (e.g. so that\n\"cat file\" in a terminal doesn't put your prompt after the last line).\nIIRC, it's actually required to call the file a \"text file\" according to\nPOSIX.\n\n> I will look into that for the next version ...\n\nIn any case, using \"git add -p\" and if needed its \"s\" command avoids\nintroducing unwanted things in the commit.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"221167","messageId":"CAETqRCjiMh_cYuZit5Z8OLki_RTz8=ViYPMv005iQu9Fv=U0ow@mail.gmail.com","threadId":"34160","inReplyTo":"vpq8v299pn6.fsf@anie.imag.fr","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Benoît Person","fromEmail":"benoit.person@ensimag.fr","sentAt":"2013-06-18T09:06:16Z","receivedAt":"2013-06-18T09:06:16Z","isPatch":true,"sender":{"key":"benoit.person@ensimag.fr","avatar":null},"body":"On 17 June 2013 09:12, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n>>> Also, it seems to be only part of the solution. With your change, from\n>>> contrib/mw-to-git/ and after running only \"make\",\n>>>\n>>> ./git-mw takes the installed version of GitMediawiki.pm in priority\n>>>\n>>> ../../bin-wrappers/git takes the installed version of git-mw only (i.e.\n>>> does not know \"git mw\" if \"make install\" hasn't been ran).\n>> Same thing as the documentation point, I think I am a bit lost in that\n>> whole thing. I will re-look into it for the next version :/ .\n>\n> In short, the include path should contain both the *.pm file and the\n> git-<foo> ones.\nThe fact is, for now, is there a way to test changes in\ngit-remote-mediawiki.perl without 'make install'-ing it ? I could not find one\n\nSo maybe in the \"build-perl-script\" of the toplevel Makefile we could add\nsomething copying the script at the toplevel ?\n\nAnd in GitMediawiki's Makefile, we let everything stay as is : copying *.pm\ninto /perl/blib/lib when building and copying it in installdir when installing ?\n\n> I think you removed a newline from the end of the file. It's usually\n> considered good practice to have this trailing newline (e.g. so that\n> \"cat file\" in a terminal doesn't put your prompt after the last line).\n> IIRC, it's actually required to call the file a \"text file\" according to\n> POSIX.\nThat catch oO, thanks for the explanations.\nFrom my point of view, this could definitely be improved from:\n> -     perlcritic -2 *.perl\n> +     perlcritic -2 *.perl\n> \\ No newline at end of file\nto something like that:\n> -     perlcritic -2 *.perl\n> +     perlcritic -2 *.perl\n> \\ removed newline at end of file\nwhich gives more insights into why the line is considered \"edited\".\n\nBenoit Person\n"},{"id":"221173","messageId":"vpqhagvu3u1.fsf@anie.imag.fr","threadId":"34160","inReplyTo":"CAETqRCjiMh_cYuZit5Z8OLki_RTz8=ViYPMv005iQu9Fv=U0ow@mail.gmail.com","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-18T10:10:30Z","receivedAt":"2013-06-18T10:10:30Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Benoît Person <benoit.person@ensimag.fr> writes:\n\n>>From my point of view, this could definitely be improved from:\n>> -     perlcritic -2 *.perl\n>> +     perlcritic -2 *.perl\n>> \\ No newline at end of file\n> to something like that:\n>> -     perlcritic -2 *.perl\n>> +     perlcritic -2 *.perl\n>> \\ removed newline at end of file\n> which gives more insights into why the line is considered \"edited\".\n\nToo late ;-). This is a diff/patch thing, and Git is compatible with\nthem.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"221182","messageId":"vpqa9mnu1s3.fsf@anie.imag.fr","threadId":"34160","inReplyTo":"CAETqRCjiMh_cYuZit5Z8OLki_RTz8=ViYPMv005iQu9Fv=U0ow@mail.gmail.com","subject":"Re: [PATCH V3 1/4] git-mw: Introduction of GitMediawiki.pm","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-06-18T10:54:52Z","receivedAt":"2013-06-18T10:54:52Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Benoît Person <benoit.person@ensimag.fr> writes:\n\n> On 17 June 2013 09:12, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:\n>>>> Also, it seems to be only part of the solution. With your change, from\n>>>> contrib/mw-to-git/ and after running only \"make\",\n>>>>\n>>>> ./git-mw takes the installed version of GitMediawiki.pm in priority\n>>>>\n>>>> ../../bin-wrappers/git takes the installed version of git-mw only (i.e.\n>>>> does not know \"git mw\" if \"make install\" hasn't been ran).\n>>> Same thing as the documentation point, I think I am a bit lost in that\n>>> whole thing. I will re-look into it for the next version :/ .\n>>\n>> In short, the include path should contain both the *.pm file and the\n>> git-<foo> ones.\n> The fact is, for now, is there a way to test changes in\n> git-remote-mediawiki.perl without 'make install'-ing it ? I could not find one\n\nYou can put contrib/mw-to-git/ in your $PATH, and then run git normally.\n\n> So maybe in the \"build-perl-script\" of the toplevel Makefile we could add\n> something copying the script at the toplevel ?\n\nI find this a bit dirty, as it polutes the toplevel with untracked files\n(that are not in the .gitignore file). But that's what the testsuite\nalready does (IIRC, it does a symlink), so I'd say it's OK for now.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}