initialize repository url on demand
authorTimo Savola <tsavola@movial.fi>
Thu, 10 Apr 2008 20:28:38 +0000 (23:28 +0300)
committerTimo Savola <tsavola@movial.fi>
Thu, 10 Apr 2008 20:28:38 +0000 (23:28 +0300)
matrix/components.py
matrix/repositories.py

index d7ce852..50b9663 100644 (file)
@@ -87,9 +87,6 @@ def init():
        packages = {}
 
        for c in config.components.itervalues():
-               c.repo.init()
-               c.meta.init()
-
                if not c.meta.exists():
                        c.meta.clone()
 
index 8268536..96629b6 100644 (file)
@@ -15,8 +15,8 @@ class Repository(object):
                self.path = path
                self.commits = commits
                self.exclude = exclude
-               self.url = None
-               self.hash = None
+               self.__url = None
+               self.__hash = None
 
        def __str__(self):
                return self.path
@@ -24,14 +24,18 @@ class Repository(object):
        def get_commit(self):
                return self.commits.get(config.board) or self.commits.get(None)
 
-       def init(self):
+       def get_url(self):
+               if self.__url is None:
+                       self.__url = self.__get_url()
+               return self.__url
+
+       def __get_url(self):
                if git.contains_database(self.path):
                        url = git.getvar(self.path, 'remote.origin.url')
                        if url:
-                               self.url = url
                                if config.debug:
-                                       print 'Using', self.url
-                               return
+                                       print 'Using', url
+                               return url
 
                for root in config.roots:
                        for suffix in ('.git', ''):
@@ -42,10 +46,9 @@ class Repository(object):
                                if not git.peek_remote(url, quiet=True):
                                        continue
 
-                               self.url = url
                                if config.debug:
                                        print 'Found', url
-                               return
+                               return url
 
                raise Error('Failed to locate repository: ' + self.name)
 
@@ -58,7 +61,7 @@ class Repository(object):
                if os.path.exists(self.path):
                        self.__clone_in_place()
                else:
-                       git.clone(self.path, self.url, checkout=False)
+                       git.clone(self.path, self.get_url(), checkout=False)
 
                if self.exclude:
                        git.exclude(self.path, self.exclude)
@@ -67,7 +70,7 @@ class Repository(object):
 
        def __clone_in_place(self):
                tmp = os.path.join(self.path, 'tmp')
-               git.clone(tmp, self.url, checkout=False)
+               git.clone(tmp, self.get_url(), checkout=False)
 
                try:
                        tmpdb = git.database_path(tmp)
@@ -117,9 +120,9 @@ class Repository(object):
                                remove_tree(path)
 
        def get_hash(self):
-               if not self.hash:
-                       self.hash = git.rev_parse(self.path, 'HEAD')
-               return self.hash
+               if not self.__hash:
+                       self.__hash = git.rev_parse(self.path, 'HEAD')
+               return self.__hash
 
        def describe(self):
                return git.describe(self.path)