Support for 'upstream' repositories refactored.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Sun, 04 Dec 2016 22:21:22 +0000
changeset 88 112075e99cef
parent 87 a4637233f94f
child 89 3fae142744f4
Support for 'upstream' repositories refactored. Each repository (factory) may define a 'staging' and an 'uptream' repository. A 'canonical' repository is mandatory. When checking out and/or updating, first changes from 'staging' are pulled, then from 'upstream' and at last from 'canonical repository'. Mercurial paths are defined. Repository sets updated accordingly.
rakelib/rbspec.rb
rakelib/scm.rb
rakelib/support.rb
rakelib/workflow.rake
specs/repositories.rbspec
--- a/rakelib/rbspec.rb	Sun Nov 27 22:57:33 2016 +0000
+++ b/rakelib/rbspec.rb	Sun Dec 04 22:21:22 2016 +0000
@@ -531,18 +531,6 @@
     def accept_visitor(visitor)
       return visitor.visit_repository(self)
     end
-
-    def upstream(value = '**token**')
-      if value != '**token**' then
-        self._set_property(:upstream, value)
-      else
-        if self.property_defined?(:upstream)
-          return self._get_property(:upstream)
-        else
-          return self.canonical
-        end
-      end
-    end
     
   end # class Repository
 
--- a/rakelib/scm.rb	Sun Nov 27 22:57:33 2016 +0000
+++ b/rakelib/scm.rb	Sun Dec 04 22:21:22 2016 +0000
@@ -147,6 +147,13 @@
         end
         hg.pull('staging')
       end
+      if repository.upstream then        
+        if not paths.has_key? 'upstream'           
+          paths['upstream'] = "#{repository.upstream}/#{directory.gsub('/', separator)}"
+          hg.paths = paths
+        end
+        hg.pull('upstream')
+      end
       if not paths.has_key? 'canonical'
         paths['canonical'] = "#{repository.canonical}/#{directory.gsub('/', separator)}"
         hg.paths = paths
@@ -251,25 +258,31 @@
     separator = kwargs[:separator] || '.'
     revision =  kwargs[:revision] 
     
-    paths = { 'default' => "#{repository.upstream}/#{directory.gsub('/', separator)}",
-              'canonical' => "#{repository.canonical}/#{directory.gsub('/', separator)}" }            
+    paths = { 'canonical' => "#{repository.canonical}/#{directory.gsub('/', separator)}" }            
+    if repository.upstream then
+      paths['upstream'] = "#{repository.upstream}/#{directory.gsub('/', separator)}"
+    end
     if repository.staging then
       paths['staging'] = "#{repository.staging}/#{directory.gsub('/', separator)}"
     end
+
     
     begin
       if repository.staging then
-        hg = HG::Repository.clone(paths['staging'], root / directory, noupdate: true)
+        paths['default'] = paths['staging']
+        hg = HG::Repository.clone(paths['staging'], root / directory, noupdate: true)        
         hg.paths = paths
-        hg.pull('default')  
+        hg.pull('upstream') if paths['upstream'] 
+        hg.pull('canonical')
+      elsif repository.upstream then
+        paths['default'] = paths['upstream']
+        hg = HG::Repository.clone(paths['upstream'], root / directory, noupdate: true)        
+        hg.paths = paths
+        hg.pull('canonical')
       else
-        hg = HG::Repository.clone(paths['default'], root / directory, noupdate: true)
+        hg = HG::Repository.clone(paths['canonical'], root / directory, noupdate: true)
         hg.paths = paths
       end
-      
-      if paths['default'] != paths['canonical'] then
-        hg.pull('canonical')
-      end
       # If revision is not specified, then look for bookmark
       # `master`. If it exist, then check out `master`. If it 
       # does not, then checkout tip or throw an error.
--- a/rakelib/support.rb	Sun Nov 27 22:57:33 2016 +0000
+++ b/rakelib/support.rb	Sun Dec 04 22:21:22 2016 +0000
@@ -46,7 +46,7 @@
   end
   if (ENV['USERNAME'] == 'jv') or (ENV['USERNAME'] == 'vranyj1')
     return true
-  end 
+  end
   return false
 end
 
--- a/rakelib/workflow.rake	Sun Nov 27 22:57:33 2016 +0000
+++ b/rakelib/workflow.rake	Sun Dec 04 22:21:22 2016 +0000
@@ -50,13 +50,13 @@
 
   desc "Display changes to be pushed to upstream repositores (use it to review what workflow:push-upstream would do)"
   task :'out-upstream', :user, :pass do | t, args |
-    push('default', args[:user], args[:pass], true, false)
+    push('upstream', args[:user], args[:pass], true, false)
   end
   task :'out-upstream' => :'setup'
 
   desc "Push currently checked out revisions to upstream repositories (to be called after all tests pass on all configurations)"
   task :'push-upstream', :user, :pass do | t, args |
-    push('default', args[:user], args[:pass], false, false)
+    push('upstream', args[:user], args[:pass], false, false)
   end
   task :'push-upstream' => :'setup'
 
--- a/specs/repositories.rbspec	Sun Nov 27 22:57:33 2016 +0000
+++ b/specs/repositories.rbspec	Sun Dec 04 22:21:22 2016 +0000
@@ -18,8 +18,9 @@
 #    on https://swing.fit.cvut.cz/hg in addition to canonical on hosted on 
 #    BitBucket.
 #
-#  3."ci-jv": for use on Jan Vrany's private CI. Uses local staging repositories 
-#    in addition to canonical on hosted on BitBucket.
+#  3."ci-jv": for use on Jan Vrany's private CI. Uses (his) local staging repositories 
+#    and repositories hosted at SWING as upstream repos. 
+#    
 #
 REPOSITORYSET = (ENV['REPOSITORYSET'] || 'default') if not defined? REPOSITORYSET
 
@@ -47,19 +48,21 @@
 when 'ci-swing'
   repository :'exept:public' do
     type :cvs    
-    canonical ":ext:swing.fit.cvut.cz/var/local/cvs"
+    canonical ":ext:#{ENV['USER'] || ENV['USERNAME']}@swing.fit.cvut.cz/var/local/cvs"
   end
 
   repository :'bitbucket:janvrany' do
     type :hg
     canonical "https://bitbucket.org/janvrany"
-    staging "ssh://swing.fit.cvut.cz//var/local/hg"
+    # Use local build slave network address to allow for faster
+    # checkouts
+    staging "ssh://#{ENV['USER'] || ENV['USERNAME']}@192.168.12.1//var/local/hg"
     separator '-'
   end
 
   repository :'swing:private:hg' do
     type :hg
-    canonical "ssh://192.168.12.2//hg"
+    canonical "ssh://#{ENV['USER'] || ENV['USERNAME']}@192.168.12.2//hg"
     separator '.'
   end
 
@@ -73,13 +76,20 @@
   repository :'bitbucket:janvrany' do
     type :hg
     canonical "https://bitbucket.org/janvrany"
-    staging "ssh://hg@192.168.0.250"
+    upstream  "ssh://hg@swing.fit.cvut.cz//var/local/hg"
+    staging   "ssh://hg@192.168.0.250"
     separator '-'
   end
 
   repository :'swing:private:hg' do
     type :hg
+    # No, don't do this - CI has no access to those
+    # SWING repositories (no VPN, no keys set up)
+    #
+    # canonical "ssh://192.168.12.2//hg"
+    # staging   "ssh://hg@192.168.0.250"
+    
     canonical "ssh://hg@192.168.0.250"
     separator '-'
   end
-end
\ No newline at end of file
+end