Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0a31d8863c
Fetching contributors…

Cannot retrieve contributors at this time

executable file 80 lines (69 sloc) 2.24 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#!/usr/bin/env ruby

require 'rexml/document'
require 'rubygems'
require 'rake'
if ARGV.size < 4
  puts "I need at least 4 arg: repo/manifest.xml newmanifest.xml ep-engine master"
  exit 1
end

path = ARGV[0] # Required. Example: some/repo/manifest/default.xml
oxml = ARGV[1] # Example: output/build-manifest.xml -- usable as input to repo tool.
gerrit_project = ARGV[2] # Required.
gerrit_refspec = ARGV[3] # Required.

root = REXML::Document.new(File.new(path)).root

default = root.get_elements("//default")[0]
remotes = {}

root.each_element("//remote") do |remote|
  remotes[remote.attributes['name']] = remote
end

projects = {}

root.each_element("//project") do |project|
  projects[project.attributes['name']] = project
end

if oxml
  # Emit a manifest.xml that can be used as input to
  # the repo / fetch-manifest.rb tool.
  #
  File.open(oxml, 'w') do |o|
    o.write "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
    o.write "<manifest>\n"
    remotes.keys.sort.each do |name|
      remote = remotes[name]
      o.write " <remote name=\"#{name}\" fetch=\"#{remote.attributes['fetch']}\"/>\n"
    end
    o.write "\n"
    o.write " <default remote=\"#{default.attributes['remote']}\" revision=\"#{default.attributes['revision']}\"/>\n"
    o.write "\n"
    projects.keys.sort.each do |name|
      project = projects[name]
      remote = project.attributes['remote']
      path = project.attributes['path'] || project.attributes['name']
curr = project.attributes['revision'] || default.attributes['revision']
if name == gerrit_project
         curr = gerrit_refspec
      end
      Dir.chdir(path) do
        #curr = `git rev-parse HEAD`.chomp
        o.write " <project name=\"#{name}\" path=\"#{path}\" revision=\"#{curr}\""
        if remote
          o.write "\n"
          o.write " remote=\"#{remote}\""
        end

        has_body = false

        project.each_element do |child|
          o.write(">\n") unless has_body
          o.write(" ")
          o.write(child)
          o.write("\n")
          has_body = true
        end

        if has_body
          o.write " </project>\n"
        else
          o.write "/>\n"
        end
      end
    end
    o.write "</manifest>\n"
  end
end
Something went wrong with that request. Please try again.