incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#6272] Re-added file size on SCM log view and added extended tests of indexless log
Date Fri, 14 Jun 2013 14:15:27 GMT
Updated Branches:
  refs/heads/cj/6272 8a0833e56 -> ba62f4da1


[#6272] Re-added file size on SCM log view and added extended tests of indexless log

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/ba62f4da
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/ba62f4da
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/ba62f4da

Branch: refs/heads/cj/6272
Commit: ba62f4da154673fea9545632fd82e0666f5e6cb9
Parents: 8a0833e
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Jun 14 14:15:08 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Jun 14 14:15:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py         |  3 +-
 Allura/allura/model/repository.py               |  6 ++
 Allura/allura/templates/widgets/repo/log.html   |  7 +-
 ForgeGit/forgegit/model/git_repo.py             | 18 ++++
 .../forgegit/tests/model/test_repository.py     | 85 ++++++++++++++++-
 ForgeSVN/forgesvn/model/svn.py                  | 20 +++-
 .../forgesvn/tests/model/test_repository.py     | 98 +++++++++++++++++++-
 7 files changed, 223 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index e8848eb..4f6122d 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -475,8 +475,7 @@ class CommitBrowser(BaseController):
     def log(self, limit=25, path=None, **kw):
         is_file = False
         if path:
-            path = path.lstrip('/')
-            is_file = self.tree._tree.get_blob_by_path(path) is not None
+            is_file = c.app.repo.is_file(path, self._commit._id)
         commits = list(islice(c.app.repo.log(
                 revs=self._commit._id,
                 path=path,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 6916bec..aefbdca 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -179,6 +179,10 @@ class RepositoryImplementation(object):
         '''Determine if the repository is empty by checking the filesystem'''
         raise NotImplementedError, 'is_empty'
 
+    def is_file(self, path, rev=None):
+        '''Determine if the repository is a file by checking the filesystem'''
+        raise NotImplementedError, 'is_file'
+
     @classmethod
     def shorthand_for_commit(cls, oid):
         return '[%s]' % oid[:6]
@@ -349,6 +353,8 @@ class Repository(Artifact, ActivityObject):
         return self._impl.last_commit_ids(commit, paths)
     def is_empty(self):
         return self._impl.is_empty()
+    def is_file(self, path, rev=None):
+        return self._impl.is_file(path, rev)
     def get_heads(self):
         """
         Return list of heads for the repo.

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/Allura/allura/templates/widgets/repo/log.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/repo/log.html b/Allura/allura/templates/widgets/repo/log.html
index 840ebb2..69d7129 100644
--- a/Allura/allura/templates/widgets/repo/log.html
+++ b/Allura/allura/templates/widgets/repo/log.html
@@ -35,9 +35,9 @@
         <tr class="rev">
           <td>
             <div>
-                {%if is_file%}
+                {%if is_file %}
                     <div class="grid-1"><input type="checkbox" class="revision"
revision="{{commit.id}}" url_commit="{{app.repo.url_for_commit(commit.id)}}"></div>
-                {%endif%}
+                {% endif %}
                 <a class="rev" href="{{app.repo.url_for_commit(commit.id)}}">{{app.repo.shorthand_for_commit(commit.id)}}</a>
                 {% if commit.refs -%}
                     (
@@ -46,6 +46,9 @@
                     {%- endfor -%}
                     )
                 {%- endif %}
+                {%if is_file %}
+                    ({{ commit.size|filesizeformat if commit.size else 'None' }})
+                {% endif %}
                 by {{ user_link(commit.authored.email, commit.authored.name) }}
                 {%- if commit.committed.email != commit.authored.email %},
                 pushed by {{ user_link(commit.committed.email, commit.committed.name) }}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 2220260..4a8b10a 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -288,6 +288,7 @@ class GitImplementation(M.RepositoryImplementation):
         If id_only is True, returns only the commit ID, otherwise it returns
         detailed information about each commit.
         """
+        path = path.strip('/') if path else None
         if exclude is not None:
             revs.extend(['^%s' % e for e in exclude])
 
@@ -295,6 +296,13 @@ class GitImplementation(M.RepositoryImplementation):
             if id_only:
                 yield ci.hexsha
             else:
+                size = None
+                if path:
+                    try:
+                        node = ci.tree/path
+                        size = node.size if node.type == 'blob' else None
+                    except KeyError as e:
+                        size = None
                 yield {
                         'id': ci.hexsha,
                         'message': h.really_unicode(ci.message or '--none--'),
@@ -310,6 +318,7 @@ class GitImplementation(M.RepositoryImplementation):
                             },
                         'refs': refs,
                         'parents': [pci.hexsha for pci in ci.parents],
+                        'size': size,
                     }
 
     def _iter_commits_with_refs(self, *args, **kwargs):
@@ -399,6 +408,15 @@ class GitImplementation(M.RepositoryImplementation):
     def is_empty(self):
         return not self._git or len(self._git.heads) == 0
 
+    def is_file(self, path, rev=None):
+        path = path.strip('/')
+        ci = self._git.rev_parse(rev)
+        try:
+            node = ci.tree/path
+            return node.type == 'blob'
+        except KeyError as e:
+            return False
+
     @LazyProperty
     def head(self):
         return self._git.head.commit.hexsha

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 0bbd6c2..dba95ae 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -219,10 +219,89 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         i = self.repo.index()
         assert i['type_s'] == 'Git Repository', i
 
+    def test_log_id_only(self):
+        entries = list(self.repo.log(id_only=True))
+        assert_equal(entries, [
+            '1e146e67985dcd71c74de79613719bef7bddca4a',
+            'df30427c488aeab84b2352bdf88a3b19223f9d7a',
+            '6a45885ae7347f1cac5103b0050cc1be6a1496c8',
+            '9a7df788cf800241e3bb5a849c8870f2f8259d98'])
+
     def test_log(self):
-        for entry in self.repo.log(id_only=False):
-            assert str(entry['authored'])
-            assert entry['message']
+        entries = list(self.repo.log(id_only=False))
+        assert_equal(entries, [
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': '1e146e67985dcd71c74de79613719bef7bddca4a',
+             'message': u'Change README\n',
+             'parents': ['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
+             'refs': ['HEAD', 'foo', 'master'],
+             'size': None},
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': 'df30427c488aeab84b2352bdf88a3b19223f9d7a',
+             'message': u'Add README\n',
+             'parents': ['6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
+             'refs': [],
+             'size': None},
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 43, 26),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 43, 26),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': '6a45885ae7347f1cac5103b0050cc1be6a1496c8',
+             'message': u'Remove file\n',
+             'parents': ['9a7df788cf800241e3bb5a849c8870f2f8259d98'],
+             'refs': [],
+             'size': None},
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 42, 54),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 42, 54),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': '9a7df788cf800241e3bb5a849c8870f2f8259d98',
+             'message': u'Initial commit\n',
+             'parents': [],
+             'refs': [],
+             'size': None},
+            ])
+
+    def test_log_file(self):
+        entries = list(self.repo.log(path='README', id_only=False))
+        assert_equal(entries, [
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': '1e146e67985dcd71c74de79613719bef7bddca4a',
+             'message': u'Change README\n',
+             'parents': ['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
+             'refs': ['HEAD', 'foo', 'master'],
+             'size': 28},
+            {'authored': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
+                          'email': u'rcopeland@geek.net',
+                          'name': u'Rick Copeland'},
+             'committed': {'date': datetime.datetime(2010, 10, 7, 18, 44, 1),
+                           'email': u'rcopeland@geek.net',
+                           'name': u'Rick Copeland'},
+             'id': 'df30427c488aeab84b2352bdf88a3b19223f9d7a',
+             'message': u'Add README\n',
+             'parents': ['6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
+             'refs': [],
+             'size': 15},
+            ])
 
     def test_commit(self):
         entry = self.repo.commit('HEAD')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 82b31b9..dcb08e0 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -512,7 +512,7 @@ class SVNImplementation(M.RepositoryImplementation):
         if path is None:
             url = self._url
         else:
-            url = '/'.join([self._url, path])
+            url = '/'.join([self._url, path.strip('/')])
         while revno > exclude:
             rev = pysvn.Revision(pysvn.opt_revision_kind.number, revno)
             try:
@@ -527,13 +527,17 @@ class SVNImplementation(M.RepositoryImplementation):
                 if id_only:
                     yield ci.revision.number
                 else:
-                    yield self._map_log(ci)
+                    yield self._map_log(ci, url)
             if len(logs) < page_size:
                 return  # we didn't get a full page, don't bother calling SVN again
             revno = ci.revision.number - 1
 
-    def _map_log(self, ci):
+    def _map_log(self, ci, url):
         revno = ci.revision.number
+        try:
+            size = int(self._svn.list(url)[0][0].size)
+        except pysvn.ClientError as e:
+            size = None
         return {
                 'id': revno,
                 'message': h.really_unicode(ci.get('message', '--none--')),
@@ -549,6 +553,7 @@ class SVNImplementation(M.RepositoryImplementation):
                     },
                 'refs': ['HEAD'] if revno == self.head else [],
                 'parents': [revno-1] if revno > 1 else [],
+                'size': size,
             }
 
     def open_blob(self, blob):
@@ -717,6 +722,15 @@ class SVNImplementation(M.RepositoryImplementation):
     def is_empty(self):
         return self.head == 0
 
+    def is_file(self, path, rev=None):
+        url = '/'.join([self._url, path.strip('/')])
+        rev = pysvn.Revision(pysvn.opt_revision_kind.number, self._revno(self.rev_parse(rev)))
+        try:
+            info = self._svn.list(url, revision=rev, dirent_fields=pysvn.SVN_DIRENT_KIND)[0][0]
+            return info.kind == pysvn.node_kind.file
+        except pysvn.ClientError:
+            return False
+
     def symbolics_for_commit(self, commit):
         return [], []
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/ba62f4da/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index dfde637..537e067 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -220,10 +220,100 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         i = self.repo.index()
         assert i['type_s'] == 'SVN Repository', i
 
+    def test_log_id_only(self):
+        entries = list(self.repo.log(id_only=True))
+        assert_equal(entries, [5, 4, 3, 2, 1])
+
     def test_log(self):
-        for entry in self.repo.log(id_only=False):
-            assert entry['committed']['name'] == 'rick446'
-            assert entry['message']
+        entries = list(self.repo.log(id_only=False))
+        assert_equal(entries, [
+            {'authored': {'date': datetime(2010, 11, 18, 20, 14, 21, 515743),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 11, 18, 20, 14, 21, 515743),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 5,
+             'message': u'Copied a => b',
+             'parents': [4],
+             'refs': ['HEAD'],
+             'size': 0},
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 59, 383719),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 59, 383719),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 4,
+             'message': u'Remove hello.txt',
+             'parents': [3],
+             'refs': [],
+             'size': 0},
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 48, 272296),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 48, 272296),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 3,
+             'message': u'Modify readme',
+             'parents': [2],
+             'refs': [],
+             'size': 0},
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 36, 221863),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 36, 221863),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 2,
+             'message': u'Add path',
+             'parents': [1],
+             'refs': [],
+             'size': 0},
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 7, 238375),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 7, 238375),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 1,
+             'message': u'Create readme',
+             'parents': [],
+             'refs': [],
+             'size': 0},
+            ])
+
+    def test_log_file(self):
+        entries = list(self.repo.log(path='/README', id_only=False))
+        assert_equal(entries, [
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 48, 272296),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 48, 272296),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 3,
+             'message': u'Modify readme',
+             'parents': [2],
+             'refs': [],
+             'size': 28},
+            {'authored': {'date': datetime(2010, 10, 8, 15, 32, 7, 238375),
+                          'email': '',
+                          'name': u'rick446'},
+             'committed': {'date': datetime(2010, 10, 8, 15, 32, 7, 238375),
+                           'email': '',
+                           'name': u'rick446'},
+             'id': 1,
+             'message': u'Create readme',
+             'parents': [],
+             'refs': [],
+             'size': 28},
+            ])
+
+    def test_is_file(self):
+        assert self.repo.is_file('/README')
+        assert not self.repo.is_file('/a')
 
     def test_paged_diffs(self):
         entry = self.repo.commit(self.repo.log(2, id_only=True).next())
@@ -781,7 +871,7 @@ class TestMergeRequest(_TestWithRepoAndCommit):
             assert_equal(_svn().log.call_args[0], ('file:///tmp/svn/p/test/test2',))
             assert_equal(_svn().log.call_args[1]['revision_start'].number, 2)
             assert_equal(_svn().log.call_args[1]['limit'], 25)
-            _map_log.assert_called_once_with(_svn().log.return_value[0])
+            _map_log.assert_called_once_with(_svn().log.return_value[0], 'file:///tmp/svn/p/test/test2')
 
 class TestRepoObject(_TestWithRepoAndCommit):
 


Mime
View raw message