autoproj 2.14.0 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +30 -0
- data/.rubocop.yml +79 -91
- data/.rubocop_todo.yml +1473 -0
- data/Gemfile +9 -9
- data/Rakefile +24 -24
- data/autoproj.gemspec +22 -22
- data/bin/alocate +4 -4
- data/bin/alog +5 -7
- data/bin/amake +4 -4
- data/bin/aup +4 -4
- data/bin/autoproj +3 -3
- data/bin/autoproj_bootstrap +185 -182
- data/bin/autoproj_bootstrap.in +7 -8
- data/bin/autoproj_install +184 -181
- data/bin/autoproj_install.in +6 -7
- data/lib/autoproj/aruba_minitest.rb +6 -11
- data/lib/autoproj/autobuild.rb +5 -6
- data/lib/autoproj/autobuild_extensions/archive_importer.rb +10 -11
- data/lib/autoproj/autobuild_extensions/dsl.rb +38 -34
- data/lib/autoproj/autobuild_extensions/git.rb +27 -26
- data/lib/autoproj/autobuild_extensions/package.rb +23 -22
- data/lib/autoproj/autobuild_extensions/svn.rb +1 -2
- data/lib/autoproj/base.rb +1 -1
- data/lib/autoproj/bash_completion.rb +5 -6
- data/lib/autoproj/build_option.rb +22 -24
- data/lib/autoproj/cli/base.rb +26 -26
- data/lib/autoproj/cli/bootstrap.rb +14 -16
- data/lib/autoproj/cli/build.rb +10 -7
- data/lib/autoproj/cli/cache.rb +11 -11
- data/lib/autoproj/cli/clean.rb +10 -10
- data/lib/autoproj/cli/commit.rb +7 -8
- data/lib/autoproj/cli/doc.rb +2 -2
- data/lib/autoproj/cli/envsh.rb +1 -2
- data/lib/autoproj/cli/exec.rb +60 -20
- data/lib/autoproj/cli/inspection_tool.rb +13 -7
- data/lib/autoproj/cli/locate.rb +30 -41
- data/lib/autoproj/cli/log.rb +7 -7
- data/lib/autoproj/cli/main.rb +213 -204
- data/lib/autoproj/cli/main_doc.rb +22 -21
- data/lib/autoproj/cli/main_global.rb +44 -19
- data/lib/autoproj/cli/main_plugin.rb +18 -18
- data/lib/autoproj/cli/main_test.rb +28 -27
- data/lib/autoproj/cli/manifest.rb +7 -7
- data/lib/autoproj/cli/osdeps.rb +12 -11
- data/lib/autoproj/cli/patcher.rb +2 -3
- data/lib/autoproj/cli/query.rb +17 -18
- data/lib/autoproj/cli/reconfigure.rb +1 -2
- data/lib/autoproj/cli/reset.rb +9 -12
- data/lib/autoproj/cli/show.rb +38 -39
- data/lib/autoproj/cli/status.rb +45 -39
- data/lib/autoproj/cli/switch_config.rb +5 -6
- data/lib/autoproj/cli/tag.rb +12 -11
- data/lib/autoproj/cli/test.rb +7 -7
- data/lib/autoproj/cli/update.rb +35 -37
- data/lib/autoproj/cli/utility.rb +11 -10
- data/lib/autoproj/cli/version.rb +42 -40
- data/lib/autoproj/cli/versions.rb +14 -15
- data/lib/autoproj/cli/watch.rb +33 -37
- data/lib/autoproj/cli/which.rb +16 -20
- data/lib/autoproj/cli.rb +4 -2
- data/lib/autoproj/configuration.rb +77 -84
- data/lib/autoproj/environment.rb +28 -13
- data/lib/autoproj/exceptions.rb +9 -3
- data/lib/autoproj/find_workspace.rb +20 -25
- data/lib/autoproj/git_server_configuration.rb +40 -44
- data/lib/autoproj/gitorious.rb +1 -1
- data/lib/autoproj/installation_manifest.rb +64 -29
- data/lib/autoproj/local_package_set.rb +13 -11
- data/lib/autoproj/manifest.rb +132 -130
- data/lib/autoproj/metapackage.rb +2 -6
- data/lib/autoproj/ops/atomic_write.rb +7 -6
- data/lib/autoproj/ops/build.rb +4 -6
- data/lib/autoproj/ops/cache.rb +41 -43
- data/lib/autoproj/ops/cached_env.rb +5 -4
- data/lib/autoproj/ops/configuration.rb +511 -506
- data/lib/autoproj/ops/import.rb +73 -63
- data/lib/autoproj/ops/install.rb +178 -174
- data/lib/autoproj/ops/loader.rb +77 -76
- data/lib/autoproj/ops/main_config_switcher.rb +36 -45
- data/lib/autoproj/ops/phase_reporting.rb +4 -4
- data/lib/autoproj/ops/snapshot.rb +250 -247
- data/lib/autoproj/ops/tools.rb +76 -78
- data/lib/autoproj/ops/watch.rb +6 -6
- data/lib/autoproj/ops/which.rb +17 -14
- data/lib/autoproj/options.rb +13 -2
- data/lib/autoproj/os_package_installer.rb +102 -92
- data/lib/autoproj/os_package_query.rb +7 -13
- data/lib/autoproj/os_package_resolver.rb +189 -140
- data/lib/autoproj/os_repository_installer.rb +4 -4
- data/lib/autoproj/os_repository_resolver.rb +8 -6
- data/lib/autoproj/package_definition.rb +12 -13
- data/lib/autoproj/package_managers/apt_dpkg_manager.rb +10 -10
- data/lib/autoproj/package_managers/bundler_manager.rb +147 -111
- data/lib/autoproj/package_managers/debian_version.rb +25 -21
- data/lib/autoproj/package_managers/emerge_manager.rb +2 -3
- data/lib/autoproj/package_managers/gem_manager.rb +68 -77
- data/lib/autoproj/package_managers/homebrew_manager.rb +3 -4
- data/lib/autoproj/package_managers/manager.rb +8 -3
- data/lib/autoproj/package_managers/pacman_manager.rb +2 -3
- data/lib/autoproj/package_managers/pip_manager.rb +20 -22
- data/lib/autoproj/package_managers/pkg_manager.rb +3 -4
- data/lib/autoproj/package_managers/port_manager.rb +2 -3
- data/lib/autoproj/package_managers/shell_script_manager.rb +32 -22
- data/lib/autoproj/package_managers/unknown_os_manager.rb +5 -8
- data/lib/autoproj/package_managers/yum_manager.rb +12 -15
- data/lib/autoproj/package_managers/zypper_manager.rb +11 -14
- data/lib/autoproj/package_manifest.rb +27 -26
- data/lib/autoproj/package_selection.rb +187 -187
- data/lib/autoproj/package_set.rb +127 -113
- data/lib/autoproj/python.rb +55 -55
- data/lib/autoproj/query_base.rb +20 -14
- data/lib/autoproj/reporter.rb +19 -19
- data/lib/autoproj/repository_managers/apt.rb +101 -67
- data/lib/autoproj/repository_managers/unknown_os_manager.rb +3 -3
- data/lib/autoproj/shell_completion.rb +16 -13
- data/lib/autoproj/source_package_query.rb +29 -36
- data/lib/autoproj/system.rb +32 -21
- data/lib/autoproj/test.rb +127 -104
- data/lib/autoproj/variable_expansion.rb +7 -9
- data/lib/autoproj/vcs_definition.rb +35 -32
- data/lib/autoproj/version.rb +1 -1
- data/lib/autoproj/workspace.rb +123 -107
- data/lib/autoproj/zsh_completion.rb +8 -9
- data/lib/autoproj.rb +53 -55
- data/samples/autoproj/init.rb +1 -2
- metadata +53 -51
- data/.travis.yml +0 -24
@@ -1,301 +1,304 @@
|
|
1
1
|
module Autoproj
|
2
2
|
module Ops
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
3
|
+
class Snapshot
|
4
|
+
# Update version control information with new choices
|
5
|
+
#
|
6
|
+
# The two parameters are formatted as expected in the version_control
|
7
|
+
# and overrides fields in source.yml / overrides.yml, that is (in YAML)
|
8
|
+
#
|
9
|
+
# - package_name:
|
10
|
+
# version: '10'
|
11
|
+
# control: '20'
|
12
|
+
# info: '30'
|
13
|
+
#
|
14
|
+
# The two parameters are expected to only use full package names, and
|
15
|
+
# not regular expressions
|
16
|
+
#
|
17
|
+
# @param [Array<String=>Hash>] overrides the information that should augment
|
18
|
+
# the current state
|
19
|
+
# @param [Array<String=>Hash>] state the current state
|
20
|
+
# @param [Hash] the updated information
|
21
|
+
def self.merge_packets(overrides, state)
|
22
|
+
overriden = overrides.map { |entry| entry.keys.first }.to_set
|
23
|
+
filtered_state = state.find_all do |pkg|
|
24
|
+
name, = pkg.first
|
25
|
+
!overriden.include?(name)
|
26
|
+
end
|
27
|
+
filtered_state + overrides
|
26
28
|
end
|
27
|
-
filtered_state + overrides
|
28
|
-
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def sort_versions(versions)
|
38
|
-
pkg_sets, pkgs = versions.partition { |vcs| vcs.keys.first =~ /^pkg_set:/ }
|
39
|
-
pkg_sets.sort_by { |vcs| vcs.keys.first } +
|
40
|
-
pkgs.sort_by { |vcs| vcs.keys.first }
|
41
|
-
end
|
30
|
+
def self.update_log_available?(manifest)
|
31
|
+
new(manifest).import_state_log_package
|
32
|
+
true
|
33
|
+
rescue ArgumentError
|
34
|
+
false
|
35
|
+
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Array.new
|
37
|
+
def sort_versions(versions)
|
38
|
+
pkg_sets, pkgs = versions.partition { |vcs| vcs.keys.first =~ /^pkg_set:/ }
|
39
|
+
pkg_sets.sort_by { |vcs| vcs.keys.first } +
|
40
|
+
pkgs.sort_by { |vcs| vcs.keys.first }
|
48
41
|
end
|
49
42
|
|
50
|
-
|
51
|
-
|
43
|
+
def save_versions(versions, versions_file, replace: false)
|
44
|
+
existing_versions = Array.new
|
45
|
+
if !replace && File.exist?(versions_file)
|
46
|
+
existing_versions = YAML.load(File.read(versions_file)) ||
|
47
|
+
Array.new
|
48
|
+
end
|
52
49
|
|
53
|
-
|
54
|
-
|
50
|
+
# create direcotry for versions file first
|
51
|
+
FileUtils.mkdir_p(File.dirname(versions_file))
|
55
52
|
|
56
|
-
|
53
|
+
# augment the versions file with the updated versions
|
54
|
+
versions = Snapshot.merge_packets(versions, existing_versions)
|
57
55
|
|
58
|
-
|
59
|
-
File.open(versions_file, 'w') do |io|
|
60
|
-
io.write YAML.dump(versions)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.snapshot( packages, target_dir )
|
65
|
-
# todo
|
66
|
-
end
|
56
|
+
versions = sort_versions(versions)
|
67
57
|
|
68
|
-
|
58
|
+
# write the yaml file
|
59
|
+
File.open(versions_file, "w") do |io|
|
60
|
+
io.write YAML.dump(versions)
|
61
|
+
end
|
62
|
+
end
|
69
63
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
# Otherwise (the default), it leads to an error.
|
74
|
-
#
|
75
|
-
# @return [Boolean]
|
76
|
-
# @see initialize error_or_warn
|
77
|
-
def keep_going?; !!@keep_going end
|
64
|
+
def self.snapshot(packages, target_dir)
|
65
|
+
# todo
|
66
|
+
end
|
78
67
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
68
|
+
attr_reader :manifest
|
69
|
+
|
70
|
+
# Control what happens if a package fails to be snapshotted
|
71
|
+
#
|
72
|
+
# If true, the failure to snapshot a package should lead to a warning.
|
73
|
+
# Otherwise (the default), it leads to an error.
|
74
|
+
#
|
75
|
+
# @return [Boolean]
|
76
|
+
# @see initialize error_or_warn
|
77
|
+
def keep_going?
|
78
|
+
!!@keep_going
|
79
|
+
end
|
83
80
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
def initialize(manifest, keep_going: false)
|
82
|
+
@manifest = manifest
|
83
|
+
@keep_going = keep_going
|
84
|
+
end
|
88
85
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
def snapshot_package_sets(target_dir = nil, only_local: true)
|
87
|
+
result = Array.new
|
88
|
+
manifest.each_package_set do |pkg_set|
|
89
|
+
next if pkg_set.local?
|
90
|
+
|
91
|
+
vcs_info =
|
92
|
+
begin pkg_set.snapshot(target_dir, only_local: only_local)
|
93
|
+
rescue Exception => e
|
94
|
+
error_or_warn(pkg_set, e)
|
95
|
+
next
|
96
|
+
end
|
97
|
+
|
98
|
+
if vcs_info
|
99
|
+
result << Hash["pkg_set:#{pkg_set.repository_id}", vcs_info]
|
100
|
+
else
|
101
|
+
error_or_warn(pkg_set, "cannot snapshot package set #{pkg_set.name}: importer snapshot failed")
|
94
102
|
end
|
95
|
-
|
96
|
-
if vcs_info
|
97
|
-
result << Hash["pkg_set:#{pkg_set.repository_id}", vcs_info]
|
98
|
-
else
|
99
|
-
error_or_warn(pkg_set, "cannot snapshot package set #{pkg_set.name}: importer snapshot failed")
|
100
103
|
end
|
104
|
+
result
|
101
105
|
end
|
102
|
-
result
|
103
|
-
end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
107
|
+
def error_or_warn(package, error)
|
108
|
+
if error.kind_of?(Interrupt)
|
109
|
+
raise
|
110
|
+
elsif keep_going?
|
111
|
+
error = error.message unless error.respond_to?(:to_str)
|
112
|
+
Autoproj.warn error
|
113
|
+
elsif error.respond_to?(:to_str)
|
114
|
+
raise Autobuild::PackageException.new(package, "snapshot"), error
|
115
|
+
else
|
116
|
+
raise
|
111
117
|
end
|
112
|
-
Autoproj.warn error
|
113
|
-
elsif error.respond_to?(:to_str)
|
114
|
-
raise Autobuild::PackageException.new(package, 'snapshot'), error
|
115
|
-
else
|
116
|
-
raise
|
117
118
|
end
|
118
|
-
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
importer = package.autobuild.importer
|
129
|
-
if !importer
|
130
|
-
error_or_warn(package, "cannot snapshot #{package_name} as it has no importer")
|
131
|
-
next
|
132
|
-
elsif !importer.respond_to?(:snapshot)
|
133
|
-
error_or_warn(package, "cannot snapshot #{package_name} as the #{importer.class} importer does not support it")
|
134
|
-
next
|
135
|
-
end
|
120
|
+
def snapshot_packages(packages, target_dir = nil, only_local: true, fingerprint: false)
|
121
|
+
result = Array.new
|
122
|
+
fingerprint_memo = Hash.new
|
123
|
+
packages.each do |package_name|
|
124
|
+
package = manifest.find_package_definition(package_name)
|
125
|
+
unless package
|
126
|
+
raise ArgumentError, "#{package_name} is not a known package"
|
127
|
+
end
|
136
128
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
129
|
+
importer = package.autobuild.importer
|
130
|
+
if !importer
|
131
|
+
error_or_warn(package, "cannot snapshot #{package_name} as it has no importer")
|
132
|
+
next
|
133
|
+
elsif !importer.respond_to?(:snapshot)
|
134
|
+
error_or_warn(package, "cannot snapshot #{package_name} as the #{importer.class} importer does not support it")
|
141
135
|
next
|
142
136
|
end
|
143
137
|
|
144
|
-
|
145
|
-
|
146
|
-
|
138
|
+
vcs_info =
|
139
|
+
begin importer.snapshot(package.autobuild, target_dir, only_local: only_local)
|
140
|
+
rescue Exception => e
|
141
|
+
error_or_warn(package, e)
|
142
|
+
next
|
143
|
+
end
|
147
144
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
145
|
+
if fingerprint
|
146
|
+
vcs_info["fingerprint"] = package.autobuild.fingerprint(memo: fingerprint_memo)
|
147
|
+
end
|
148
|
+
|
149
|
+
if vcs_info
|
150
|
+
result << Hash[package_name, vcs_info]
|
151
|
+
else
|
152
|
+
error_or_warn(package, "cannot snapshot #{package_name}: importer snapshot failed")
|
153
|
+
end
|
152
154
|
end
|
155
|
+
result
|
153
156
|
end
|
154
|
-
result
|
155
|
-
end
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
# Returns the list of existing version tags
|
159
|
+
def tags(package)
|
160
|
+
importer = package.importer
|
161
|
+
all_tags = importer.run_git_bare(package, "tag")
|
162
|
+
all_tags.find_all do |tag_name|
|
163
|
+
end
|
162
164
|
end
|
163
|
-
end
|
164
165
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
166
|
+
# Returns a package that is used to store this installs import history
|
167
|
+
#
|
168
|
+
# Its importer is guaranteed to be a git importer
|
169
|
+
#
|
170
|
+
# @return [Autobuild::Package] a package whose importer is
|
171
|
+
# {Autobuild::Git}
|
172
|
+
def import_state_log_package
|
173
|
+
pkg = manifest.main_package_set.create_autobuild_package
|
174
|
+
unless pkg.importer
|
175
|
+
if Autobuild::Git.can_handle?(pkg.srcdir)
|
176
|
+
pkg.importer = Autobuild.git(pkg.srcdir)
|
177
|
+
end
|
176
178
|
end
|
177
|
-
end
|
178
179
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
pkg
|
183
|
-
end
|
180
|
+
unless pkg.importer.kind_of?(Autobuild::Git)
|
181
|
+
raise ArgumentError, "cannot use autoproj auto-import feature if the main configuration is not managed under git"
|
182
|
+
end
|
184
183
|
|
185
|
-
|
186
|
-
|
187
|
-
end
|
184
|
+
pkg
|
185
|
+
end
|
188
186
|
|
189
|
-
|
187
|
+
def self.import_state_log_ref
|
188
|
+
"refs/autoproj"
|
189
|
+
end
|
190
190
|
|
191
|
-
|
192
|
-
File.join(Workspace::OVERRIDES_DIR, DEFAULT_VERSIONS_FILE_BASENAME)
|
193
|
-
end
|
191
|
+
DEFAULT_VERSIONS_FILE_BASENAME = "50-versions.yml"
|
194
192
|
|
195
|
-
|
196
|
-
|
197
|
-
# Try to resolve the log ref, and extract the version file from it
|
198
|
-
begin
|
199
|
-
yaml = main.importer.show(main, self.class.import_state_log_ref, import_state_log_file)
|
200
|
-
YAML.load(yaml) || Array.new
|
201
|
-
rescue Autobuild::PackageException
|
202
|
-
Array.new
|
193
|
+
def import_state_log_file
|
194
|
+
File.join(Workspace::OVERRIDES_DIR, DEFAULT_VERSIONS_FILE_BASENAME)
|
203
195
|
end
|
204
|
-
end
|
205
196
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
197
|
+
def current_import_state
|
198
|
+
main = import_state_log_package
|
199
|
+
# Try to resolve the log ref, and extract the version file from it
|
200
|
+
begin
|
201
|
+
yaml = main.importer.show(main, self.class.import_state_log_ref, import_state_log_file)
|
202
|
+
YAML.load(yaml) || Array.new
|
203
|
+
rescue Autobuild::PackageException
|
204
|
+
Array.new
|
205
|
+
end
|
214
206
|
end
|
215
|
-
versions = snapshot_package_sets
|
216
|
-
versions += snapshot_packages(packages)
|
217
|
-
versions = Snapshot.merge_packets(versions, current_versions)
|
218
|
-
save_import_state(name, versions)
|
219
|
-
end
|
220
207
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
208
|
+
def update_package_import_state(name, packages)
|
209
|
+
current_versions = current_import_state
|
210
|
+
if current_versions.empty?
|
211
|
+
# Do a full snapshot this time only
|
212
|
+
Autoproj.message " building initial autoproj import log, this may take a while"
|
213
|
+
packages = manifest.all_selected_source_packages
|
214
|
+
.find_all { |pkg| File.directory?(pkg.autobuild.srcdir) }
|
215
|
+
.map(&:name)
|
216
|
+
end
|
217
|
+
versions = snapshot_package_sets
|
218
|
+
versions += snapshot_packages(packages)
|
219
|
+
versions = Snapshot.merge_packets(versions, current_versions)
|
220
|
+
save_import_state(name, versions)
|
231
221
|
end
|
232
|
-
# And save it in our reflog
|
233
|
-
main.importer.run_git_bare(main, "update-ref", '-m', name, self.class.import_state_log_ref, commit_id)
|
234
|
-
end
|
235
222
|
|
236
|
-
|
237
|
-
|
238
|
-
# The target git repository's current index and history is left
|
239
|
-
# unmodified. The only modification is the creation of a new dangling
|
240
|
-
# commit.
|
241
|
-
#
|
242
|
-
# It creates a temporary file and gives it to the block so that the file
|
243
|
-
# gets filled with the new content
|
244
|
-
#
|
245
|
-
# @yieldparam [Tempfile] io a temporary file
|
246
|
-
# @param [Autobuild::Package] a package object whose importer is a git
|
247
|
-
# importer. The git commit is created in this repository
|
248
|
-
# @param [String] path the file to be created or updated, relative to
|
249
|
-
# the root of the git repository
|
250
|
-
# @param [String] the commit message
|
251
|
-
# @return [String] the commit ID
|
252
|
-
def self.create_commit(pkg, path, message, parent_id = nil, real_author: true)
|
253
|
-
importer = pkg.importer
|
254
|
-
object_id = Tempfile.open 'autoproj-versions' do |io|
|
255
|
-
yield(io)
|
256
|
-
io.flush
|
257
|
-
importer.run_git_bare(
|
258
|
-
pkg, 'hash-object', '-w',
|
259
|
-
'--path', path, io.path).first
|
260
|
-
end
|
223
|
+
def save_import_state(name, versions)
|
224
|
+
versions = sort_versions(versions)
|
261
225
|
|
262
|
-
|
263
|
-
|
264
|
-
|
226
|
+
main = import_state_log_package
|
227
|
+
git_dir = main.importer.git_dir(main, false)
|
228
|
+
# Ensure that our ref is being logged
|
229
|
+
FileUtils.touch File.join(git_dir, "logs", *self.class.import_state_log_ref.split("/"))
|
230
|
+
# Create the commit with the versions info
|
231
|
+
commit_id = Snapshot.create_commit(main, import_state_log_file, name, real_author: false) do |io|
|
232
|
+
YAML.dump(versions, io)
|
233
|
+
end
|
234
|
+
# And save it in our reflog
|
235
|
+
main.importer.run_git_bare(main, "update-ref", "-m", name, self.class.import_state_log_ref, commit_id)
|
265
236
|
end
|
266
237
|
|
267
|
-
|
238
|
+
# Create a git commit in which a file contains provided content
|
239
|
+
#
|
240
|
+
# The target git repository's current index and history is left
|
241
|
+
# unmodified. The only modification is the creation of a new dangling
|
242
|
+
# commit.
|
243
|
+
#
|
244
|
+
# It creates a temporary file and gives it to the block so that the file
|
245
|
+
# gets filled with the new content
|
246
|
+
#
|
247
|
+
# @yieldparam [Tempfile] io a temporary file
|
248
|
+
# @param [Autobuild::Package] a package object whose importer is a git
|
249
|
+
# importer. The git commit is created in this repository
|
250
|
+
# @param [String] path the file to be created or updated, relative to
|
251
|
+
# the root of the git repository
|
252
|
+
# @param [String] the commit message
|
253
|
+
# @return [String] the commit ID
|
254
|
+
def self.create_commit(pkg, path, message, parent_id = nil, real_author: true)
|
255
|
+
importer = pkg.importer
|
256
|
+
object_id = Tempfile.open "autoproj-versions" do |io|
|
257
|
+
yield(io)
|
258
|
+
io.flush
|
259
|
+
importer.run_git_bare(
|
260
|
+
pkg, "hash-object", "-w",
|
261
|
+
"--path", path, io.path
|
262
|
+
).first
|
263
|
+
end
|
268
264
|
|
269
|
-
|
270
|
-
|
271
|
-
env['GIT_AUTHOR_NAME'] = 'autoproj'
|
272
|
-
env['GIT_AUTHOR_EMAIL'] = 'autoproj'
|
273
|
-
env['GIT_COMMITTER_NAME'] = 'autoproj'
|
274
|
-
env['GIT_COMMITTER_EMAIL'] = 'autoproj'
|
275
|
-
end
|
265
|
+
cacheinfo = ["100644", object_id, path]
|
266
|
+
cacheinfo = cacheinfo.join(",") if Autobuild::Git.at_least_version(2, 1)
|
276
267
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
ENV.delete('GIT_INDEX_FILE')
|
268
|
+
parent_id ||= importer.rev_parse(pkg, "HEAD")
|
269
|
+
|
270
|
+
env = Hash.new
|
271
|
+
unless real_author
|
272
|
+
env["GIT_AUTHOR_NAME"] = "autoproj"
|
273
|
+
env["GIT_AUTHOR_EMAIL"] = "autoproj"
|
274
|
+
env["GIT_COMMITTER_NAME"] = "autoproj"
|
275
|
+
env["GIT_COMMITTER_EMAIL"] = "autoproj"
|
276
|
+
end
|
277
|
+
|
278
|
+
# Create the tree using a temporary index in order to not mess with
|
279
|
+
# the user's index state. read-tree initializes the new index and
|
280
|
+
# then we add the overrides file with update-index / write-tree
|
281
|
+
our_index = File.join(importer.git_dir(pkg, false), "index.autoproj")
|
292
282
|
FileUtils.rm_f our_index
|
293
|
-
|
283
|
+
begin
|
284
|
+
ENV["GIT_INDEX_FILE"] = our_index
|
285
|
+
importer.run_git_bare(pkg, "read-tree", parent_id)
|
286
|
+
# And add the new file
|
287
|
+
importer.run_git_bare(
|
288
|
+
pkg, "update-index",
|
289
|
+
"--add", "--cacheinfo", *cacheinfo
|
290
|
+
)
|
291
|
+
tree_id = importer.run_git_bare(pkg, "write-tree").first
|
292
|
+
ensure
|
293
|
+
ENV.delete("GIT_INDEX_FILE")
|
294
|
+
FileUtils.rm_f our_index
|
295
|
+
end
|
294
296
|
|
295
|
-
|
296
|
-
|
297
|
-
|
297
|
+
importer.run_git_bare(
|
298
|
+
pkg, "commit-tree",
|
299
|
+
tree_id, "-p", parent_id, env: env, input_streams: [message]
|
300
|
+
).first
|
301
|
+
end
|
298
302
|
end
|
299
303
|
end
|
300
|
-
end
|
301
304
|
end
|