incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [04/13] git commit: [#6212] Support config option to disable counting lines-of-code
Date Tue, 14 May 2013 18:03:33 GMT
[#6212] Support config option to disable counting lines-of-code

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/c7d03b33
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c7d03b33
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c7d03b33

Branch: refs/heads/cj/5571
Commit: c7d03b33a30f9d9ed474b41773ee4240e1fae47c
Parents: 9912f31
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon May 13 20:44:53 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon May 13 21:56:19 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/stats.py                      |   28 ++++++++-------
 ForgeUserStats/forgeuserstats/tests/test_model.py |   30 ++++++++++++++++
 2 files changed, 45 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c7d03b33/Allura/allura/model/stats.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/stats.py b/Allura/allura/model/stats.py
index 166933e..3946557 100644
--- a/Allura/allura/model/stats.py
+++ b/Allura/allura/model/stats.py
@@ -20,6 +20,7 @@ import pymongo
 from pylons import tmpl_context as c, app_globals as g
 from pylons import request
 from tg import config
+from paste.deploy.converters import asbool
 
 import bson
 from ming import schema as S
@@ -501,19 +502,20 @@ class Stats(MappedClass):
             oldcommit = newcommit.repo.commit(newcommit.parent_ids[0])
 
         totlines = 0
-        for changed in d.changed:
-            newblob = newcommit.tree.get_blob_by_path(changed)
-            oldblob = oldcommit.tree.get_blob_by_path(changed)
-            totlines+=_computeLines(newblob, oldblob)
-
-        for copied in d.copied:
-            newblob = newcommit.tree.get_blob_by_path(copied['new'])
-            oldblob = oldcommit.tree.get_blob_by_path(copied['old'])
-            totlines+=_computeLines(newblob, oldblob)
-
-        for added in d.added:
-            newblob = newcommit.tree.get_blob_by_path(added)
-            totlines+=_computeLines(newblob)
+        if asbool(config.get('userstats.count_lines_of_code', True)):
+            for changed in d.changed:
+                newblob = newcommit.tree.get_blob_by_path(changed)
+                oldblob = oldcommit.tree.get_blob_by_path(changed)
+                totlines+=_computeLines(newblob, oldblob)
+
+            for copied in d.copied:
+                newblob = newcommit.tree.get_blob_by_path(copied['new'])
+                oldblob = oldcommit.tree.get_blob_by_path(copied['old'])
+                totlines+=_computeLines(newblob, oldblob)
+
+            for added in d.added:
+                newblob = newcommit.tree.get_blob_by_path(added)
+                totlines+=_computeLines(newblob)
 
         _addCommitData(self, topics, languages, totlines)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c7d03b33/ForgeUserStats/forgeuserstats/tests/test_model.py
----------------------------------------------------------------------
diff --git a/ForgeUserStats/forgeuserstats/tests/test_model.py b/ForgeUserStats/forgeuserstats/tests/test_model.py
index 2da99e1..dd77b32 100644
--- a/ForgeUserStats/forgeuserstats/tests/test_model.py
+++ b/ForgeUserStats/forgeuserstats/tests/test_model.py
@@ -21,6 +21,7 @@ from datetime import datetime, timedelta
 
 from pylons import tmpl_context as c
 from tg import config
+import mock
 
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.tests import decorators as td
@@ -400,3 +401,32 @@ class TestUserStats(unittest.TestCase):
             self.assertEqual(stats.start_date, datetime(2013,04,01))
         with h.push_config(config, **{'userstats.start_date': '2011-04-01'}):
             self.assertEqual(stats.start_date, datetime(2012,04,01))
+
+    @mock.patch('allura.model.stats.difflib.unified_diff')
+    def test_count_loc(self, unified_diff):
+        stats = USM.UserStats()
+        newcommit = mock.Mock(
+                parent_ids=['deadbeef'],
+                diffs=mock.Mock(
+                    changed=[mock.MagicMock()],
+                    copied=[mock.MagicMock()],
+                    added=[mock.MagicMock()],
+                ),
+            )
+        unified_diff.return_value = ['+++','---','+line']
+        newcommit.tree.get_blob_by_path.return_value = mock.MagicMock()
+        newcommit.tree.get_blob_by_path.return_value.__iter__.return_value = ['one']
+        newcommit.repo.commit().tree.get_blob_by_path.return_value = mock.MagicMock()
+        newcommit.repo.commit().tree.get_blob_by_path.return_value.__iter__.return_value
= ['two']
+        commit_datetime = datetime.now()
+        project = mock.Mock(
+                trove_topic=[],
+                trove_language=[],
+            )
+        stats.addCommit(newcommit, commit_datetime, project)
+        self.assertEqual(stats.general[0].commits[0], {'lines': 3, 'number': 1, 'language':
None})
+        unified_diff.reset_mock()
+        with h.push_config(config, **{'userstats.count_lines_of_code': 'false'}):
+            stats.addCommit(newcommit, commit_datetime, project)
+        self.assertEqual(stats.general[0].commits[0], {'lines': 3, 'number': 2, 'language':
None})
+        unified_diff.assert_not_called()


Mime
View raw message