diff --git a/inc/salvatore_ecriveur.php b/inc/salvatore_ecriveur.php index efb0f2979859081d62c8920b42ca318bf38d825d..f458a551e68c9c2e3fa07704a30c579661882ddf 100644 --- a/inc/salvatore_ecriveur.php +++ b/inc/salvatore_ecriveur.php @@ -34,6 +34,9 @@ include_spip('inc/xml'); include_spip('inc/lang_liste'); include_spip('inc/session'); +include_spip('inc/salvatore_svn'); +include_spip('inc/salvatore_git'); + /** * @param array $liste_sources @@ -310,7 +313,7 @@ function salvatore_exporter_module($id_tradlang_module, $source, $url_site, $url if (count($commit_infos)) { $nb_to_commit = count($commit_infos); if ($message_commit) { - $commit_infos['message'] = $message_commit; + $commit_infos['.message'] = $message_commit; } file_put_contents($dir_module . '/' . $module . '.commit.json', json_encode($commit_infos)); } @@ -394,24 +397,9 @@ function salvatore_read_lastmodified_file($file_name, $source, $dir_depots) { if ($source['dir']) { $file_path_relative = $source['dir'] . DIRECTORY_SEPARATOR . $file_path_relative; } - $file_path = $dir_depots . $source['dir_checkout'] . DIRECTORY_SEPARATOR . $file_path_relative; - - $lastmodified = 0; - switch ($source['methode']) { - case 'git': - $d = getcwd(); - chdir($dir_depots . $source['dir_checkout']); - $lastmodified = exec("git log -1 -c --pretty=tformat:'%ct' $file_path_relative | head -1"); - $lastmodified = intval(trim($lastmodified)); - chdir($d); - break; - case 'svn': - $lastmodified = exec('env LC_MESSAGES=en_US.UTF-8 svn info ' . $file_path . "| awk '/^Last Changed Date/ { print $4 \" \" $5 }'"); - $lastmodified = strtotime($lastmodified); - break; - } - return $lastmodified; + $salvatore_lastmodified_file = "salvatore_" . $source['methode'] . "_lastmodified_file"; + return $salvatore_lastmodified_file($dir_depots . $source['dir_checkout'], $file_path_relative); } @@ -428,21 +416,9 @@ function salvatore_read_status_modif($module, $source, $dir_depots) { $pre = $source['dir'] . DIRECTORY_SEPARATOR; } $files_list = [$pre . $module . '_*', $pre . $module . '.xml']; - $files_list = implode(' ', $files_list); - - $d = getcwd(); - chdir($dir_depots . $source['dir_checkout']); - $output = array(); - switch ($source['methode']) { - case 'git': - exec("git status --short $files_list 2>&1", $output); - break; - case 'svn': - exec("svn status $files_list 2>&1", $output); - break; - } - chdir($d); - return implode("\n", $output); + + $salvatore_status_file = "salvatore_" . $source['methode'] . "_status_file"; + return $salvatore_status_file($dir_depots . $source['dir_checkout'], $files_list); } /* diff --git a/inc/salvatore_git.php b/inc/salvatore_git.php new file mode 100644 index 0000000000000000000000000000000000000000..76e014708b8af1468a806a0890db362d3f4e9263 --- /dev/null +++ b/inc/salvatore_git.php @@ -0,0 +1,69 @@ +<?php + +/* + This file is part of Salvatore, the translation robot of Trad-lang (SPIP) + + Salvatore is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Trad-Lang is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Trad-Lang; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Copyright 2003-2020 + Florent Jugla <florent.jugla@eledo.com>, + Philippe Riviere <fil@rezo.net>, + Chryjs <chryjs!@!free!.!fr>, + kent1 <kent1@arscenic.info> + Cerdic <cedric@yterium.com> +*/ + +/** + * Lire la date de derniere modif d'un fichier versionne + * (retourne 0 si le fichier n'est pas versionne) + * @param string $dir_repo + * @param string $file + * @return false|int + */ +function salvatore_git_lastmodified_file($dir_repo, $file) { + + $d = getcwd(); + chdir($dir_repo); + $file = escapeshellarg($file); + $lastmodified = exec("git log -1 -c --pretty=tformat:'%ct' $file | head -1"); + $lastmodified = intval(trim($lastmodified)); + chdir($d); + return $lastmodified; +} + +/** + * Afficher le status d'un ou plusieurs fichiers + * @param string $dir_repo + * @param string|array $file_or_files + * @return string + */ +function salvatore_git_status_file($dir_repo, $file_or_files) { + + if (is_array($file_or_files)) { + $file_or_files = array_map('escapeshellarg', $file_or_files); + $file_or_files = implode(' ', $file_or_files); + } + else { + $file_or_files = escapeshellarg($file_or_files); + } + + $d = getcwd(); + chdir($dir_repo); + $output = array(); + exec("git status --short $file_or_files 2>&1", $output); + //exec("svn status $files_list 2>&1", $output); + chdir($d); + return implode("\n", $output); +} diff --git a/inc/salvatore_svn.php b/inc/salvatore_svn.php new file mode 100644 index 0000000000000000000000000000000000000000..bdacc63f40d598902ced81a27c4dbb7b214eb8fe --- /dev/null +++ b/inc/salvatore_svn.php @@ -0,0 +1,68 @@ +<?php + +/* + This file is part of Salvatore, the translation robot of Trad-lang (SPIP) + + Salvatore is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + Trad-Lang is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Trad-Lang; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Copyright 2003-2020 + Florent Jugla <florent.jugla@eledo.com>, + Philippe Riviere <fil@rezo.net>, + Chryjs <chryjs!@!free!.!fr>, + kent1 <kent1@arscenic.info> + Cerdic <cedric@yterium.com> +*/ + +/** + * Lire la date de derniere modif d'un fichier versionne + * (retourne 0 si le fichier n'est pas versionne) + * @param string $dir_repo + * @param string $file + * @return false|int + */ +function salvatore_svn_lastmodified_file($dir_repo, $file) { + + $d = getcwd(); + chdir($dir_repo); + $file = escapeshellarg($file); + $lastmodified = exec('env LC_MESSAGES=en_US.UTF-8 svn info ' . $file . "| awk '/^Last Changed Date/ { print $4 \" \" $5 }'"); + $lastmodified = strtotime($lastmodified); + chdir($d); + return $lastmodified; +} + +/** + * Afficher le status d'un ou plusieurs fichiers + * @param string $dir_repo + * @param string|array $file_or_files + * @return string + */ +function salvatore_svn_status_file($dir_repo, $file_or_files) { + + if (is_array($file_or_files)) { + $file_or_files = array_map('escapeshellarg', $file_or_files); + $file_or_files = implode(' ', $file_or_files); + } + else { + $file_or_files = escapeshellarg($file_or_files); + } + + $d = getcwd(); + chdir($dir_repo); + $output = array(); + exec("svn status $file_or_files 2>&1", $output); + chdir($d); + return implode("\n", $output); +}