source: spip-zone/_plugins_/trad-lang/trunk/inc/salvatore_git.php @ 119844

Last change on this file since 119844 was 119844, checked in by Cerdic, 2 years ago

une abstraction git et une abstraction svn pour les fonctions de bas niveau dont on a besoin pour chaque methode

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1<?php
2
3/*
4    This file is part of Salvatore, the translation robot of Trad-lang (SPIP)
5
6    Salvatore is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    Trad-Lang is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Trad-Lang; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20    Copyright 2003-2020
21        Florent Jugla <florent.jugla@eledo.com>,
22        Philippe Riviere <fil@rezo.net>,
23        Chryjs <chryjs!@!free!.!fr>,
24        kent1 <kent1@arscenic.info>
25        Cerdic <cedric@yterium.com>
26*/
27
28/**
29 * Lire la date de derniere modif d'un fichier versionne
30 * (retourne 0 si le fichier n'est pas versionne)
31 * @param string $dir_repo
32 * @param string $file
33 * @return false|int
34 */
35function salvatore_git_lastmodified_file($dir_repo, $file) {
36
37        $d = getcwd();
38        chdir($dir_repo);
39        $file = escapeshellarg($file);
40        $lastmodified = exec("git log -1 -c --pretty=tformat:'%ct' $file | head -1");
41        $lastmodified = intval(trim($lastmodified));
42        chdir($d);
43        return $lastmodified;
44}
45
46/**
47 * Afficher le status d'un ou plusieurs fichiers
48 * @param string $dir_repo
49 * @param string|array $file_or_files
50 * @return string
51 */
52function salvatore_git_status_file($dir_repo, $file_or_files) {
53
54        if (is_array($file_or_files)) {
55                $file_or_files = array_map('escapeshellarg', $file_or_files);
56                $file_or_files = implode(' ', $file_or_files);
57        }
58        else {
59                $file_or_files = escapeshellarg($file_or_files);
60        }
61
62        $d = getcwd();
63        chdir($dir_repo);
64        $output = array();
65        exec("git status --short $file_or_files 2>&1", $output);
66        //exec("svn status $files_list 2>&1", $output);
67        chdir($d);
68        return implode("\n", $output);
69}
Note: See TracBrowser for help on using the repository browser.