Hi,

We have a recurring little issue on some git projects of our
fusionforge instance: in the "Repository History" panel of the scm
tab, the names of the contributors of the projects (with the counts of
"Adds" and "Updates") are sometimes wrong. #1 Some users may have less
contributions counted than the reality, #2 Some users may not be
listed at all, #3 some users are unduly attributed some commits.

A big part of these problems were solved by commits
1da92a5bb4f80f42df5d4cc03435d9641a771ee3 and
1a6dc7231c562105613e42a9eb2127878b9e5bf0.

There are still some cases where there are inaccuracies, and this is
particularly annoying in case #3 since project members are then
surprised to see an unknown commiter listed.

This is caused by the fact that the name/email of the commiter, as
recorded by git, is free text and may not match the Real Name / email
of the forge user. The code which tries to match git commiters to
forge users is located in function gatherStats, in
src/plugins/scmgit/common/GitPlugin.class.php

I tried to find some improvements to the matching logic and so far my
only idea has been to test restricting the matching to the members of
the project, rather than the whole forge user base. Doing this has
the following consequences:

- if the stats are computed daily along the life of the project, the
  list of members of the project has very high chance to match the
  list of commiters, except for cases where a git commiter is not a
  forge member or a project member at the time of the push.

- if the stats are later recomputed, the list of project members is
  the current one at the date of the re-computation, thus any past
  members of the project are ignored.

I tested such a modified gatherStats on a project started in January
2007, with 10721 commits. For both tests I recomputed the whole stats
history:

- With the original gatherStats version, 24 commiters are listed in
  the Repository History, totaling 3654 adds and 25264 updates. One of
  the commiter listed is not part at all of the project but has a
  forge user login name identical as the git user name of one of the
  commiter (their first-name in both cases)

- With the modified gatherStats restricted to project members, 16
  commiters are listed, totaling 3375 adds and 24013 updates. The
  erroneous commiter is not listed anymore, but also 7 commiters
  disappear, as they where once members of the project but are not
  anymore.

To summarize:

The fact that some project have erroneous commiters is quite annoying,
but the above solution has some drawbacks. What do you think about
that? Do you have other ideas to remove erroneous commiters?

I attach the patch to gatherStats though I'm not sure at all that it's
a good idea to apply it.

--
Matthieu

diff --git a/src/plugins/scmgit/common/GitPlugin.class.php b/src/plugins/scmgit/common/GitPlugin.class.php
index 8ef6b88..870994f 100644
--- a/src/plugins/scmgit/common/GitPlugin.class.php
+++ b/src/plugins/scmgit/common/GitPlugin.class.php
@@ -785,21 +785,22 @@ control over it to the project's administrator.");
 			// 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 ) ) );
 
+			$project_users = $project->getUsers(false, false);
 			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;
+				// try to match users on real name or email but only among project users
+				$foundmatch = false;
+				foreach ($project_users as $pr_user) {
+					if (strtolower($user) == strtolower($pr_user->getRealName())
+						|| strtolower($user2email[$user]) == strtolower($pr_user->getEmail())
+						|| strtolower($user) == strtolower($pr_user->getUnixName())) {
+						$user_id = $pr_user->getID();
+						$foundmatch = true;
+						break;
 					}
 				}
-
+				if (! $foundmatch) {
+					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;
_______________________________________________
Fusionforge-general mailing list
Fusionforge-general@lists.fusionforge.org
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-general

Reply via email to