incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#6083] Improved empty repo checking
Date Fri, 19 Apr 2013 21:05:24 GMT
Updated Branches:
  refs/heads/cj/6083 47dc023b9 -> 936cb8323 (forced update)


[#6083] Improved empty repo checking

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

Branch: refs/heads/cj/6083
Commit: 936cb8323fcab37071292d53a31ef5195f65e9ab
Parents: 4ac36f9
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Apr 19 20:47:52 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Apr 19 21:05:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py                |    6 ++++++
 ForgeGit/forgegit/controllers.py                 |    5 +++--
 ForgeGit/forgegit/model/git_repo.py              |    3 +++
 ForgeGit/forgegit/templates/git/index.html       |    8 +++++++-
 ForgeGit/forgegit/tests/model/test_repository.py |   16 ++++++++++++++++
 ForgeSVN/forgesvn/controllers.py                 |    5 +++--
 ForgeSVN/forgesvn/model/svn.py                   |    3 +++
 ForgeSVN/forgesvn/templates/svn/index.html       |    8 +++++++-
 ForgeSVN/forgesvn/tests/model/test_repository.py |   16 ++++++++++++++++
 requirements-common.txt                          |    2 ++
 requirements-sf.txt                              |    2 +-
 11 files changed, 67 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 793f411..cae4ce0 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -163,6 +163,10 @@ class RepositoryImplementation(object):
             commit = parent
         return result
 
+    def is_empty(self):
+        '''Determine if the repository is empty by checking the filesystem'''
+        raise NotImplementedError, 'is_empty'
+
     @classmethod
     def shorthand_for_commit(cls, oid):
         return '[%s]' % oid[:6]
@@ -342,6 +346,8 @@ class Repository(Artifact, ActivityObject):
         return self._impl.commits_count(path, rev)
     def last_commit_ids(self, commit, paths):
         return self._impl.last_commit_ids(commit, paths)
+    def is_empty(self):
+        return self._impl.is_empty()
 
     def _log(self, rev, skip, limit):
         head = self.commit(rev)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeGit/forgegit/controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/controllers.py b/ForgeGit/forgegit/controllers.py
index b3fdd5d..320cc9b 100644
--- a/ForgeGit/forgegit/controllers.py
+++ b/ForgeGit/forgegit/controllers.py
@@ -26,8 +26,9 @@ class BranchBrowser(repository.BranchBrowser):
     @expose('jinja:forgegit:templates/git/index.html')
     @with_trailing_slash
     def index(self, limit=None, page=0, count=0, **kw):
+        is_empty = c.app.repo.is_empty()
         latest = c.app.repo.latest(branch=self._branch)
-        if not latest:
-            return dict(allow_fork=False, log=[])
+        if is_empty or not latest:
+            return dict(allow_fork=False, log=[], is_empty=is_empty)
         redirect(c.app.repo._impl.url_for_symbolic(latest._id) + 'tree/')
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index c47589a..296430f 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -355,6 +355,9 @@ class GitImplementation(M.RepositoryImplementation):
             if os.path.exists(tmpfilename):
                 os.remove(tmpfilename)
 
+    def is_empty(self):
+        return len(self._git.heads) == 0
+
 
 class _OpenedGitBlob(object):
     CHUNK_SIZE=4096

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeGit/forgegit/templates/git/index.html
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/templates/git/index.html b/ForgeGit/forgegit/templates/git/index.html
index 99881ae..4276e65 100644
--- a/ForgeGit/forgegit/templates/git/index.html
+++ b/ForgeGit/forgegit/templates/git/index.html
@@ -37,7 +37,7 @@
     {% if int(count) > int(limit) %}
       <a href="log?page=1">More</a>
     {% endif %}
-  {% elif c.app.repo.status == 'ready' %}
+  {% elif is_empty %}
     {% if h.has_access(c.app, 'write')() %}
     <div class="message warning scm-learn-basics">
       <div class="content">
@@ -84,5 +84,11 @@ git branch --set-upstream master origin/master  # so 'git pull' will work
later<
     {% else %}
     <p><b>No (more) commits</b></p>
     {% endif %}
+  {% elif c.app.repo.status == 'ready' %}
+    {% if h.has_access(c.app, 'write')() %}
+    <p>The metadata for this repository is to be missing.  Please try <a href="{{c.app.url}}refresh">refreshing</a>
to correct this.</p>
+    {% else %}
+    <p><b>No (more) commits</b></p>
+    {% endif %}
   {% endif %}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/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 41c48fd..18de668 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -27,6 +27,7 @@ import tg
 from ming.base import Object
 from ming.orm import ThreadLocalORMSession, session
 from nose.tools import assert_equal
+from testfixtures import TempDirectory
 
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura.lib import helpers as h
@@ -307,6 +308,21 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         os.makedirs("/tmp/tarball/git/t/te/test/testgit.git/test-src-git-HEAD")
         assert_equal(self.repo.get_tarball_status('HEAD'), None)
 
+    def test_is_empty(self):
+        assert not self.repo.is_empty()
+        with TempDirectory() as d:
+            repo2 = GM.Repository(
+                name='test',
+                fs_path=d.path,
+                url_path = '/test/',
+                tool = 'git',
+                status = 'creating')
+            repo2.init()
+            assert repo2.is_empty()
+            repo2.refresh()
+            ThreadLocalORMSession.flush_all()
+            assert repo2.is_empty()
+
 
 class TestGitCommit(unittest.TestCase):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeSVN/forgesvn/controllers.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/controllers.py b/ForgeSVN/forgesvn/controllers.py
index 156b13a..b14c134 100644
--- a/ForgeSVN/forgesvn/controllers.py
+++ b/ForgeSVN/forgesvn/controllers.py
@@ -30,9 +30,10 @@ class BranchBrowser(repository.BranchBrowser):
     @expose('jinja:forgesvn:templates/svn/index.html')
     @with_trailing_slash
     def index(self, limit=None, page=0, count=0, **kw):
+        is_empty = c.app.repo.is_empty()
         latest = c.app.repo.latest(branch=self._branch)
-        if not latest:
-            return dict(allow_fork=False, log=[])
+        if empty or not latest:
+            return dict(allow_fork=False, log=[], is_empty=is_empty)
         redirect(c.app.repo._impl.url_for_symbolic(latest._id) + 'tree/')
 
     @expose()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index b4c354d..1224f9c 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -666,5 +666,8 @@ class SVNImplementation(M.RepositoryImplementation):
             if os.path.exists(tmpfilename):
                 os.remove(tmpfilename)
 
+    def is_empty(self):
+        return self._svn.revpropget('revision', url=self._url)[0].number == 0
+
 
 Mapper.compile_all()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/ForgeSVN/forgesvn/templates/svn/index.html
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/templates/svn/index.html b/ForgeSVN/forgesvn/templates/svn/index.html
index ed80fb9..47db43e 100644
--- a/ForgeSVN/forgesvn/templates/svn/index.html
+++ b/ForgeSVN/forgesvn/templates/svn/index.html
@@ -37,7 +37,7 @@
     {% if count > limit %}
       <a href="{{c.app.url}}log?page=1">More</a>
     {% endif %}
-  {% elif c.app.repo.status == 'ready' %}
+  {% elif is_empty %}
     {% if h.has_access(c.app, 'write')() %}
     <div class="message warning scm-learn-basics">
       <div class="content">
@@ -93,5 +93,11 @@ svn import {{c.app.repo.clone_url('rw', c.user.username)}} -m "Initial
commit"</
     {% else %}
     <p><b>No (more) commits</b></p>
     {% endif %}
+  {% elif c.app.repo.status == 'ready' %}
+    {% if h.has_access(c.app, 'write')() %}
+    <p>The metadata for this repository is to be missing.  Please try <a href="{{c.app.url}}refresh">refreshing</a>
to correct this.</p>
+    {% else %}
+    <p><b>No (more) commits</b></p>
+    {% endif %}
   {% endif %}
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/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 1f93dfd..e8fb14e 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -30,6 +30,7 @@ import tg
 import ming
 from ming.base import Object
 from ming.orm import session, ThreadLocalORMSession
+from testfixtures import TempDirectory
 
 from alluratest.controller import setup_basic_test, setup_global_objects
 from allura import model as M
@@ -292,6 +293,21 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         self.repo.tarball('1')
         assert os.path.isfile("/tmp/tarball/svn/t/te/test/testsvn/test-src-1.tar.gz")
 
+    def test_is_empty(self):
+        assert not self.repo.is_empty()
+        with TempDirectory() as d:
+            repo2 = SM.Repository(
+                name='test',
+                fs_path=d.path,
+                url_path = '/test/',
+                tool = 'svn',
+                status = 'creating')
+            repo2.init()
+            assert repo2.is_empty()
+            repo2.refresh()
+            ThreadLocalORMSession.flush_all()
+            assert repo2.is_empty()
+
 class TestSVNRev(unittest.TestCase):
 
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/requirements-common.txt
----------------------------------------------------------------------
diff --git a/requirements-common.txt b/requirements-common.txt
index e072ad9..4dcf695 100644
--- a/requirements-common.txt
+++ b/requirements-common.txt
@@ -76,3 +76,5 @@ nose==1.1.2
 pyflakes==0.5.0
 WebTest==1.4.0
 clonedigger==1.1.0
+testfixtures==3.0.0
+q==2.3

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/936cb832/requirements-sf.txt
----------------------------------------------------------------------
diff --git a/requirements-sf.txt b/requirements-sf.txt
index 628e1e8..0fc28a6 100644
--- a/requirements-sf.txt
+++ b/requirements-sf.txt
@@ -4,7 +4,7 @@ akismet==0.2.0
 amqplib==0.6.1
 kombu==1.0.4
 coverage==3.5a1-20110413
-ForgeHg==0.1.6
+ForgeHg==0.1.7
 ForgePastebin==0.2.6
 mechanize==0.2.4
 MySQL-python==1.2.3c1


Mime
View raw message