From 9ec9c5e09acda51ca50ee5b1ca8ae4ffc4c44f25 Mon Sep 17 00:00:00 2001 From: Cerdic <cedric@yterium.com> Date: Sun, 19 Jan 2020 19:04:42 +0100 Subject: [PATCH] une abstraction git et une abstraction svn pour les fonctions de bas niveau dont on a besoin pour chaque methode --- inc/salvatore_ecriveur.php | 42 +++++------------------ inc/salvatore_git.php | 69 ++++++++++++++++++++++++++++++++++++++ inc/salvatore_svn.php | 68 +++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 33 deletions(-) create mode 100644 inc/salvatore_git.php create mode 100644 inc/salvatore_svn.php diff --git a/inc/salvatore_ecriveur.php b/inc/salvatore_ecriveur.php index efb0f29..f458a55 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 0000000..76e0147 --- /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 0000000..bdacc63 --- /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); +} -- GitLab