Sha256: 73f983dc48d18edbf93ddef7e5ba0454d08adaff97b5a6cddbb46c5936016cbc

Contents?: true

Size: 1.93 KB

Versions: 8

Compression:

Stored size: 1.93 KB

Contents

require 'rim/command_helper'
require 'rim/upload_module_helper'

module RIM

class UploadHelper < CommandHelper

  def initialize(workspace_root, review, logger, module_infos = nil)
    @module_helpers = []
    @review = review
    super(workspace_root, logger, module_infos)
  end

  # upload all module changes into corresponding remote repositories
  def upload
    # get the name of the current workspace branch
    RIM::git_session(@ws_root) do |s|
      branch = s.current_branch
      if !branch.start_with?("rim/")
        begin
          sha1 = s.rev_sha1(branch)
          @logger.info("Uploading modules...")
          upload_modules(get_upload_revisions(s, sha1))
        ensure
          s.execute("git checkout #{branch}")
        end
      else
        raise RimException.new("The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.")
      end
    end
  end

  # called to add a module info
  def add_module_info(module_info)
    @module_helpers.push(UploadModuleHelper.new(@ws_root, module_info, @review, @logger))
  end
  
private
  # upload all modules
  def upload_modules(info)
    each_module_parallel("uploading", @module_helpers) do |m|
      m.upload(info.parent, info.sha1s)
    end
  end

  # get revisions to upload i.e. the revisions up to the last remote revision
  # the function returns the revisions in order of appearal i.e. the oldest first 
  def get_upload_revisions(session, rev)
    # remote revs are where we stop traversal
    non_remote_revs = {}
    session.all_reachable_non_remote_revs(rev).each do |r| 
      non_remote_revs[r] = true
    end
    revisions = []
    # make sure we deal only with sha1s
    rev = session.rev_sha1(rev)
    while rev && non_remote_revs[rev]
      revisions.push(rev)
      parents = session.parent_revs(rev)
      rev = parents.size > 0 ? parents.first : nil
    end
    Struct.new(:parent, :sha1s).new(rev, revisions.reverse!)
  end

end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
esr-rim-1.3.3 lib/rim/upload_helper.rb
esr-rim-1.3.2 lib/rim/upload_helper.rb
esr-rim-1.3.1 lib/rim/upload_helper.rb
esr-rim-1.3.0 lib/rim/upload_helper.rb
esr-rim-1.2.2 lib/rim/upload_helper.rb
esr-rim-1.2.1 lib/rim/upload_helper.rb
esr-rim-1.2.0 lib/rim/upload_helper.rb
esr-rim-1.1.5 lib/rim/upload_helper.rb