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
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative 'run.rb'
require 'tempfile'
def main(source, revision)
root = capture!(%w[git rev-parse --show-toplevel]).chomp
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
clone(source, revision)
modify(source, revision)
copy(root)
end
end
end
def clone(source, revision)
run!(%W[git clone --quiet --depth=1 -b #{revision} https://#{source}.git .])
end
def modify(source, revision)
Dir['*.proto'].each do |proto|
tmp = proto + '.bak'
run2!(%W[sed s/gitlab-org\\/gitaly-proto/gitlab-org\\/gitaly\\/proto/ #{proto}], out: tmp)
FileUtils.mv(tmp, proto)
end
FileUtils.mv('README.md', 'README.orig.md')
commit_id = capture!(%w[git rev-parse HEAD]).chomp
readme = <<EOS
# Vendored copy of gitaly-proto
Vendored from #{source} at #{commit_id}.
Migration in progress, see
https://gitlab.com/gitlab-org/gitaly/issues/1761. Do not edit files in
this directory, your changes will be ignored and overwritten.
EOS
File.open('README.md', 'w') { |f| f.write(readme) }
File.open('REVISION', 'w') { |f| f.write(revision) }
File.open('SOURCE', 'w') { |f| f.write(source) }
end
def copy(root)
dest = File.join(root, 'proto')
FileUtils.rm(Dir["#{dest}/*.proto"])
file_list = Dir['*.proto'] + Dir['*.md'] + %w[VERSION REVISION SOURCE]
FileUtils.cp(file_list, dest)
end
unless ARGV.count == 2
abort "Usage: #{$0} SOURCE REVISION"
end
main(*ARGV)
|