autoproj 2.14.0 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +25 -0
  3. data/.github/workflows/test.yml +30 -0
  4. data/.rubocop.yml +79 -91
  5. data/.rubocop_todo.yml +1473 -0
  6. data/Gemfile +9 -9
  7. data/Rakefile +24 -24
  8. data/autoproj.gemspec +22 -22
  9. data/bin/alocate +4 -4
  10. data/bin/alog +5 -7
  11. data/bin/amake +4 -4
  12. data/bin/aup +4 -4
  13. data/bin/autoproj +3 -3
  14. data/bin/autoproj_bootstrap +185 -182
  15. data/bin/autoproj_bootstrap.in +7 -8
  16. data/bin/autoproj_install +184 -181
  17. data/bin/autoproj_install.in +6 -7
  18. data/lib/autoproj/aruba_minitest.rb +6 -11
  19. data/lib/autoproj/autobuild.rb +5 -6
  20. data/lib/autoproj/autobuild_extensions/archive_importer.rb +10 -11
  21. data/lib/autoproj/autobuild_extensions/dsl.rb +38 -34
  22. data/lib/autoproj/autobuild_extensions/git.rb +27 -26
  23. data/lib/autoproj/autobuild_extensions/package.rb +23 -22
  24. data/lib/autoproj/autobuild_extensions/svn.rb +1 -2
  25. data/lib/autoproj/base.rb +1 -1
  26. data/lib/autoproj/bash_completion.rb +5 -6
  27. data/lib/autoproj/build_option.rb +22 -24
  28. data/lib/autoproj/cli/base.rb +26 -26
  29. data/lib/autoproj/cli/bootstrap.rb +14 -16
  30. data/lib/autoproj/cli/build.rb +10 -7
  31. data/lib/autoproj/cli/cache.rb +11 -11
  32. data/lib/autoproj/cli/clean.rb +10 -10
  33. data/lib/autoproj/cli/commit.rb +7 -8
  34. data/lib/autoproj/cli/doc.rb +2 -2
  35. data/lib/autoproj/cli/envsh.rb +1 -2
  36. data/lib/autoproj/cli/exec.rb +60 -20
  37. data/lib/autoproj/cli/inspection_tool.rb +13 -7
  38. data/lib/autoproj/cli/locate.rb +30 -41
  39. data/lib/autoproj/cli/log.rb +7 -7
  40. data/lib/autoproj/cli/main.rb +213 -204
  41. data/lib/autoproj/cli/main_doc.rb +22 -21
  42. data/lib/autoproj/cli/main_global.rb +44 -19
  43. data/lib/autoproj/cli/main_plugin.rb +18 -18
  44. data/lib/autoproj/cli/main_test.rb +28 -27
  45. data/lib/autoproj/cli/manifest.rb +7 -7
  46. data/lib/autoproj/cli/osdeps.rb +12 -11
  47. data/lib/autoproj/cli/patcher.rb +2 -3
  48. data/lib/autoproj/cli/query.rb +17 -18
  49. data/lib/autoproj/cli/reconfigure.rb +1 -2
  50. data/lib/autoproj/cli/reset.rb +9 -12
  51. data/lib/autoproj/cli/show.rb +38 -39
  52. data/lib/autoproj/cli/status.rb +45 -39
  53. data/lib/autoproj/cli/switch_config.rb +5 -6
  54. data/lib/autoproj/cli/tag.rb +12 -11
  55. data/lib/autoproj/cli/test.rb +7 -7
  56. data/lib/autoproj/cli/update.rb +35 -37
  57. data/lib/autoproj/cli/utility.rb +11 -10
  58. data/lib/autoproj/cli/version.rb +42 -40
  59. data/lib/autoproj/cli/versions.rb +14 -15
  60. data/lib/autoproj/cli/watch.rb +33 -37
  61. data/lib/autoproj/cli/which.rb +16 -20
  62. data/lib/autoproj/cli.rb +4 -2
  63. data/lib/autoproj/configuration.rb +77 -84
  64. data/lib/autoproj/environment.rb +28 -13
  65. data/lib/autoproj/exceptions.rb +9 -3
  66. data/lib/autoproj/find_workspace.rb +20 -25
  67. data/lib/autoproj/git_server_configuration.rb +40 -44
  68. data/lib/autoproj/gitorious.rb +1 -1
  69. data/lib/autoproj/installation_manifest.rb +64 -29
  70. data/lib/autoproj/local_package_set.rb +13 -11
  71. data/lib/autoproj/manifest.rb +132 -130
  72. data/lib/autoproj/metapackage.rb +2 -6
  73. data/lib/autoproj/ops/atomic_write.rb +7 -6
  74. data/lib/autoproj/ops/build.rb +4 -6
  75. data/lib/autoproj/ops/cache.rb +41 -43
  76. data/lib/autoproj/ops/cached_env.rb +5 -4
  77. data/lib/autoproj/ops/configuration.rb +511 -506
  78. data/lib/autoproj/ops/import.rb +73 -63
  79. data/lib/autoproj/ops/install.rb +178 -174
  80. data/lib/autoproj/ops/loader.rb +77 -76
  81. data/lib/autoproj/ops/main_config_switcher.rb +36 -45
  82. data/lib/autoproj/ops/phase_reporting.rb +4 -4
  83. data/lib/autoproj/ops/snapshot.rb +250 -247
  84. data/lib/autoproj/ops/tools.rb +76 -78
  85. data/lib/autoproj/ops/watch.rb +6 -6
  86. data/lib/autoproj/ops/which.rb +17 -14
  87. data/lib/autoproj/options.rb +13 -2
  88. data/lib/autoproj/os_package_installer.rb +102 -92
  89. data/lib/autoproj/os_package_query.rb +7 -13
  90. data/lib/autoproj/os_package_resolver.rb +189 -140
  91. data/lib/autoproj/os_repository_installer.rb +4 -4
  92. data/lib/autoproj/os_repository_resolver.rb +8 -6
  93. data/lib/autoproj/package_definition.rb +12 -13
  94. data/lib/autoproj/package_managers/apt_dpkg_manager.rb +10 -10
  95. data/lib/autoproj/package_managers/bundler_manager.rb +147 -111
  96. data/lib/autoproj/package_managers/debian_version.rb +25 -21
  97. data/lib/autoproj/package_managers/emerge_manager.rb +2 -3
  98. data/lib/autoproj/package_managers/gem_manager.rb +68 -77
  99. data/lib/autoproj/package_managers/homebrew_manager.rb +3 -4
  100. data/lib/autoproj/package_managers/manager.rb +8 -3
  101. data/lib/autoproj/package_managers/pacman_manager.rb +2 -3
  102. data/lib/autoproj/package_managers/pip_manager.rb +20 -22
  103. data/lib/autoproj/package_managers/pkg_manager.rb +3 -4
  104. data/lib/autoproj/package_managers/port_manager.rb +2 -3
  105. data/lib/autoproj/package_managers/shell_script_manager.rb +32 -22
  106. data/lib/autoproj/package_managers/unknown_os_manager.rb +5 -8
  107. data/lib/autoproj/package_managers/yum_manager.rb +12 -15
  108. data/lib/autoproj/package_managers/zypper_manager.rb +11 -14
  109. data/lib/autoproj/package_manifest.rb +27 -26
  110. data/lib/autoproj/package_selection.rb +187 -187
  111. data/lib/autoproj/package_set.rb +127 -113
  112. data/lib/autoproj/python.rb +55 -55
  113. data/lib/autoproj/query_base.rb +20 -14
  114. data/lib/autoproj/reporter.rb +19 -19
  115. data/lib/autoproj/repository_managers/apt.rb +101 -67
  116. data/lib/autoproj/repository_managers/unknown_os_manager.rb +3 -3
  117. data/lib/autoproj/shell_completion.rb +16 -13
  118. data/lib/autoproj/source_package_query.rb +29 -36
  119. data/lib/autoproj/system.rb +32 -21
  120. data/lib/autoproj/test.rb +127 -104
  121. data/lib/autoproj/variable_expansion.rb +7 -9
  122. data/lib/autoproj/vcs_definition.rb +35 -32
  123. data/lib/autoproj/version.rb +1 -1
  124. data/lib/autoproj/workspace.rb +123 -107
  125. data/lib/autoproj/zsh_completion.rb +8 -9
  126. data/lib/autoproj.rb +53 -55
  127. data/samples/autoproj/init.rb +1 -2
  128. metadata +53 -51
  129. data/.travis.yml +0 -24
@@ -1,301 +1,304 @@
1
1
  module Autoproj
2
2
  module Ops
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)
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
- def self.update_log_available?(manifest)
31
- new(manifest).import_state_log_package
32
- true
33
- rescue ArgumentError
34
- false
35
- end
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
- 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
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
- # create direcotry for versions file first
51
- FileUtils.mkdir_p(File.dirname( versions_file ))
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
- # augment the versions file with the updated versions
54
- versions = Snapshot.merge_packets( versions, existing_versions )
50
+ # create direcotry for versions file first
51
+ FileUtils.mkdir_p(File.dirname(versions_file))
55
52
 
56
- versions = sort_versions(versions)
53
+ # augment the versions file with the updated versions
54
+ versions = Snapshot.merge_packets(versions, existing_versions)
57
55
 
58
- # write the yaml file
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
- attr_reader :manifest
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
- # 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?; !!@keep_going end
64
+ def self.snapshot(packages, target_dir)
65
+ # todo
66
+ end
78
67
 
79
- def initialize(manifest, keep_going: false)
80
- @manifest = manifest
81
- @keep_going = keep_going
82
- end
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
- def snapshot_package_sets(target_dir = nil, only_local: true)
85
- result = Array.new
86
- manifest.each_package_set do |pkg_set|
87
- next if pkg_set.local?
81
+ def initialize(manifest, keep_going: false)
82
+ @manifest = manifest
83
+ @keep_going = keep_going
84
+ end
88
85
 
89
- vcs_info =
90
- begin pkg_set.snapshot(target_dir, only_local: only_local)
91
- rescue Exception => e
92
- error_or_warn(pkg_set, e)
93
- next
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
- def error_or_warn(package, error)
106
- if error.kind_of?(Interrupt)
107
- raise
108
- elsif keep_going?
109
- if !error.respond_to?(:to_str)
110
- error = error.message
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
- 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
- if !package
126
- raise ArgumentError, "#{package_name} is not a known package"
127
- end
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
- vcs_info =
138
- begin importer.snapshot(package.autobuild, target_dir, only_local: only_local)
139
- rescue Exception => e
140
- error_or_warn(package, e)
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
- if fingerprint
145
- vcs_info['fingerprint'] = package.autobuild.fingerprint(memo: fingerprint_memo)
146
- end
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
- if vcs_info
149
- result << Hash[package_name, vcs_info]
150
- else
151
- error_or_warn(package, "cannot snapshot #{package_name}: importer snapshot failed")
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
- # Returns the list of existing version tags
158
- def tags(package)
159
- importer = package.importer
160
- all_tags = importer.run_git_bare(package, 'tag')
161
- all_tags.find_all do |tag_name|
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
- # Returns a package that is used to store this installs import history
166
- #
167
- # Its importer is guaranteed to be a git importer
168
- #
169
- # @return [Autobuild::Package] a package whose importer is
170
- # {Autobuild::Git}
171
- def import_state_log_package
172
- pkg = manifest.main_package_set.create_autobuild_package
173
- if !pkg.importer
174
- if Autobuild::Git.can_handle?(pkg.srcdir)
175
- pkg.importer = Autobuild.git(pkg.srcdir)
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
- if !pkg.importer.kind_of?(Autobuild::Git)
180
- raise ArgumentError, "cannot use autoproj auto-import feature if the main configuration is not managed under git"
181
- end
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
- def self.import_state_log_ref
186
- "refs/autoproj"
187
- end
184
+ pkg
185
+ end
188
186
 
189
- DEFAULT_VERSIONS_FILE_BASENAME = "50-versions.yml"
187
+ def self.import_state_log_ref
188
+ "refs/autoproj"
189
+ end
190
190
 
191
- def import_state_log_file
192
- File.join(Workspace::OVERRIDES_DIR, DEFAULT_VERSIONS_FILE_BASENAME)
193
- end
191
+ DEFAULT_VERSIONS_FILE_BASENAME = "50-versions.yml"
194
192
 
195
- def current_import_state
196
- main = import_state_log_package
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
- def update_package_import_state(name, packages)
207
- current_versions = current_import_state
208
- if current_versions.empty?
209
- # Do a full snapshot this time only
210
- Autoproj.message " building initial autoproj import log, this may take a while"
211
- packages = manifest.all_selected_source_packages.
212
- find_all { |pkg| File.directory?(pkg.autobuild.srcdir) }.
213
- map(&:name)
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
- def save_import_state(name, versions)
222
- versions = sort_versions(versions)
223
-
224
- main = import_state_log_package
225
- git_dir = main.importer.git_dir(main, false)
226
- # Ensure that our ref is being logged
227
- FileUtils.touch File.join(git_dir, 'logs', *self.class.import_state_log_ref.split("/"))
228
- # Create the commit with the versions info
229
- commit_id = Snapshot.create_commit(main, import_state_log_file, name, real_author: false) do |io|
230
- YAML.dump(versions, io)
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
- # Create a git commit in which a file contains provided content
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
- cacheinfo = ["100644", object_id, path]
263
- if Autobuild::Git.at_least_version(2, 1)
264
- cacheinfo = cacheinfo.join(",")
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
- parent_id ||= importer.rev_parse(pkg, 'HEAD')
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
- env = Hash.new
270
- if !real_author
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
- # Create the tree using a temporary index in order to not mess with
278
- # the user's index state. read-tree initializes the new index and
279
- # then we add the overrides file with update-index / write-tree
280
- our_index = File.join(importer.git_dir(pkg, false), 'index.autoproj')
281
- FileUtils.rm_f our_index
282
- begin
283
- ENV['GIT_INDEX_FILE'] = our_index
284
- importer.run_git_bare(pkg, 'read-tree', parent_id)
285
- # And add the new file
286
- importer.run_git_bare(
287
- pkg, 'update-index',
288
- '--add', '--cacheinfo', *cacheinfo)
289
- tree_id = importer.run_git_bare(pkg, 'write-tree').first
290
- ensure
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
- end
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
- importer.run_git_bare(
296
- pkg, 'commit-tree',
297
- tree_id, '-p', parent_id, env: env, input_streams: [message]).first
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