forked from github-linguist/linguist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast-submodule-update
executable file
·67 lines (55 loc) · 1.54 KB
/
fast-submodule-update
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
#!/usr/bin/env ruby
require "thread"
ROOT = File.expand_path("../..", __FILE__).freeze
Dir.chdir(ROOT)
SUBMODULES = `git config --list --file .gitmodules`.lines.grep(/\.path=/).map { |line| line.chomp.split("=", 2).last }.freeze
SLOW_SUBMODULES = %w[
vendor/grammars/factor
vendor/grammars/fsharpbinding
vendor/grammars/ioke-outdated
]
class TaskResult < Struct.new(:submodule, :output, :status); end
def run_process(*args)
read, write = IO.pipe
pid = Process.spawn(*args, in: :close, out: write, err: [:child, :out])
write.close
output = read.read
read.close
Process.wait(pid)
[output, $?]
end
def update_submodule(submodule)
output, status = run_process("git", "submodule", "update", "--", submodule)
TaskResult.new(submodule, output, status)
end
def run_thread(submodules, results)
loop do
begin
submodule = submodules.pop(true)
rescue ThreadError
# The queue is empty.
break
end
results.push(update_submodule(submodule))
end
end
submodules = Queue.new
results = Queue.new
# Update the slow submodules first so they can update in the background while
# the fast ones run.
SUBMODULES.partition { |submodule| SLOW_SUBMODULES.include?(submodule) }.flatten.each do |submodule|
submodules.push(submodule)
end
8.times do
Thread.new { run_thread(submodules, results) }
end
success = true
SUBMODULES.each do
result = results.pop
unless result.status.success?
success = false
puts "Error updating #{result.submodule}"
end
puts result.output if result.output =~ /\S/
end
exit success ? 0 : 1