[Fusionforge-commits] FusionForge branch Branch_5_3 updated. 40cfba9fed2a0611f6d531b8eb47fe194acf8361

Franck Villaume nerville at fusionforge.org
Sat Aug 30 19:17:00 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, Branch_5_3 has been updated
       via  40cfba9fed2a0611f6d531b8eb47fe194acf8361 (commit)
      from  1e186ad0baa31f4180b8ad8054e53a93b49891df (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 40cfba9fed2a0611f6d531b8eb47fe194acf8361
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Sat Aug 30 18:54:52 2014 +0200

    fix [#717]: Wrong data report in SCM plugin: scmgit & scmsvn fix

diff --git a/src/db/20140829-scm-stats-add-column-updates.sql b/src/db/20140829-scm-stats-add-column-updates.sql
new file mode 100644
index 0000000..bd63db9
--- /dev/null
+++ b/src/db/20140829-scm-stats-add-column-updates.sql
@@ -0,0 +1,8 @@
+ALTER TABLE stats_cvs_user ADD COLUMN updates INT;
+ALTER TABLE stats_cvs_group ADD COLUMN updates INT;
+ALTER TABLE stats_cvs_user ALTER COLUMN updates SET DEFAULT 0;
+ALTER TABLE stats_cvs_group ALTER COLUMN updates SET DEFAULT 0;
+ALTER TABLE stats_cvs_user ADD COLUMN deletes INT;
+ALTER TABLE stats_cvs_group ADD COLUMN deletes INT;
+ALTER TABLE stats_cvs_user ALTER COLUMN deletes SET DEFAULT 0;
+ALTER TABLE stats_cvs_group ALTER COLUMN deletes SET DEFAULT 0;
diff --git a/src/plugins/scmgit/common/GitPlugin.class.php b/src/plugins/scmgit/common/GitPlugin.class.php
index f93e643..2fb3828 100644
--- a/src/plugins/scmgit/common/GitPlugin.class.php
+++ b/src/plugins/scmgit/common/GitPlugin.class.php
@@ -65,9 +65,9 @@ class GitPlugin extends SCMPlugin {
 		}
 
 		if ($project->usesPlugin($this->name) && forge_check_perm('scm', $project->getID(), 'read')) {
-			$result = db_query_params('SELECT sum(commits) AS commits, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
+			$result = db_query_params('SELECT sum(updates) AS updates, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
 						array($project->getID()));
-			$commit_num = db_result($result,0,'commits');
+			$commit_num = db_result($result,0,'updates');
 			$add_num    = db_result($result,0,'adds');
 			if (!$commit_num) {
 				$commit_num=0;
@@ -345,11 +345,10 @@ class GitPlugin extends SCMPlugin {
 		global $HTML;
 		$b = '';
 
-		$result = db_query_params('SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined FROM stats_cvs_user s, users u WHERE group_id=$1 AND s.user_id=u.user_id AND (commits>0 OR adds >0) GROUP BY u.user_id, realname, user_name, u.user_id ORDER BY combined DESC, realname',
+		$result = db_query_params('SELECT u.realname, u.user_name, u.user_id, sum(updates) as updates, sum(adds) as adds, sum(adds+commits) as combined FROM stats_cvs_user s, users u WHERE group_id=$1 AND s.user_id=u.user_id AND (commits>0 OR adds >0) GROUP BY u.user_id, realname, user_name, u.user_id ORDER BY combined DESC, realname',
 			array($project->getID()));
 
 		if (db_numrows($result) > 0) {
-//			$b .= $HTML->boxMiddle(_('Repository Statistics'));
 
 			$tableHeaders = array(
 			_('Name'),
@@ -359,22 +358,22 @@ class GitPlugin extends SCMPlugin {
 			$b .= $HTML->listTableTop($tableHeaders, false, '', 'repo-history');
 
 			$i = 0;
-			$total = array('adds' => 0, 'commits' => 0);
+			$total = array('adds' => 0, 'updates' => 0);
 
 			while($data = db_fetch_array($result)) {
 				$b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
 				$b .= '<td class="halfwidth">';
 				$b .= util_make_link_u($data['user_name'], $data['user_id'], $data['realname']);
 				$b .= '</td><td class="onequarterwidth align-right">'.$data['adds']. '</td>'.
-					'<td class="onequarterwidth align-right">'.$data['commits'].'</td></tr>';
+					'<td class="onequarterwidth align-right">'.$data['updates'].'</td></tr>';
 				$total['adds'] += $data['adds'];
-				$total['commits'] += $data['commits'];
+				$total['updates'] += $data['updates'];
 				$i++;
 			}
 			$b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
 			$b .= '<td class="halfwidth"><strong>'._('Total').':</strong></td>'.
 				'<td class="onequarterwidth align-right"><strong>'.$total['adds']. '</strong></td>'.
-				'<td class="onequarterwidth align-right"><strong>'.$total['commits'].'</strong></td>';
+				'<td class="onequarterwidth align-right"><strong>'.$total['updates'].'</strong></td>';
 			$b .= '</tr>';
 			$b .= $HTML->listTableBottom();
 		}
@@ -717,9 +716,12 @@ class GitPlugin extends SCMPlugin {
 			$usr_adds    = array();
 			$usr_updates = array();
 			$usr_deletes = array();
+			$usr_commits = array();
 
 			$adds    = 0;
 			$updates = 0;
+			$deletes = 0;
+			$commits = 0;
 
 			$repo = forge_get_config('repos_path', 'scmgit') . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git';
 			if (!is_dir($repo) || !is_dir("$repo/refs")) {
@@ -742,12 +744,23 @@ class GitPlugin extends SCMPlugin {
 				return false;
 			}
 
+			$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
+						array ($month_string,
+						       $day,
+						       $project->getID())) ;
+			if(!$res) {
+				echo "Error while cleaning stats_cvs_user\n" ;
+				db_rollback () ;
+				return false ;
+			}
+
 			$last_user    = "";
 			while (!feof($pipe) && $data = fgets($pipe)) {
 				$line = trim($data);
 				// Drop bad UTF-8 - it's quite hard to make git output non-UTF-8
 				// (e.g. by enforcing an unknown encoding) - but some users do!
 				// and this makes PostgreSQL choke
+				// this fix removes tabs in line. the regex used in short-commit stats line has been changed accordingly.
 				$line = preg_replace('/[^(\x20-\x7F)]/','', $line);
 				if (strlen($line) > 0) {
 					$result = preg_match("/^(?P<name>.+) <(?P<mail>.+)>/", $line, $matches);
@@ -759,10 +772,13 @@ class GitPlugin extends SCMPlugin {
 							$usr_adds[$last_user] = 0;
 							$usr_updates[$last_user] = 0;
 							$usr_deletes[$last_user] = 0;
+							$usr_commits[$last_user] = 0;
 						}
+						$commits++;
+						$usr_commits[$last_user]++;
 					} else {
 						// Short-commit stats line
-						$result = preg_match("/^(?P<mode>[AMD])\s+(?P<file>.+)$/", $line, $matches);
+						$result = preg_match("/^(?P<mode>[AMD])(?P<file>.+)$/", $line, $matches);
 						if (!$result) continue;
 						if ($last_user == "") continue;
 						if (!isset($usr_adds[$last_user])) $usr_adds[$last_user] = 0;
@@ -776,20 +792,23 @@ class GitPlugin extends SCMPlugin {
 							$updates++;
 						} elseif ($matches['mode'] == 'D') {
 							$usr_deletes[$last_user]++;
+							$deletes++;
 						}
 					}
 				}
 			}
 
 			// inserting group results in stats_cvs_groups
-			if ($updates > 0 || $adds > 0) {
-				if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+			if ($updates > 0 || $adds > 0 || $deletes > 0 || $commits > 0) {
+				if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds,updates,deletes) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
 						      array($month_string,
 							     $day,
 							     $project->getID(),
 							     0,
+							     $commits,
+							     $adds,
 							     $updates,
-							     $adds))) {
+							     $deletes))) {
 					echo "Error while inserting into stats_cvs_group\n";
 					db_rollback();
 					return false;
@@ -797,7 +816,7 @@ class GitPlugin extends SCMPlugin {
 			}
 
 			// building the user list
-			$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ) ) );
+			$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ), array_keys( $usr_deletes ), array_keys( $usr_commits ) ) );
 
 			foreach ($user_list as $user) {
 				// Trying to get user id from user name or email
@@ -814,16 +833,20 @@ class GitPlugin extends SCMPlugin {
 					}
 				}
 
+				$uc = isset($usr_commits[$user]) ? $usr_commits[$user] : 0;
 				$uu = isset($usr_updates[$user]) ? $usr_updates[$user] : 0;
 				$ua = isset($usr_adds[$user]) ? $usr_adds[$user] : 0;
-				if ($uu > 0 || $ua > 0) {
-					if (!db_query_params('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+				$ud = isset($usr_deletes[$user]) ? $usr_deletes[$user] : 0;
+				if ($uu > 0 || $ua > 0 || $uc > 0 || $ud > 0) {
+					if (!db_query_params('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds,updates,deletes) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
 							      array($month_string,
 								     $day,
 								     $project->getID(),
 								     $user_id,
+								     $uc,
+								     $ua,
 								     $uu,
-								     $ua))) {
+								     $ud))) {
 						echo "Error while inserting into stats_cvs_user\n";
 						db_rollback();
 						return false;
@@ -974,7 +997,7 @@ class GitPlugin extends SCMPlugin {
 					$result = array();
 					$result['section'] = 'scm';
 					$result['group_id'] = $group_id;
-					$result['ref_id'] = 'browser.php?group_id='.$group_id;
+					$result['ref_id'] = 'browser.php?group_id='.$group_id.'&commit='.$splitedLine[3];
 					$result['description'] = htmlspecialchars($splitedLine[2]).' (commit '.$splitedLine[3].')';
 					$userObject = user_get_object_by_email($splitedLine[1]);
 					if (is_a($userObject, 'GFUser')) {
diff --git a/src/plugins/scmsvn/common/SVNPlugin.class.php b/src/plugins/scmsvn/common/SVNPlugin.class.php
index 6e3c973..be2c54a 100644
--- a/src/plugins/scmsvn/common/SVNPlugin.class.php
+++ b/src/plugins/scmsvn/common/SVNPlugin.class.php
@@ -69,9 +69,9 @@ class SVNPlugin extends SCMPlugin {
 		}
 
 		if ($project->usesPlugin($this->name) && forge_check_perm('scm', $project->getID(), 'read')) {
-			$result = db_query_params('SELECT sum(commits) AS commits, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
+			$result = db_query_params('SELECT sum(updates) AS updates, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
 						  array ($project->getID())) ;
-			$commit_num = db_result($result,0,'commits');
+			$commit_num = db_result($result,0,'updates');
 			$add_num    = db_result($result,0,'adds');
 			if (!$commit_num) {
 				$commit_num=0;
@@ -399,8 +399,8 @@ class SVNPlugin extends SCMPlugin {
 
 	function gatherStats($params) {
 		global $last_user, $last_time, $last_tag, $time_ok, $start_time, $end_time,
-			$adds, $deletes, $updates, $date_key,
-			$usr_adds, $usr_deletes, $usr_updates;
+			$adds, $deletes, $updates, $commits, $date_key,
+			$usr_adds, $usr_deletes, $usr_updates, $usr_commits;
 
 		$time_ok = true;
 
@@ -425,8 +425,13 @@ class SVNPlugin extends SCMPlugin {
 
 			$adds    = 0;
 			$updates = 0;
+			$deletes = 0;
+			$commits = 0;
+
 			$usr_adds    = array();
 			$usr_updates = array();
+			$usr_deletes = array();
+			$usr_commits = array();
 
 			$repo = forge_get_config('repos_path', 'scmsvn') . '/' . $project->getUnixName();
 			if (!is_dir ($repo) || !is_file ("$repo/format")) {
@@ -481,14 +486,16 @@ class SVNPlugin extends SCMPlugin {
 			xml_parser_free($xml_parser);
 
 			// inserting group results in stats_cvs_groups
-			if ($updates > 0 || $adds > 0) {
-				if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+			if ($updates > 0 || $adds > 0 || $deletes > 0 || $commits > 0) {
+				if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds,updates,deletes) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
 						      array ($month_string,
 							     $day,
 							     $project->getID(),
 							     0,
+							     $commits,
+							     $adds,
 							     $updates,
-							     $adds))) {
+							     $deletes))) {
 					echo "Error while inserting into stats_cvs_group\n" ;
 					db_rollback();
 					return false;
@@ -496,7 +503,7 @@ class SVNPlugin extends SCMPlugin {
 			}
 
 			// building the user list
-			$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ) ) );
+			$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ),  array_keys( $usr_deletes ), array_keys( $usr_commits )) );
 
 			foreach ( $user_list as $user ) {
 				// trying to get user id from user name
@@ -507,16 +514,20 @@ class SVNPlugin extends SCMPlugin {
 					continue;
 				}
 
+				$uc = isset($usr_commits[$user]) ? $usr_commits[$user] : 0 ;
 				$uu = isset($usr_updates[$user]) ? $usr_updates[$user] : 0 ;
 				$ua = isset($usr_adds[$user]) ? $usr_adds[$user] : 0 ;
-				if ($uu > 0 || $ua > 0) {
-					if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+				$ud = isset($usr_deletes[$user]) ? $usr_deletes[$user] : 0 ;
+				if ($uu > 0 || $ua > 0 || $uc > 0 || $ud > 0) {
+					if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds, updates, deletes) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)',
 							      array ($month_string,
 								     $day,
 								     $project->getID(),
 								     $user_id,
+								     $uc,
+								     $ua,
 								     $uu,
-								     $ua))) {
+								     $ud))) {
 						echo "Error while inserting into stats_cvs_user\n" ;
 						db_rollback () ;
 						return false ;
@@ -597,8 +608,7 @@ class SVNPlugin extends SCMPlugin {
 
 	function activity($params) {
 		global $last_user, $last_time, $last_tag, $time_ok, $start_time, $end_time,
-			$adds, $deletes, $updates, $date_key,
-			$usr_adds, $usr_deletes, $usr_updates,
+			$adds, $deletes, $updates, $commits, $date_key,
 			$messages, $last_message, $times, $revisions, $users;
 		$group_id = $params['group'];
 		$project = group_get_object($group_id);
@@ -628,7 +638,7 @@ class SVNPlugin extends SCMPlugin {
 				}
 			}
 			xml_parser_free($xml_parser);
-			if ($adds > 0 || $updates > 0) {
+			if ($adds > 0 || $updates > 0 || $commits > 0 || $deletes > 0) {
 				$i = 0;
 				foreach ($messages as $message) {
 					$result = array();
@@ -658,12 +668,14 @@ class SVNPlugin extends SCMPlugin {
 // End of class, helper functions now
 
 function SVNPluginCharData($parser, $chars) {
-	global $last_tag, $last_user, $last_time, $start_time, $end_time,
+	global $last_tag, $last_user, $last_time, $start_time, $end_time, $usr_commits, $commits,
 		$time_ok, $user_list, $last_message, $messages, $times, $users;
 	switch ($last_tag) {
 		case "AUTHOR": {
 			$last_user = preg_replace('/[^a-z0-9_-]/', '', strtolower(trim($chars)));
 			$users[] = $last_user;
+			$usr_commits[$last_user] = isset($usr_commits[$last_user]) ? ($usr_commits[$last_user]+1) : 1 ;
+			$commits++;
 			break;
 		}
 		case "DATE": {
@@ -673,12 +685,16 @@ function SVNPluginCharData($parser, $chars) {
 				$time_ok = true;
 			} else {
 				$time_ok = false;
+				$usr_commits[$last_user]--;
+				$commits--;
 			}
 			$times[] = $last_time;
 			break;
 		}
 		case "MSG": {
-                        $messages[count($messages)-1] .= $chars;
+			if ($time_ok === true) {
+				$messages[count($messages)-1] .= $chars;
+			}
                         /* note: there may be more than one msg
 			 * (happen when the message contain accents).
 			 */
@@ -688,8 +704,8 @@ function SVNPluginCharData($parser, $chars) {
 }
 
 function SVNPluginStartElement($parser, $name, $attrs) {
-	global $last_user, $last_time, $last_tag, $time_ok,
-		$adds, $updates, $usr_adds, $usr_updates, $last_message, $messages, $times, $revisions;
+	global $last_user, $last_time, $last_tag, $time_ok, $commits,
+		$adds, $updates, $usr_adds, $usr_updates, $last_message, $messages, $times, $revisions, $deletes, $usr_deletes;
 	$last_tag = $name;
 	switch($name) {
 		case "LOGENTRY": {
@@ -700,7 +716,8 @@ function SVNPluginStartElement($parser, $name, $attrs) {
 			break;
 		}
 		case "PATH": {
-			if ($time_ok) {
+			if ($time_ok === true) {
+
 				if ($attrs['ACTION'] == "M") {
 					$updates++;
 					if ($last_user) {
@@ -711,12 +728,19 @@ function SVNPluginStartElement($parser, $name, $attrs) {
 					if ($last_user) {
 						$usr_adds[$last_user] = isset($usr_adds[$last_user]) ? ($usr_adds[$last_user]+1) : 1 ;
 					}
+				} elseif ($attrs['ACTION'] == 'D') {
+					$deletes++;
+					if ($last_user) {
+						$usr_deletes[$last_user] = isset($usr_deletes[$last_user]) ? ($usr_deletes[$last_user]+1) : 1 ;
+					}
 				}
 			}
 			break;
 		}
                 case "MSG": {
-                        $messages[] = "";
+			if ($time_ok === true) {
+				$messages[] = "";
+			}
 			break;
                 }
 	}

-----------------------------------------------------------------------

Summary of changes:
 src/db/20140829-scm-stats-add-column-updates.sql |    8 +++
 src/plugins/scmgit/common/GitPlugin.class.php    |   57 +++++++++++++------
 src/plugins/scmsvn/common/SVNPlugin.class.php    |   64 +++++++++++++++-------
 3 files changed, 92 insertions(+), 37 deletions(-)
 create mode 100644 src/db/20140829-scm-stats-add-column-updates.sql


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list