reapack-index 1.1rc4 → 1.1rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 055dade2288572ca9c5ba6b088830910e4c02ba4
4
- data.tar.gz: c0a47135f969d857dd62758411e24c3c55ee11b6
3
+ metadata.gz: 521e9cf95253116fdbdae336d5e103e412800a63
4
+ data.tar.gz: 0ba6258b623ec7dc4daefc2055ba8cd9e5a147a8
5
5
  SHA512:
6
- metadata.gz: b36c261cb78483239b8c7130f60ed1140e82b439ed3d7b63b37a70f829575cab3c4811384bfac35f6420e9102f27b620aba1baf512ad396d9c90675c59d11434
7
- data.tar.gz: 76444bacda5d294b627caf9f53167675dd6980f1edb5ff4771f73db4c1438d51ed7ccaa906b9d90ce96ef09af2746ac7bd553678aada64190c9b375165944c91
6
+ metadata.gz: 0cbe24ed175822879c0dc9fff484b6311c7d3a53d4000d8ee7036d885184e85b448f8f953fb5ca5f50b872556cc826e2b521845166fca18637867d98f9dc5624
7
+ data.tar.gz: a747dc392326879db9980f449ac483d13b92d8a6d0de0e003f2b6242957cf23e718f24ea8cc4b9af68b6d5f55f20ffdc2e48770b95a504ae3543120e300adcc3
data/README.md CHANGED
@@ -29,7 +29,7 @@ reapack-index [options] [path-to-your-repository]
29
29
  ```
30
30
  Modes:
31
31
  -c, --check Test every package including uncommited changes and exit
32
- -s, --scan [FILE|COMMIT] Scan new commits (default), a file or a commit
32
+ -s, --scan [PATH|COMMIT] Scan new commits (default), a path or a specific commit
33
33
  --no-scan Do not scan for new commits
34
34
  --rebuild Clear the index and rescan the whole git history
35
35
  Indexer options:
@@ -56,7 +56,7 @@ class ReaPack::Index::CLI
56
56
  opts[:check] = true
57
57
  end
58
58
 
59
- op.on '-s', '--scan [FILE|COMMIT]', 'Scan new commits (default), a file or a commit' do |commit|
59
+ op.on '-s', '--scan [PATH|COMMIT]', 'Scan new commits (default), a path or a specific commit' do |commit|
60
60
  opts[:check] = opts[:rebuild] = false
61
61
  opts[:scan] ||= []
62
62
 
@@ -78,16 +78,23 @@ private
78
78
  else
79
79
  @index.auto_bump_commit = false
80
80
 
81
+ # call process_commit only once per commit instead of once per --scan argument
82
+ commits = Hash.new
81
83
  @opts[:scan].map {|hash|
82
- if c = @git.last_commit_for(@git.relative_path hash)
83
- [c, hash]
84
+ files = @git.last_commits_for @git.relative_path(hash)
85
+ if !files.empty?
86
+ files.each {|commit, files|
87
+ commits[commit] = Array.new unless commits.has_key? commit # keep nil
88
+ commits[commit].concat files unless commits[commit].nil?
89
+ }
84
90
  elsif c = @git.get_commit(hash)
85
- c
91
+ commits[c] = nil
86
92
  else
87
93
  $stderr.puts "--scan: bad file or revision: '%s'" % hash
88
94
  throw :stop, false
89
95
  end
90
- }.compact
96
+ }
97
+ commits.to_a
91
98
  end
92
99
 
93
100
  unless commits.empty?
@@ -97,7 +104,7 @@ private
97
104
  end
98
105
  end
99
106
 
100
- def process_commit(commit, file = nil)
107
+ def process_commit(commit, files = nil)
101
108
  if @opts[:verbose]
102
109
  log 'processing %s: %s' % [commit.short_id, commit.summary]
103
110
  end
@@ -108,9 +115,9 @@ private
108
115
 
109
116
  commit.each_diff
110
117
  .select {|diff|
111
- (file.nil? || diff.file == file) &&
118
+ (files.nil? || files.include?(diff.file)) &&
112
119
  (not ignored? expand_path(diff.file)) &&
113
- ReaPack::Index.type_of(diff.file)
120
+ ReaPack::Index.is_package?(diff.file)
114
121
  }
115
122
  .sort_by {|diff|
116
123
  diff.status == :deleted || diff.new_header[:noindex] ? 0 : 1
@@ -1,5 +1,6 @@
1
1
  module ReaPack
2
2
  class Index
3
- VERSION = '1.1rc4'
3
+ # bump in setup/reapack-index.nsi too
4
+ VERSION = '1.1rc5'
4
5
  end
5
6
  end
@@ -50,6 +50,20 @@ class ReaPack::Index
50
50
  }
51
51
  end
52
52
 
53
+ def last_commits_for(pattern)
54
+ dir = pattern.empty? ? '' : pattern + '/'
55
+ out = Hash.new
56
+ last_commit.filelist.each {|file|
57
+ path = File.split(file).first + '/'
58
+ next unless path.start_with?(dir) || file == pattern
59
+
60
+ commit = last_commit_for(file)
61
+ out[commit] ||= Array.new
62
+ out[commit] << file
63
+ }
64
+ out
65
+ end
66
+
53
67
  def guess_url_template
54
68
  remote = @repo.remotes['origin']
55
69
  return unless remote
@@ -67,7 +81,8 @@ class ReaPack::Index
67
81
  root = Pathname.new self.path
68
82
  file = Pathname.new File.expand_path(path)
69
83
 
70
- file.relative_path_from(root).to_s
84
+ rel = file.relative_path_from(root).to_s
85
+ rel == '.' ? '' : rel
71
86
  end
72
87
 
73
88
  def create_commit(message, files)
@@ -163,6 +178,12 @@ class ReaPack::Index
163
178
  o && id == o.id
164
179
  end
165
180
 
181
+ alias :eql? :==
182
+
183
+ def hash
184
+ id.hash
185
+ end
186
+
166
187
  def inspect
167
188
  "#<#{self.class} #{id} #{summary}>"
168
189
  end
@@ -1,11 +1,15 @@
1
1
  class ReaPack::Index
2
- Provides = Struct.new :file_pattern, :url_template, :platform, :type, :main do
2
+ Provides = Struct.new :file_pattern, :url_template, :target, :platform, :type, :main do
3
3
  PROVIDES_REGEX = /
4
4
  \A
5
- ( \[ \s* (?<options> .+? ) \s* \] )?
5
+ (?: \[ \s* (?<options> .+? ) \s* \] )?
6
6
  \s*
7
- (?<file> .+?)
8
- ( \s+ (?<url> (?:file|https?):\/\/.+ ) )?
7
+ (?<pattern>.+?)
8
+ (?:
9
+ \s*>\s*(?<target>.+?)
10
+ |
11
+ \s+ (?<url_tpl>(?:file|https?):\/\/.+)
12
+ )?
9
13
  \z
10
14
  /x.freeze
11
15
 
@@ -24,11 +28,9 @@ class ReaPack::Index
24
28
  m = line.strip.match PROVIDES_REGEX
25
29
  return unless m
26
30
 
27
- options, pattern, url_tpl = m[:options], m[:file], m[:url]
31
+ instance = self.new m[:pattern], m[:url_tpl], m[:target]
28
32
 
29
- instance = self.new pattern, url_tpl
30
-
31
- options and options.split("\x20").each {|user_opt|
33
+ m[:options]&.split("\x20")&.each {|user_opt|
32
34
  user_opt.strip!
33
35
  next if user_opt.empty?
34
36
 
@@ -37,7 +37,7 @@ class ReaPack::Index
37
37
 
38
38
  HEADER_ALIASES = {
39
39
  [:reascript_name, :jsfx_name, :theme_name,
40
- :extension_name, :desc] => :description,
40
+ :extension_name, :desc, :name] => :description,
41
41
  [:links, :website] => :link,
42
42
  :screenshots => :screenshot,
43
43
  }.freeze
@@ -47,6 +47,7 @@ class ReaPack::Index
47
47
  def initialize(cat, pkg, mh, index)
48
48
  @cat, @pkg, @mh, @index = cat, pkg, mh, index
49
49
  @cselector = @index.cdetector[pkg.path]
50
+ @self_overriden = false
50
51
  end
51
52
 
52
53
  def run
@@ -76,7 +77,7 @@ class ReaPack::Index
76
77
  @cselector.clear
77
78
  sources = parse_provides @mh[:provides]
78
79
 
79
- if !metapackage? && sources.none? {|src| src.file.nil? }
80
+ unless metapackage? || @self_overriden
80
81
  # add the package itself as a main source
81
82
  src = Source.new make_url(@pkg.path)
82
83
  src.detect_sections @pkg
@@ -142,6 +143,13 @@ class ReaPack::Index
142
143
  end
143
144
 
144
145
  files.map {|file|
146
+ if line.target
147
+ target = line.target
148
+ expanded = ReaPack::Index.expand line.target, @pkg.category
149
+ else
150
+ target = file
151
+ end
152
+
145
153
  src = Source.new make_url(file, line.url_template)
146
154
  src.platform = line.platform
147
155
  src.type = line.type
@@ -154,7 +162,7 @@ class ReaPack::Index
154
162
  end
155
163
 
156
164
  @cselector.push src.type || @pkg.type, src.platform,
157
- line.url_template ? expanded : file
165
+ line.url_template || line.target ? expanded : target
158
166
 
159
167
  if file == @pkg.path
160
168
  if metapackage?
@@ -164,9 +172,14 @@ class ReaPack::Index
164
172
  # not a metapackage? then the current file is registered by default
165
173
  src.detect_sections @pkg
166
174
  end
175
+
176
+ src.file = target if line.target
177
+ @self_overriden = true
167
178
  else
168
179
  if line.url_template
169
180
  src.file = file
181
+ elsif line.target
182
+ src.file = target
170
183
  else
171
184
  src.file = Pathname.new(file).relative_path_from(pathdir).to_s
172
185
  end
data/lib/reapack/index.rb CHANGED
@@ -37,6 +37,7 @@ class ReaPack::Index
37
37
  effect: %w{jsfx},
38
38
  data: %w{data},
39
39
  theme: %w{theme},
40
+ langpack: %w{ReaperLangPack},
40
41
  }.freeze
41
42
 
42
43
  FS_ROOT = File.expand_path('/').freeze
@@ -4,7 +4,7 @@ Unicode true
4
4
  !include Sections.nsh
5
5
  !include StrRep.nsh
6
6
 
7
- !define VERSION "1.1rc4"
7
+ !define VERSION "1.1rc5"
8
8
  !define NAME "reapack-index ${VERSION}"
9
9
  !define LONG_VERSION "0.1.0.0"
10
10
 
@@ -318,8 +318,6 @@ processing [a-f0-9]{7}: third commit
318
318
  end
319
319
 
320
320
  def test_scan_file
321
- options = [ '--scan', 'cat/test1.lua']
322
-
323
321
  setup = proc {
324
322
  Dir.chdir @git.path
325
323
 
@@ -329,19 +327,123 @@ processing [a-f0-9]{7}: third commit
329
327
  @git.create_commit 'second commit', [
330
328
  mkfile('cat/test1.lua', '@version 2'),
331
329
  mkfile('cat/test2.lua', '@version 2.2'),
330
+ mkfile('cat/test3.lua', '@version 3'),
332
331
  ]
333
332
 
334
333
  @git.create_commit 'third commit',
335
- [mkfile('cat/test3.lua', '@version 3')]
334
+ [mkfile('cat/test4.lua', '@version 4')]
335
+ }
336
+
337
+ wrapper ['--progress', '--scan', 'cat/test1.lua', '--scan', 'cat/test2.lua'],
338
+ setup: setup do
339
+ stdin, stderr = capture_io { @cli.run }
340
+
341
+ contents = read_index
342
+ refute_match 'version name="1"', contents, 'The initial commit was scanned'
343
+ assert_match 'version name="2"', contents
344
+ assert_match 'test2.lua', contents, 'test2.lua was indexed'
345
+ refute_match 'test3.lua', contents, 'The third commit was scanned'
346
+
347
+ assert_match /Indexing commit \d+ of 1/, stderr # not 3 commits!
348
+ end
349
+ end
350
+
351
+ def test_scan_directory
352
+ setup = proc {
353
+ Dir.chdir @git.path
354
+
355
+ mkfile('dir1/uncommited.lua')
356
+
357
+ @git.create_commit 'initial commit',
358
+ [mkfile('dir1/test1.lua', '@version 1')]
359
+
360
+ @git.create_commit 'second commit', [
361
+ mkfile('dir1/test2.lua', '@version 2'),
362
+ mkfile('dir1/sub/test3.lua', '@version 3'),
363
+ mkfile('dir2/test4.lua', '@version 4'),
364
+ ]
365
+ }
366
+
367
+ wrapper ['--progress', '--scan', 'dir1'], setup: setup do
368
+ stdout, stderr = capture_io { @cli.run }
369
+
370
+ contents = read_index
371
+ assert_match 'test1.lua', contents
372
+ assert_match 'test2.lua', contents
373
+ assert_match 'test3.lua', contents
374
+ refute_match 'test4.lua', contents, 'test4.lua was indexed'
375
+
376
+ assert_match /Indexing commit \d+ of 2/, stderr # not 3 commits!
377
+ end
378
+ end
379
+
380
+ def test_scan_directory_uncommited
381
+ setup = proc {
382
+ Dir.chdir @git.path
383
+
384
+ mkfile('dir/uncommited.lua')
385
+ }
386
+
387
+ wrapper ['--scan', 'dir'], setup: setup do
388
+ @git.create_commit 'initial commit', [mkfile('README.md')]
389
+
390
+ assert_output nil, /--scan: bad file or revision: 'dir'/i do
391
+ assert_throws(:stop, false) { @cli.run }
392
+ end
393
+ end
394
+ end
395
+
396
+ def test_scan_directory_absolute
397
+ options = ['--scan', nil]
398
+
399
+ setup = proc {
400
+ @git.create_commit 'initial commit',
401
+ [mkfile('dir/test.lua', '@version 1')]
402
+ options[1] = mkpath('dir')
336
403
  }
337
404
 
338
405
  wrapper options, setup: setup do
339
406
  capture_io { @cli.run }
340
407
 
341
- refute_match 'version name="1"', read_index, 'The initial commit was scanned'
342
- assert_match 'version name="2"', read_index
343
- refute_match 'test2.lua', read_index, 'test2.lua was indexed'
344
- refute_match 'test3.lua', read_index, 'The third commit was scanned'
408
+ assert_match 'test.lua', read_index
409
+ end
410
+ end
411
+
412
+ def test_scan_directory_root
413
+ setup = proc {
414
+ Dir.chdir @git.path
415
+
416
+ @git.create_commit 'initial commit',
417
+ [mkfile('dir1/test1.lua', '@version 1'),
418
+ mkfile('dir2/test2.lua', '@version 2')]
419
+ }
420
+
421
+ wrapper ['--scan', '.'], setup: setup do
422
+ capture_io { @cli.run }
423
+
424
+ contents = read_index
425
+ assert_match 'test1.lua', contents
426
+ assert_match 'test2.lua', contents
427
+ end
428
+ end
429
+
430
+ def test_scan_stick_to_full_commit
431
+ options = ['--scan', nil, '--scan', 'cat/test1.lua']
432
+
433
+ setup = proc {
434
+ Dir.chdir @git.path
435
+
436
+ @git.create_commit 'initial commit',
437
+ [mkfile('cat/test1.lua', '@version 1'),
438
+ mkfile('cat/test2.lua', '@version 2')]
439
+
440
+ options[1] = @git.last_commit.id
441
+ }
442
+
443
+ wrapper options, setup: setup do
444
+ capture_io { @cli.run }
445
+
446
+ assert_match 'test2.lua', read_index
345
447
  end
346
448
  end
347
449
 
@@ -360,4 +360,47 @@ class TestIndex::Provides < MiniTest::Test
360
360
  refute_match 'main="main"', contents
361
361
  assert_match '<source>http://host/Category/script.lua</source>', contents
362
362
  end
363
+
364
+ def test_rename_target
365
+ index = ReaPack::Index.new @dummy_path
366
+ index.files = ['Category/source.lua', 'Category/source.png']
367
+ index.url_template = 'http://host/$path'
368
+
369
+ index.scan index.files.first, <<-IN
370
+ @version 1.0
371
+ @provides
372
+ source.lua > target.lua
373
+ source.png > target.png
374
+ IN
375
+
376
+ index.write!
377
+
378
+ xml = File.read index.path
379
+
380
+ assert_match 'file="target.lua"', xml
381
+ assert_match 'file="target.png"', xml
382
+ refute_match 'file="source.png"', xml
383
+
384
+ assert_equal 1,
385
+ xml.scan(/#{Regexp.quote('http://host/Category/source.lua')}/).count
386
+ assert_match 'http://host/Category/source.png', xml
387
+ end
388
+
389
+ def test_rename_target_no_wrong_conflict
390
+ index = ReaPack::Index.new @dummy_path
391
+
392
+ # target.lua is not in the same directory
393
+ index.files = ['Category/s1.lua', 'target.lua', 'Category/s2.lua']
394
+ index.url_template = 'http://host/$path'
395
+
396
+ index.scan index.files.first, <<-IN
397
+ @version 1.0
398
+ @provides . > target.lua
399
+ IN
400
+
401
+ index.scan index.files.last, <<-IN
402
+ @version 1.0
403
+ @provides ../target.lua
404
+ IN
405
+ end
363
406
  end
@@ -226,4 +226,30 @@ class TestIndex::Scan < MiniTest::Test
226
226
  index.write!
227
227
  assert_equal expected, File.read(index.path)
228
228
  end
229
+
230
+ def test_langpack
231
+ index = ReaPack::Index.new @dummy_path
232
+ index.url_template = 'http://host/$path'
233
+ index.files = ['Translations/French.ReaperLangPack']
234
+
235
+ index.scan index.files.first, <<-IN
236
+ @version 1.0
237
+ IN
238
+
239
+ expected = <<-XML
240
+ <?xml version="1.0" encoding="utf-8"?>
241
+ <index version="1">
242
+ <category name="Translations">
243
+ <reapack name="French.ReaperLangPack" type="langpack">
244
+ <version name="1.0">
245
+ <source>http://host/Translations/French.ReaperLangPack</source>
246
+ </version>
247
+ </reapack>
248
+ </category>
249
+ </index>
250
+ XML
251
+
252
+ index.write!
253
+ assert_equal expected, File.read(index.path)
254
+ end
229
255
  end
data/test/test_git.rb CHANGED
@@ -19,6 +19,7 @@ class TestGit < MiniTest::Test
19
19
  def test_relative_path
20
20
  assert_equal 'test', @git.relative_path(File.join(@git.path, 'test'))
21
21
  assert_match 'test', @git.relative_path('test')
22
+ assert_equal '', @git.relative_path(File.join(@git.path, '.'))
22
23
  end
23
24
 
24
25
  def test_guess_url_template
@@ -140,6 +141,26 @@ class TestGit < MiniTest::Test
140
141
  assert_nil @git.last_commit_for('foo/bar')
141
142
  end
142
143
 
144
+ def test_last_commits_for_directory
145
+ c1 = @git.create_commit 'first commit', [mkfile('hello/world')]
146
+ c2 = @git.create_commit 'second commit', [mkfile('hello/world', 'modified')]
147
+ c3 = @git.create_commit 'third commit', [mkfile('chunky/bacon')]
148
+ c4 = @git.create_commit 'fourth commit', [mkfile('hello/sub/world')]
149
+ c5 = @git.create_commit 'fifth commit',
150
+ [mkfile('helloworld/a'), mkfile('hello-world')]
151
+
152
+ assert_equal({c2 => ['hello/world'], c4 => ['hello/sub/world']},
153
+ @git.last_commits_for('hello'))
154
+ assert_equal({c3 => ['chunky/bacon']}, @git.last_commits_for('chunky'))
155
+ assert_equal({c4 => ['hello/sub/world']}, @git.last_commits_for('hello/sub'))
156
+ assert_empty @git.last_commits_for('foobar')
157
+
158
+ assert_equal({c2 => ['hello/world']}, @git.last_commits_for('hello/world'))
159
+ assert_equal({c3 => ['chunky/bacon'], c5 => ['hello-world', 'helloworld/a'],
160
+ c4 => ['hello/sub/world'], c2 => ['hello/world']},
161
+ @git.last_commits_for(''))
162
+ end
163
+
143
164
  def test_multibyte_filename
144
165
  filename = "\342\200\224.lua"
145
166
 
data/test/test_index.rb CHANGED
@@ -20,6 +20,7 @@ class TestIndex < MiniTest::Test
20
20
  'Cat/test.jsfx' => :effect,
21
21
  'Cat/test.data' => :data,
22
22
  'Cat/test.theme' => :theme,
23
+ 'Cat/test.ReaperLangPack' => :langpack,
23
24
  }.each {|fn, type|
24
25
  actual = ReaPack::Index.type_of fn
25
26
  assert_equal type, actual,
@@ -41,6 +42,7 @@ class TestIndex < MiniTest::Test
41
42
  'ext' => :extension,
42
43
  'data' => :data,
43
44
  'theme' => :theme,
45
+ 'langpack' => :langpack,
44
46
  }.each {|input, type|
45
47
  actual = ReaPack::Index.resolve_type input
46
48
  assert_equal type, actual,
@@ -66,6 +66,18 @@ class TestProvides < MiniTest::Test
66
66
  ].map {|l| ReaPack::Index::Provides.parse(l).main? }
67
67
  end
68
68
 
69
+ def test_target
70
+ l1 = ReaPack::Index::Provides.parse 'src.txt > dst.txt'
71
+ assert_equal 'src.txt', l1.file_pattern
72
+ assert_equal 'dst.txt', l1.target
73
+ assert_nil l1.url_template
74
+
75
+ l2 = ReaPack::Index::Provides.parse 'src.txt>dst.txt http://test.com'
76
+ assert_equal 'src.txt', l2.file_pattern
77
+ assert_equal 'dst.txt http://test.com', l2.target
78
+ assert_nil l2.url_template
79
+ end
80
+
69
81
  def test_invalid_options
70
82
  assert_equal ["unknown option 'HeLlO'", "unknown option 'Test'"],
71
83
  [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reapack-index
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1rc4
4
+ version: 1.1rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - cfillion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-29 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler