[jhbuild] support for a local DVCS mirror



commit 2ec6ea102e04f18efde12290700d221fd367a85f
Author: Frederic Peters <fpeters 0d be>
Date:   Fri Apr 24 17:19:53 2009 +0200

    support for a local DVCS mirror
    
    Add a new option (dvcs_mirror_dir) that can be set to hold a mirror of
    a DVCS repository (git only at the moment), so local clones are used,
    instead of clones of the real remote server; thus saving space for
    people with multiple JHBuild checkout dirs. (GNOME #575809)
---
 jhbuild/config.py             |    2 +-
 jhbuild/defaults.jhbuildrc    |    3 +++
 jhbuild/versioncontrol/git.py |   36 +++++++++++++++++++++++++++++++++---
 3 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/jhbuild/config.py b/jhbuild/config.py
index d720119..3e9ec71 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -47,7 +47,7 @@ _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'jhbuildbot_master', 'jhbuildbot_slavename', 'jhbuildbot_password',
                 'jhbuildbot_svn_commits_box',
                 'use_local_modulesets', 'ignore_suggests', 'modulesets_dir',
-                'mirror_policy', 'module_mirror_policy',
+                'mirror_policy', 'module_mirror_policy', 'dvcs_mirror_dir',
                 ]
 
 env_prepends = {}
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index 2965dbc..ca2a3bc 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -144,3 +144,6 @@ use_local_modulesets = False
 
 # whether to ignore soft dependencies
 ignore_suggests = False
+
+# local directory for DVCS mirror (git only atm)
+dvcs_mirror_dir = None
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index bad1b5f..cc4c966 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -74,6 +74,11 @@ class GitRepository(Repository):
                revision = None, tag = None):
         if module is None:
             module = name
+
+        mirror_module = None
+        if self.config.dvcs_mirror_dir:
+            mirror_module = os.path.join(self.config.dvcs_mirror_dir, module)
+
         # allow remapping of branch for module
         if name in self.config.branches:
             try:
@@ -83,9 +88,14 @@ class GitRepository(Repository):
             else:
                 if new_module:
                     module = new_module
-        if not urlparse.urlparse(module)[0]:
+        if not (urlparse.urlparse(module)[0] or module[0] == '/'):
             module = urlparse.urljoin(self.href, module)
-        return GitBranch(self, module, subdir, checkoutdir, revision, tag)
+
+        if mirror_module:
+            return GitBranch(self, mirror_module, subdir, checkoutdir,
+                    revision, tag, unmirrored_module=module)
+        else:
+            return GitBranch(self, module, subdir, checkoutdir, revision, tag)
 
     def to_sxml(self):
         return [sxml.repository(type='git', name=self.name, href=self.href)]
@@ -94,11 +104,13 @@ class GitRepository(Repository):
 class GitBranch(Branch):
     """A class representing a GIT branch."""
 
-    def __init__(self, repository, module, subdir, checkoutdir=None, branch=None, tag=None):
+    def __init__(self, repository, module, subdir, checkoutdir=None,
+                 branch=None, tag=None, unmirrored_module=None):
         Branch.__init__(self, repository, module, checkoutdir)
         self.subdir = subdir
         self.branch = branch
         self.tag = tag
+        self.unmirrored_module = unmirrored_module
 
     def srcdir(self):
         path_elements = [self.checkoutroot]
@@ -182,6 +194,20 @@ class GitBranch(Branch):
             cmd = ['git', 'submodule', 'update']
             buildscript.execute(cmd, cwd=self.srcdir)
 
+    def update_dvcs_mirror(self, buildscript):
+        if not self.config.dvcs_mirror_dir:
+            return
+
+        mirror_dir = os.path.join(self.config.dvcs_mirror_dir,
+                os.path.basename(self.module) + '.git')
+
+        if os.path.exists(mirror_dir):
+            buildscript.execute(['git', 'fetch'], cwd=mirror_dir)
+        else:
+            buildscript.execute(
+                    ['git', 'clone', '--mirror', self.unmirrored_module],
+                    cwd=self.config.dvcs_mirror_dir)
+
     def _checkout(self, buildscript, copydir=None):
 
         if self.config.quiet_mode:
@@ -189,6 +215,8 @@ class GitBranch(Branch):
         else:
             quiet = []
 
+        self.update_dvcs_mirror(buildscript)
+
         cmd = ['git', 'clone'] + quiet + [self.module]
         if self.checkoutdir:
             cmd.append(self.checkoutdir)
@@ -220,6 +248,8 @@ class GitBranch(Branch):
         else:
             quiet = []
 
+        self.update_dvcs_mirror(buildscript)
+
         stashed = False
         if get_output(['git', 'diff'], cwd=cwd):
             stashed = True



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]