commit:     a4ce4f5a312c08eb90ccb741f673780b8559d0c4
Author:     Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Fri May 23 21:33:47 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Jun 12 21:11:49 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=a4ce4f5a

git.py: adds update() function

Moves the fix_git_source() function to allow both add() and update()
to make use of it. While the update() function calls git remote
set-url, replacing the old url with the new url provided by
overlay.update().

---
 layman/overlays/git.py | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/layman/overlays/git.py b/layman/overlays/git.py
index f3790ca..ee8c53b 100644
--- a/layman/overlays/git.py
+++ b/layman/overlays/git.py
@@ -46,21 +46,24 @@ class GitOverlay(OverlaySource):
             _location, ignore)
         self.subpath = None
 
+    def _fix_git_source(self, source):
+    '''
+    Adds trailing slash to http sources
+
+    @param source: source URL, string.
+    '''
+        # http:// should get trailing slash, other protocols shouldn't
+        if source.split(':')[:1] == 'http':
+            if not source.endswith('/'):
+                return source + '/'
+        return source
+
     def add(self, base):
         '''Add overlay.'''
 
         if not self.supported():
             return 1
 
-        def fix_git_source(source):
-            # http:// should get trailing slash, other protocols shouldn't
-            if source.split(':')[0] == 'http':
-                if source.endswith('/'):
-                    return source
-                else:
-                    return source + '/'
-            return source
-
         cfg_opts = self.config["git_addopts"]
         target = path([base, self.parent.name])
 
@@ -70,7 +73,7 @@ class GitOverlay(OverlaySource):
             args.append('-q')
         if len(cfg_opts):
             args.append(cfg_opts)
-        args.append(fix_git_source(self.src))
+        args.append(self._fix_git_source(self.src))
         args.append(target)
         success = False
         # adding cwd=base due to a new git bug in selinux due to
@@ -95,6 +98,21 @@ class GitOverlay(OverlaySource):
         self.output.debug("set git user info...args=%s" % ' '.join(args), 8)
         return self.run_command(self.command(), args, cmd=self.type, 
cwd=target)
 
+    def update(self, base, src):
+        '''
+        Update overlay src-url
+        
+        @params base: base location where all overlays are installed.
+        @params src:  source URL.
+        '''
+        self.output.debug("git.update(); starting...%s" % self.parent.name, 6)
+        target = path([base, self.parent.name])
+
+        # git remote set-url <name> <newurl> <oldurl>
+        args = ['remote', 'set-url', 'origin', self._fix_git_source(src), 
self._fix_git_source(self.src)]
+
+        return self.run_command(self.command(), args, cmd=self.type, 
cwd=target)
+
     def sync(self, base):
         '''Sync overlay.'''
 

Reply via email to