Skip to content
Extraits de code Groupes Projets
Valider 9ec9c5e0 rédigé par cerdic's avatar cerdic
Parcourir les fichiers

une abstraction git et une abstraction svn pour les fonctions de bas niveau...

une abstraction git et une abstraction svn pour les fonctions de bas niveau dont on a besoin pour chaque methode
parent 88ad2385
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -34,6 +34,9 @@ include_spip('inc/xml'); ...@@ -34,6 +34,9 @@ include_spip('inc/xml');
include_spip('inc/lang_liste'); include_spip('inc/lang_liste');
include_spip('inc/session'); include_spip('inc/session');
include_spip('inc/salvatore_svn');
include_spip('inc/salvatore_git');
/** /**
* @param array $liste_sources * @param array $liste_sources
...@@ -310,7 +313,7 @@ function salvatore_exporter_module($id_tradlang_module, $source, $url_site, $url ...@@ -310,7 +313,7 @@ function salvatore_exporter_module($id_tradlang_module, $source, $url_site, $url
if (count($commit_infos)) { if (count($commit_infos)) {
$nb_to_commit = count($commit_infos); $nb_to_commit = count($commit_infos);
if ($message_commit) { 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)); 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) { ...@@ -394,24 +397,9 @@ function salvatore_read_lastmodified_file($file_name, $source, $dir_depots) {
if ($source['dir']) { if ($source['dir']) {
$file_path_relative = $source['dir'] . DIRECTORY_SEPARATOR . $file_path_relative; $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) { ...@@ -428,21 +416,9 @@ function salvatore_read_status_modif($module, $source, $dir_depots) {
$pre = $source['dir'] . DIRECTORY_SEPARATOR; $pre = $source['dir'] . DIRECTORY_SEPARATOR;
} }
$files_list = [$pre . $module . '_*', $pre . $module . '.xml']; $files_list = [$pre . $module . '_*', $pre . $module . '.xml'];
$files_list = implode(' ', $files_list);
$salvatore_status_file = "salvatore_" . $source['methode'] . "_status_file";
$d = getcwd(); return $salvatore_status_file($dir_depots . $source['dir_checkout'], $files_list);
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);
} }
/* /*
......
<?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);
}
<?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);
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter