[Fusionforge-commits] FusionForge branch master updated. v6.0.5-2118-g98616d6

Franck Villaume nerville at libremir.placard.fr.eu.org
Fri Aug 18 11:24:33 CEST 2017


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, master has been updated
       via  98616d6a4a44fdee3283b27f3ae1ce0629f64732 (commit)
      from  8726c921fa1904caf8ab180db4dbf25150e681fa (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 -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=98616d6a4a44fdee3283b27f3ae1ce0629f64732

commit 98616d6a4a44fdee3283b27f3ae1ce0629f64732
Author: Franck Villaume <franck.villaume at trivialdev.com>
Date:   Fri Aug 18 09:24:24 2017 +0000

    SCM plugins: backend support for stats per repositories, not only the main repo

diff --git a/src/db/20170811-scm-stats-reponame.sql b/src/db/20170811-scm-stats-reponame.sql
new file mode 100644
index 0000000..2fe471d
--- /dev/null
+++ b/src/db/20170811-scm-stats-reponame.sql
@@ -0,0 +1,15 @@
+ALTER TABLE stats_cvs_user ADD COLUMN reponame text NOT NULL default 'default_project_repo';
+ALTER TABLE stats_cvs_group ADD COLUMN reponame text NOT NULL default 'default_project_repo';
+
+UPDATE stats_cvs_group SET reponame = subquery.unix_group_name
+                       FROM (SELECT unix_group_name, groups.group_id FROM groups, stats_cvs_group
+                                                                     WHERE groups.group_id = stats_cvs_group.group_id) AS subquery
+                       WHERE stats_cvs_group.group_id = subquery.group_id;
+
+UPDATE stats_cvs_user SET reponame = subquery.unix_group_name
+                      FROM (SELECT unix_group_name, groups.group_id FROM groups, stats_cvs_user
+                                                                    WHERE groups.group_id = stats_cvs_user.group_id) AS subquery
+                      WHERE stats_cvs_user.group_id = subquery.group_id;
+
+DROP INDEX statscvsgroup_month_day_group;
+CREATE UNIQUE INDEX statscvsgroup_month_day_group ON stats_cvs_group USING btree ("month", "day", group_id, "reponame");
diff --git a/src/plugins/scmbzr/common/BzrPlugin.class.php b/src/plugins/scmbzr/common/BzrPlugin.class.php
index 2e8a99e..a8e0caa 100644
--- a/src/plugins/scmbzr/common/BzrPlugin.class.php
+++ b/src/plugins/scmbzr/common/BzrPlugin.class.php
@@ -3,7 +3,7 @@
  * FusionForge Bazaar plugin
  *
  * Copyright 2009, Roland Mas
- * Copyright 2013-2014, Franck Villaume - TrivialDev
+ * Copyright 2013-2014,2017 Franck Villaume - TrivialDev
  *
  * This file is part of FusionForge.
  *
@@ -274,7 +274,7 @@ over it to the project's administrator.");
 		}
 	}
 
-	function gatherStats ($params) {
+	function gatherStats($params) {
                 $project = $this->checkParams ($params) ;
                 if (!$project) {
                         return false ;
@@ -313,23 +313,25 @@ over it to the project's administrator.");
 				return false ;
 			}
 
-                        $pipe = popen ("bzr log file://$repo/$branch --long --verbose 2> /dev/null", 'r' ) ;
+			$pipe = popen("bzr log file://$repo/$branch --long --verbose 2> /dev/null", 'r');
 
-                        // cleaning stats_cvs_* table for the current day
-                        $res = db_query_params ('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
-                                                array ($month_string,
-                                                       $day,
-                                                       $project->getID())) ;
+			// cleaning stats_cvs_* table for the current day
+			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+						array($month_string,
+							$day,
+							$project->getID()),
+							$project->getUnixName());
                         if(!$res) {
-                                echo "Error while cleaning stats_cvs_group\n" ;
+                                echo "Error while cleaning stats_cvs_group\n";
                                 db_rollback () ;
                                 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())) ;
+			$res = db_query_params('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+						array ($month_string,
+							$day,
+							$project->getID()),
+							$project->getUnixName());
                         if(!$res) {
                                 echo "Error while cleaning stats_cvs_user\n" ;
                                 db_rollback () ;
@@ -401,15 +403,17 @@ over it to the project's administrator.");
 
                         // inserting group results in stats_cvs_groups
 			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)',
-						      array ($month_string,
-							     $day,
-							     $project->getID(),
-							     0,
-							     $commits,
-							     $adds,
-							     $updates,
-							     $deletes))) {
+				if (!db_query_params('INSERT INTO stats_cvs_group (month, day, group_id, checkouts, commits, adds, updates, deletes, reponame)
+								VALUES ($1, $2, $3, $4, $5, $6, $7)',
+								array($month_string,
+									$day,
+									$project->getID(),
+									0,
+									$commits,
+									$adds,
+									$updates,
+									$deletes,
+									$project->getUnixName()))) {
 					echo "Error while inserting into stats_cvs_group\n" ;
 					db_rollback () ;
 					return false ;
@@ -433,15 +437,17 @@ over it to the project's administrator.");
 				$ua = $usr_adds[$user] ? $usr_adds[$user] : 0 ;
 				$ud = $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)',
-							      array ($month_string,
-								     $day,
-								     $project->getID(),
-								     $user_id,
-								     $uc,
-								     $ua,
-								     $uu,
-								     $ud))) {
+					if (!db_query_params('INSERT INTO stats_cvs_user (month, day, group_id, user_id, commits, adds, updates, deletes, reponame)
+									VALUES ($1,$2,$3,$4,$5,$6)',
+									array($month_string,
+										$day,
+										$project->getID(),
+										$user_id,
+										$uc,
+										$ua,
+										$uu,
+										$ud,
+										$project->getUnixName()))) {
 						echo "Error while inserting into stats_cvs_user\n" ;
 						db_rollback () ;
 						return false ;
diff --git a/src/plugins/scmcvs/common/CVSPlugin.class.php b/src/plugins/scmcvs/common/CVSPlugin.class.php
index eb3fa42..6a2ba1d 100644
--- a/src/plugins/scmcvs/common/CVSPlugin.class.php
+++ b/src/plugins/scmcvs/common/CVSPlugin.class.php
@@ -337,20 +337,22 @@ over it to the project's administrator.");
 			}
 
 			// cleaning stats_cvs_* table for the current day
-			$res = db_query_params ('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
-						array ($month_string,
+			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+						array($month_string,
 						       $day,
-						       $project->getID())) ;
+						       $project->getID(),
+							$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_group\n" ;
 				db_rollback () ;
 				return false ;
 			}
 
-			$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
-						array ($month_string,
+			$res = db_query_params('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+						array($month_string,
 						       $day,
-						       $project->getID())) ;
+						       $project->getID(),
+							$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_user\n" ;
 				db_rollback () ;
@@ -388,13 +390,15 @@ over it to the project's administrator.");
 			fclose( $hist_file );
 
 			// inserting group results in stats_cvs_groups
-			if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
-					      array ($month_string,
+			if (!db_query_params('INSERT INTO stats_cvs_group (month, day, group_id, checkouts, commits, adds, reponame)
+							VALUES ($1, $2, $3, $4, $5, $6, $7)',
+					      array($month_string,
 						     $day,
 						     $project->getID(),
 						     $cvs_co,
 						     $cvs_commit,
-						     $cvs_add))) {
+						     $cvs_add,
+							$project->getUnixName()))) {
 				echo "Error while inserting into stats_cvs_group\n" ;
 				db_rollback () ;
 				return false ;
@@ -412,13 +416,15 @@ over it to the project's administrator.");
 					continue;
 				}
 
-				if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
-						      array ($month_string,
+				if (!db_query_params('INSERT INTO stats_cvs_user (month, day, group_id, user_id, commits, adds, reponame)
+								VALUES ($1, $2, $3, $4, $5, $6, $7)',
+						      array($month_string,
 							     $day,
 							     $project->getID(),
 							     $user_id,
 							     isset ($usr_commit[$user]) ? $usr_commit[$user] : 0,
-							     isset ($usr_add[$user]) ? $usr_add[$user] : 0))) {
+							     isset ($usr_add[$user]) ? $usr_add[$user] : 0,
+								$project->getUnixName()))) {
 					echo "Error while inserting into stats_cvs_user\n" ;
 					db_rollback () ;
 					return false ;
diff --git a/src/plugins/scmdarcs/common/DarcsPlugin.class.php b/src/plugins/scmdarcs/common/DarcsPlugin.class.php
index aca1751..6acffaa 100644
--- a/src/plugins/scmdarcs/common/DarcsPlugin.class.php
+++ b/src/plugins/scmdarcs/common/DarcsPlugin.class.php
@@ -416,152 +416,151 @@ over it to the project's administrator.");
 		}
 
 		if ($params['mode'] == 'day') {
-			db_begin();
-
 			$year = $params['year'];
 			$month = $params['month'];
 			$day = $params['day'];
-			$month_string = sprintf("%04d%02d", $year, $month);
-			$start_time = gmmktime(0, 0, 0, $month, $day, $year);
-			$end_time = $start_time + 86400;
-
-			$updates = 0;
-			$adds = 0;
-			$deletes = 0;
-			$usr_adds = array();
-			$usr_updates = array();
-			$usr_deletes = array();
+			foreach ($this->getRepositories($project) as $repo_name) {
+				gatherStatsRepo($project, $repo_name, $year, $month, $day);
+			}
+		}
+	}
 
-			$toprepo = $this->getRootRepositories($project);
-			$from_date = date("c", $start_time);
-			$to_date   = date("c", $end_time);
+	function gatherStatsRepo($group, $project_reponame, $year, $month, $day) {
+		$month_string = sprintf("%04d%02d", $year, $month);
+		$start_time = gmmktime(0, 0, 0, $month, $day, $year);
+		$end_time = $start_time + 86400;
+
+		$updates = 0;
+		$adds = 0;
+		$deletes = 0;
+		$usr_adds = array();
+		$usr_updates = array();
+		$usr_deletes = array();
+
+		$toprepo = $this->getRootRepositories($group);
+		$repo = $toprepo . '/' . $repo_name;
+		if (!is_dir($repo) || !is_dir("$repo/_darcs")) {
+			echo "No repository $repo\n";
+			return false;
+		}
+		$from_date = date("c", $start_time);
+		$to_date   = date("c", $end_time);
 
-			// cleaning stats_cvs_* table for the current day
-			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
+		db_begin();
+		// cleaning stats_cvs_* table for the current day
+		$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
 						array($month_string,
-						       $day,
-						       $project->getID()));
-			if(!$res) {
-				echo "Error while cleaning stats_cvs_group\n";
-				db_rollback();
-				return false;
-			}
+							$day,
+							$project->getID(),
+							$project_reponame));
+		if(!$res) {
+			echo "Error while cleaning stats_cvs_group\n";
+			db_rollback();
+			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;
-			}
+		$res = db_query_params('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+					array($month_string,
+						$day,
+						$project->getID(),
+						$project_reponame));
+		if(!$res) {
+			echo "Error while cleaning stats_cvs_user\n";
+			db_rollback();
+			return false;
+		}
 
-			foreach ($this->getRepositories($project) as $repo_name) {
-				$repo = $toprepo . '/' . $repo_name;
-				if (!is_dir($repo) || !is_dir("$repo/_darcs")) {
-					echo "No repository $repo\n";
-					db_rollback();
-					return false;
-				} else {
-					// echo "$repo\n";
-				}
+		$pipe = popen("darcs changes --repodir='$repo' --match 'date \"between $from_date and $to_date\"' --xml -s\n", 'r');
 
-				$pipe = popen("darcs changes --repodir='$repo' "
-								."--match 'date \"between $from_date and $to_date\"' "
-								."--xml -s\n", 'r');
-
-				$xml_parser = xml_parser_create();
-				xml_set_element_handler($xml_parser, "DarcsPluginStartElement", "DarcsPluginEndElement");
-
-				// Analyzing history stream
-				while (!feof($pipe) &&  $data = fgets($pipe, 4096)) {
-					if (!xml_parse($xml_parser, $data, feof($pipe))) {
-						debug("Unable to parse XML with error ".
-									xml_error_string(xml_get_error_code($xml_parser)).
-									" on line ".
-									xml_get_current_line_number($xml_parser));
-						db_rollback();
-						return false;
-						break;
-					}
-				}
-				xml_parser_free($xml_parser);
-			}
-
-			// inserting group results in stats_cvs_groups
+		$xml_parser = xml_parser_create();
+		xml_set_element_handler($xml_parser, "DarcsPluginStartElement", "DarcsPluginEndElement");
 
-			if (!db_query_params('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
-					      array($month_string,
-						     $day,
-						     $project->getID(),
-						     0,
-						     $updates,
-						     $adds))) {
-				echo "Error while inserting into stats_cvs_group\n";
+		// Analyzing history stream
+		while (!feof($pipe) &&  $data = fgets($pipe, 4096)) {
+			if (!xml_parse($xml_parser, $data, feof($pipe))) {
+				debug("Unable to parse XML with error ".
+					xml_error_string(xml_get_error_code($xml_parser)).
+					" on line ".
+					xml_get_current_line_number($xml_parser));
 				db_rollback();
 				return false;
 			}
+		}
+		xml_parser_free($xml_parser);
+
+		// inserting group results in stats_cvs_groups
+		if (!db_query_params('INSERT INTO stats_cvs_group (month, day, group_id, checkouts, commits, adds, reponame)
+						VALUES ($1, $2, $3, $4, $5, $6, $7)',
+					array($month_string,
+						$day,
+						$project->getID(),
+						0,
+						$updates,
+						$adds,
+						$project_reponame))) {
+			echo "Error while inserting into stats_cvs_group\n";
+			db_rollback();
+			return false;
+		}
 
-			// build map for email -> login
-
-			$email_login = array();
-			$email_login_fn = $repo."/_darcs/email-login.txt";
-			if (!file_exists($email_login_fn)) {
-				$email_login_fn = $repo."/.email-login.txt";
-			}
-			if (!file_exists($email_login_fn)) {
-				unset($email_login_fn);
-			}
+		// build map for email -> login
+		$email_login = array();
+		$email_login_fn = $repo."/_darcs/email-login.txt";
+		if (!file_exists($email_login_fn)) {
+			$email_login_fn = $repo."/.email-login.txt";
+		}
+		if (!file_exists($email_login_fn)) {
+			unset($email_login_fn);
+		}
 
-			if (isset($email_login_fn)) {
-				$fh = fopen($email_login_fn, 'r');
-				while (!feof($fh)) {
-					$a = explode(" ", fgets($fh));
-					if (isset($a[1])) {
-						$email_login[$a[0]] = rtrim($a[1]);
-					}
+		if (isset($email_login_fn)) {
+			$fh = fopen($email_login_fn, 'r');
+			while (!feof($fh)) {
+				$a = explode(" ", fgets($fh));
+				if (isset($a[1])) {
+					$email_login[$a[0]] = rtrim($a[1]);
 				}
-				fclose($fh);
 			}
+			fclose($fh);
+		}
 
-			// building the user list
-			$user_list = array_unique(array_merge(array_keys($usr_adds), array_keys($usr_updates)));
+		// building the user list
+		$user_list = array_unique(array_merge(array_keys($usr_adds), array_keys($usr_updates)));
 
-			foreach ($user_list as $user) {
-				// trying to get user id from darcs user name
-				$id = $user;
-				$tmp_email = explode("<", $id, 2);
-				if (isset($tmp_email[1])) {
-				  $tmp_email = explode(">", $tmp_email[1]);
-				  $id = $tmp_email[0];
-				}
-				if (isset($email_login[$id])) {
-				  $id = $email_login[$id];
-				}
-
-				$u = user_get_object_by_name($id);
-				if ($u) {
-					$user_id = $u->getID();
-				} else {
-					continue;
-				}
+		foreach ($user_list as $user) {
+			// trying to get user id from darcs user name
+			$id = $user;
+			$tmp_email = explode("<", $id, 2);
+			if (isset($tmp_email[1])) {
+				$tmp_email = explode(">", $tmp_email[1]);
+				$id = $tmp_email[0];
+			}
+			if (isset($email_login[$id])) {
+				$id = $email_login[$id];
+			}
 
-				if (!db_query_params('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
-						      array($month_string,
-							     $day,
-							     $project->getID(),
-							     $user_id,
-							     isset($usr_updates[$user]) ? $usr_updates[$user] : 0,
-							     isset($usr_adds[$user]) ? $usr_adds[$user] : 0))) {
-					echo "Error while inserting into stats_cvs_user\n";
-					db_rollback();
-					return false;
-				}
+			$u = user_get_object_by_name($id);
+			if ($u) {
+				$user_id = $u->getID();
+			} else {
+				continue;
 			}
 
-			db_commit();
+			if (!db_query_params('INSERT INTO stats_cvs_user (month, day, group_id, user_id, commits, adds) VALUES ($1, $2, $3, $4, $5, $6, $7)',
+							array($month_string,
+								$day,
+								$project->getID(),
+								$user_id,
+								isset($usr_updates[$user]) ? $usr_updates[$user] : 0,
+								isset($usr_adds[$user]) ? $usr_adds[$user] : 0),
+								$project_reponame)) {
+				echo "Error while inserting into stats_cvs_user\n";
+				db_rollback();
+				return false;
+			}
 		}
+
+		db_commit();
 	}
 
 	function printAdminPage($params) {
diff --git a/src/plugins/scmgit/common/GitPlugin.class.php b/src/plugins/scmgit/common/GitPlugin.class.php
index 189fe07..3ca70e5 100644
--- a/src/plugins/scmgit/common/GitPlugin.class.php
+++ b/src/plugins/scmgit/common/GitPlugin.class.php
@@ -698,150 +698,173 @@ control over it to the project's administrator.");
 			$start_time = gmmktime(0, 0, 0, $month, $day, $year);
 			$end_time = $start_time + 86400;
 
-			$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")) {
-				// echo "No repository $repo\n";
-				return false;
+			gatherStatsRepo($project->getUnixName(), $project->getUnixName(), $year, $month, $day);
+
+			$result = db_query_params('SELECT repo_name FROM scm_secondary_repos WHERE group_id=$1 AND plugin_id=$3 ORDER BY repo_name',
+						   array($project->getID(),
+							  $this->getID()));
+			$rows = db_numrows($result);
+			for ($i=0; $i<$rows; $i++) {
+				gatherStatsRepo($project, db_result($result, $i, 'repo_name', $year, $month, $day);
 			}
+		}
+	}
+
+	function gatherStatsRepo($group, $project_reponame, $year, $month, $day) {
+
+		$month_string = sprintf("%04d%02d", $year, $month);
+		$start_time = gmmktime(0, 0, 0, $month, $day, $year);
+		$end_time = $start_time + 86400;
+
+		$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') . '/' . $group->getUnixName() . '/' . $project_reponame . '.git';
+		if (!is_dir($repo) || !is_dir("$repo/refs")) {
+			// echo "No repository $repo\n";
+			return false;
+		}
 
-			# For each commit, get committer full name and e-mail (respecting git .mailmap file),
-			# and a list of files prefixed by their status (A/M/D)
-			$pipe = popen("GIT_DIR=\"$repo\" git log --since=@$start_time --until=@$end_time --all --pretty='format:%n%aN <%aE>' --name-status 2>/dev/null", 'r' );
+		# For each commit, get committer full name and e-mail (respecting git .mailmap file),
+		# and a list of files prefixed by their status (A/M/D)
+		$pipe = popen("GIT_DIR=\"$repo\" git log --since=@$start_time --until=@$end_time --all --pretty='format:%n%aN <%aE>' --name-status 2>/dev/null", 'r');
 
-			db_begin();
+		db_begin();
 
-			// cleaning stats_cvs_* table for the current day
-			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
+		// cleaning stats_cvs_* table for the current day for the default repository
+		$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 and reponame = $4',
 						array($month_string,
-						       $day,
-						       $project->getID()));
-			if (!$res) {
-				echo "Error while cleaning stats_cvs_group\n";
-				db_rollback();
-				return false;
-			}
+							$day,
+							$group->getID(),
+							$project_reponame));
+		if (!$res) {
+			echo "Error while cleaning stats_cvs_group\n";
+			db_rollback();
+			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 ;
-			}
+		$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 and reponame = $4',
+						array($month_string,
+							$day,
+							$group->getID(),
+							$project_reponame));
+		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);
-				// Replace bad UTF-8 with '?' - it's quite hard to make git output non-UTF-8
-				// (e.g. with i18n.commitEncoding = unknown) - but some users do!
-				// and this makes PostgreSQL choke (SQL> ERROR:  invalid byte sequence for encoding "UTF8": 0xf9)
-				$line = mb_convert_encoding($line, 'UTF-8', 'UTF-8');
-				if (strlen($line) > 0) {
-					$result = preg_match("/^(?P<name>.+) <(?P<mail>.+)>/", $line, $matches);
-					if ($result) {
-						// Author line
-						$last_user = $matches['name'];
-						$user2email[$last_user] = $matches['mail'];
-						if (!isset($usr_adds[$last_user])) {
-							$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);
-						if (!$result)
-							continue;
-						if ($last_user == "")
-							continue;
-						if (!isset($usr_adds[$last_user]))
-							$usr_adds[$last_user] = 0;
-						if (!isset($usr_updates[$last_user]))
-							$usr_updates[$last_user] = 0;
-						if (!isset($usr_deletes[$last_user]))
-							$usr_deletes[$last_user] = 0;
-						if ($matches['mode'] == 'A') {
-							$usr_adds[$last_user]++;
-							$adds++;
-						} elseif ($matches['mode'] == 'M') {
-							$usr_updates[$last_user]++;
-							$updates++;
-						} elseif ($matches['mode'] == 'D') {
-							$usr_deletes[$last_user]++;
-							$deletes++;
-						}
+		$last_user = "";
+		while (!feof($pipe) && $data = fgets($pipe)) {
+			$line = trim($data);
+			// Replace bad UTF-8 with '?' - it's quite hard to make git output non-UTF-8
+			// (e.g. with i18n.commitEncoding = unknown) - but some users do!
+			// and this makes PostgreSQL choke (SQL> ERROR:  invalid byte sequence for encoding "UTF8": 0xf9)
+			$line = mb_convert_encoding($line, 'UTF-8', 'UTF-8');
+			if (strlen($line) > 0) {
+				$result = preg_match("/^(?P<name>.+) <(?P<mail>.+)>/", $line, $matches);
+				if ($result) {
+					// Author line
+					$last_user = $matches['name'];
+					$user2email[$last_user] = $matches['mail'];
+					if (!isset($usr_adds[$last_user])) {
+						$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);
+					if (!$result)
+						continue;
+					if ($last_user == "")
+						continue;
+					if (!isset($usr_adds[$last_user]))
+						$usr_adds[$last_user] = 0;
+					if (!isset($usr_updates[$last_user]))
+						$usr_updates[$last_user] = 0;
+					if (!isset($usr_deletes[$last_user]))
+						$usr_deletes[$last_user] = 0;
+					if ($matches['mode'] == 'A') {
+						$usr_adds[$last_user]++;
+						$adds++;
+					} elseif ($matches['mode'] == 'M') {
+						$usr_updates[$last_user]++;
+						$updates++;
+					} elseif ($matches['mode'] == 'D') {
+						$usr_deletes[$last_user]++;
+						$deletes++;
 					}
 				}
 			}
+		}
 
-			// inserting group results in stats_cvs_groups
-			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,
-							     $deletes))) {
-					echo "Error while inserting into stats_cvs_group\n";
-					db_rollback();
-					return false;
-				}
+		// inserting group results in stats_cvs_groups
+		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, reponame)
+						VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
+						array($month_string,
+							$day,
+							$project->getID(),
+							0,
+							$commits,
+							$adds,
+							$updates,
+							$deletes,
+							$project_reponame))) {
+				echo "Error while inserting into stats_cvs_group\n";
+				db_rollback();
+				return false;
 			}
+		}
 
-			// building the user list
-			$user_list = array_unique(array_merge(array_keys($usr_adds), array_keys($usr_updates), array_keys($usr_deletes), array_keys($usr_commits)));
+		// building the user list
+		$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
-				$u = user_get_object_by_name($user);
-				if ($u) {
-					$user_id = $u->getID();
-				} else {
-					$res = db_query_params('SELECT user_id FROM users WHERE lower(realname)=$1 OR lower(email)=$2',
+		foreach ($user_list as $user) {
+			// Trying to get user id from user name or email
+			$u = user_get_object_by_name($user);
+			if ($u) {
+				$user_id = $u->getID();
+			} else {
+				$res = db_query_params('SELECT user_id FROM users WHERE lower(realname)=$1 OR lower(email)=$2',
 						array(strtolower($user), strtolower($user2email[$user])));
-					if ($res && db_numrows($res) > 0) {
-						$user_id = db_result($res, 0, 'user_id');
-					} else {
-						continue;
-					}
+				if ($res && db_numrows($res) > 0) {
+					$user_id = db_result($res, 0, 'user_id');
+				} else {
+					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;
-				$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,
-								     $ud))) {
-						echo "Error while inserting into stats_cvs_user\n";
-						db_rollback();
-						return false;
-					}
+			$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;
+			$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, reponame)
+									VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
+								array($month_string,
+									$day,
+									$project->getID(),
+									$user_id,
+									$uc,
+									$ua,
+									$uu,
+									$ud,
+									$project_reponame))) {
+					echo "Error while inserting into stats_cvs_user\n";
+					db_rollback();
+					return false;
 				}
 			}
 		}
diff --git a/src/plugins/scmhg/common/HgPlugin.class.php b/src/plugins/scmhg/common/HgPlugin.class.php
index e82ece6..eb00607 100644
--- a/src/plugins/scmhg/common/HgPlugin.class.php
+++ b/src/plugins/scmhg/common/HgPlugin.class.php
@@ -531,20 +531,22 @@ Offer DAV or SSH access.");
 				return false;
 			}
 			// cleaning stats_cvs_* table for the current day
-			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3',
+			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
 						array($month_string,
 							$day,
-							$project->getID()));
+							$project->getID(),
+							$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_group\n";
 				db_rollback();
 				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())) ;
+			$res = db_query_params('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+						array($month_string,
+							$day,
+							$project->getID(),
+							$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_user\n" ;
 				db_rollback () ;
@@ -596,7 +598,8 @@ Offer DAV or SSH access.");
 
 			// inserting group results in stats_cvs_groups
 			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)',
+				if (!db_query_params('INSERT INTO stats_cvs_group (month, day, group_id, checkouts, commits, adds, updates, deletes, reponame)
+								VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
 						      array($month_string,
 							     $day,
 							     $project->getID(),
@@ -604,7 +607,8 @@ Offer DAV or SSH access.");
 							     $commits,
 							     $adds,
 							     $updates,
-							     $deletes))) {
+							     $deletes,
+								$project->getUnixName()))) {
 					echo "Error while inserting into stats_cvs_group\n";
 					db_rollback();
 					return false;
@@ -634,7 +638,8 @@ Offer DAV or SSH access.");
 				$ua = isset($usr_adds[$user]) ? $usr_adds[$user] : 0;
 				$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)',
+					if (!db_query_params('INSERT INTO stats_cvs_user (month, day, group_id, user_id, commits, adds, updates, deletes, reponame)
+									VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
 							      array($month_string,
 								     $day,
 								     $project->getID(),
@@ -642,7 +647,8 @@ Offer DAV or SSH access.");
 								     $uc,
 								     $ua,
 								     $uu,
-								     $ud))) {
+								     $ud,
+									$project->getUnixName()))) {
 						echo "Error while inserting into stats_cvs_user\n";
 						db_rollback();
 						return false;
diff --git a/src/plugins/scmsvn/common/SVNPlugin.class.php b/src/plugins/scmsvn/common/SVNPlugin.class.php
index 1d0c742..4e0347e 100644
--- a/src/plugins/scmsvn/common/SVNPlugin.class.php
+++ b/src/plugins/scmsvn/common/SVNPlugin.class.php
@@ -399,20 +399,22 @@ some control over it to the project's administrator.");
 			$pipe = popen ("svn log file://$repo --xml -v -q -r '".'{'.$d2.'}:{'.$d1.'}'."' 2> /dev/null", 'r' ) ;
 
 			// cleaning stats_cvs_* table for the current day
-			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
+			$res = db_query_params('DELETE FROM stats_cvs_group WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
 				array($month_string,
 					$day,
-					$project->getID()));
+					$project->getID(),
+					$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_group\n";
 				db_rollback();
 				return false;
 			}
 
-			$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
-				array ($month_string,
+			$res = db_query_params('DELETE FROM stats_cvs_user WHERE month = $1 AND day = $2 AND group_id = $3 AND reponame = $4',
+				array($month_string,
 					$day,
-					$project->getID()));
+					$project->getID()
+					$project->getUnixName()));
 			if(!$res) {
 				echo "Error while cleaning stats_cvs_user\n" ;
 				db_rollback () ;
@@ -441,7 +443,8 @@ some control over it to the project's administrator.");
 
 			// inserting group results in stats_cvs_groups
 			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)',
+				if (!db_query_params('INSERT INTO stats_cvs_group (month, day, group_id, checkouts, commits, adds, updates, deletes, reponame)
+								VALUES ($1, $2, $3, $4, $5, $6, $7, $8)',
 					array($month_string,
 						$day,
 						$project->getID(),
@@ -449,7 +452,8 @@ some control over it to the project's administrator.");
 						$commits,
 						$adds,
 						$updates,
-						$deletes))) {
+						$deletes,
+						$project->getUnixName()))) {
 					echo "Error while inserting into stats_cvs_group\n";
 					db_rollback();
 					return false;
@@ -473,7 +477,8 @@ some control over it to the project's administrator.");
 				$ua = isset($usr_adds[$user]) ? $usr_adds[$user] : 0 ;
 				$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)',
+					if (!db_query_params('INSERT INTO stats_cvs_user (month, day, group_id, user_id, commits, adds, updates, deletes, reponame)
+									VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
 							      array ($month_string,
 								     $day,
 								     $project->getID(),
@@ -481,7 +486,8 @@ some control over it to the project's administrator.");
 								     $uc,
 								     $ua,
 								     $uu,
-								     $ud))) {
+								     $ud,
+									$project->getUnixName()))) {
 						echo "Error while inserting into stats_cvs_user\n";
 						db_rollback();
 						return false;

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

Summary of changes:
 src/db/20170811-scm-stats-reponame.sql            |  15 ++
 src/plugins/scmbzr/common/BzrPlugin.class.php     |  68 +++---
 src/plugins/scmcvs/common/CVSPlugin.class.php     |  30 ++-
 src/plugins/scmdarcs/common/DarcsPlugin.class.php | 245 ++++++++++---------
 src/plugins/scmgit/common/GitPlugin.class.php     | 277 ++++++++++++----------
 src/plugins/scmhg/common/HgPlugin.class.php       |  26 +-
 src/plugins/scmsvn/common/SVNPlugin.class.php     |  24 +-
 7 files changed, 373 insertions(+), 312 deletions(-)
 create mode 100644 src/db/20170811-scm-stats-reponame.sql


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list