r113722 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113721‎ | r113722 | r113723 >
Date:14:33, 13 March 2012
Author:hashar
Status:ok
Tags:
Comment:
let sync-group find file timestamp using git!
Modified paths:
  • /trunk/extensions/Translate/scripts/sync-group.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/scripts/sync-group.php
@@ -12,6 +12,7 @@
1313
1414 /// @cond
1515
 16+$options = array( 'git' );
1617 $optionsWithArgs = array( 'group', 'groupprefix', 'lang', 'start', 'end' );
1718 require( dirname( __FILE__ ) . '/cli.inc' );
1819
@@ -24,6 +25,8 @@
2526 --group Comma separated list of group IDs (cannot use groupprefix)
2627 --groupprefix Prefix of group IDs to be exported message groups (cannot use
2728 group)
 29+ --git Use git to retrieve last modified date of i18n files. Will use
 30+ subversion by default and fallback on filesystem timestamp.
2831 --lang Comma separated list of language codes or *
2932 --norc Do not add entries to recent changes table
3033 --help This help message
@@ -124,7 +127,13 @@
125128 $cs->nocolor = true;
126129 }
127130
128 - $ts = $cs->getTimestampsFromSvn( $file );
 131+ # Guess last modified date of the file from either git, svn or filesystem
 132+ $ts = false;
 133+ if( isset( $options['git'] ) ) {
 134+ $ts = $cs->getTimestampsFromGit( $file );
 135+ } else {
 136+ $ts = $cs->getTimestampsFromSvn( $file );
 137+ }
129138 if ( !$ts ) {
130139 $ts = $cs->getTimestampsFromFs( $file );
131140 }
@@ -182,6 +191,23 @@
183192 }
184193
185194 /**
 195+ * Fetch last changed timestamp for a versioned file for conflict resolution.
 196+ * @param $file \string Filename with full path.
 197+ * @return \string Timestamp or false.
 198+ */
 199+ public function getTimestampsFromGit( $file ) {
 200+ $file = escapeshellarg( $file );
 201+ $retval = 0;
 202+ $output = wfShellExec( "git log -n 1 --format=%cd $file", $retval );
 203+
 204+ if ( $retval ) {
 205+ return false;
 206+ }
 207+
 208+ return strtotime( $output );
 209+ }
 210+
 211+ /**
186212 * Fetch last changed timestamp for any file for conflict resolution.
187213 * @param $file \string Filename with full path.
188214 * @return \string Timestamp or false.

Status & tagging log