git-remote-mediawiki: introduction of Git::Mediawiki.pm

We would want to allow the user to preview what he has edited locally before pushing it out (and thus creating a non-removable revision in the mediawiki's history). This patch introduces a new perl package in which we will be able to share code between that new tool and the remote helper: git-remote-mediawiki.perl. A perl package offers the best way to handle such case: Each script can select what should be imported in its namespace. The package namespacing limits the use of side effects in the shared code. An alternate solution is to concatenate a "toolset" file with each *.perl when 'make'-ing the project. In that scheme, everything is imported in the script's namespace. Plus, files should be renamed in order to chain to Git's toplevel makefile. Hence, this solution is not acceptable. Signed-off-by: Benoit Person <benoit.person@ensimag.fr> Signed-off-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Benoit Person committed Jul 4, 2013 at 22:38 UTC e19189060fcfb62410ce8e008720dbb6e7fa0d7b
2 files changed +45 -3
contrib/mw-to-git/Git/Mediawiki.pm new
+24
@@ -0,0 +1,24 @@
1 +package Git::Mediawiki;
2 +
3 +use 5.008;
4 +use strict;
5 +use Git;
6 +
7 +BEGIN {
8 +
9 +our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
10 +
11 +# Totally unstable API.
12 +$VERSION = '0.01';
13 +
14 +require Exporter;
15 +
16 +@ISA = qw(Exporter);
17 +
18 +@EXPORT = ();
19 +
20 +# Methods which can be called as standalone functions as well:
21 +@EXPORT_OK = ();
22 +}
23 +
24 +1; # Famous last words
contrib/mw-to-git/Makefile
+21 -3
@@ -2,18 +2,36 @@
2 # Copyright (C) 2013
3 # Matthieu Moy <Matthieu.Moy@imag.fr>
4 #
5 -## Build git-remote-mediawiki
5 +# To install, run Git's toplevel 'make install' then run:
6 +#
7 +# make install
8
9 +GIT_MEDIAWIKI_PM=Git/Mediawiki.pm
10 SCRIPT_PERL=git-remote-mediawiki.perl
11 GIT_ROOT_DIR=../..
12 HERE=contrib/mw-to-git/
13
14 SCRIPT_PERL_FULL=$(patsubst %,$(HERE)/%,$(SCRIPT_PERL))
15 +INSTLIBDIR=$(shell $(MAKE) -C $(GIT_ROOT_DIR)/perl \
16 + -s --no-print-directory instlibdir)
17
18 all: build
19
15 -build install clean:
20 +install_pm:
21 + install $(GIT_MEDIAWIKI_PM) $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
22 +
23 +build:
24 + $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
25 + build-perl-script
26 +
27 +install: install_pm
28 $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
17 - $@-perl-script
29 + install-perl-script
30 +
31 +clean:
32 + $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL=$(SCRIPT_PERL_FULL) \
33 + clean-perl-script
34 + rm $(INSTLIBDIR)/$(GIT_MEDIAWIKI_PM)
35 +
36 perlcritic:
37 perlcritic -2 *.perl