p4_web_api 2014.2.0.pre2 → 2014.2.0.pre4

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.
@@ -71,6 +71,37 @@ module P4WebAPI
71
71
  .match(str)
72
72
  end
73
73
 
74
+ def self.init_changelist(p4, description)
75
+ change_spec = p4.fetch_change
76
+ change_spec._description = description
77
+ results = p4.save_change(change_spec)
78
+ results[0].gsub(/^Change (\d+) created./, '\1')
79
+ end
80
+
81
+ def self.save_content(root, depot_path, content)
82
+ local_file = local_path(depot_path, root)
83
+ dir = File.dirname(local_file)
84
+ FileUtils.mkpath(dir) unless Dir.exist?(dir)
85
+
86
+ IO.write(local_file, content)
87
+ end
88
+
89
+ def self.existing_path?(existing_results, depot_path)
90
+ existing_results.any? do |result|
91
+ result['depotFile'] == depot_path
92
+ end
93
+ end
94
+
95
+ def self.mark_change(type, p4, change_id, root, depot_path)
96
+ local_file = local_path(depot_path, root)
97
+ p4.run(type, '-c', change_id, local_file)
98
+ end
99
+
100
+ def self.local_path(depot_path, root)
101
+ stripped = depot_path.gsub(/^\/+/, '')
102
+ File.join(root, stripped)
103
+ end
104
+
74
105
  def self.singular(plural)
75
106
  matches = {
76
107
  branches: 'branch',
@@ -110,7 +141,6 @@ module P4WebAPI
110
141
  'changeType' => 'Type',
111
142
  'desc' => 'Description'
112
143
  }
113
- DESCRIBES_MAP = CHANGES_MAP
114
144
  CHANGES_DATES = ['Date']
115
145
 
116
146
  CLIENTS_MAP = {
@@ -127,6 +157,11 @@ module P4WebAPI
127
157
  }
128
158
  DEPOTS_DATES = ['Date']
129
159
 
160
+ # Note that individual files are handled differently, since the keys are
161
+ # prefixed
162
+ DESCRIBE_MAP = CHANGES_MAP
163
+ DESCRIBE_DATES = CHANGES_DATES
164
+
130
165
  DIRS_MAP = {
131
166
  'dir' => 'Dir'
132
167
  }
@@ -199,6 +234,14 @@ module P4WebAPI
199
234
  make_normalizer(CLIENTS_MAP, offset, CLIENTS_DATES)
200
235
  when 'depots'
201
236
  make_normalizer(DEPOTS_MAP, offset, DEPOTS_DATES)
237
+ when 'describe'
238
+ # This only affects 'base' fields, not fields related to each file
239
+ base_normalize = make_normalizer(DESCRIBE_MAP, offset, DESCRIBE_DATES)
240
+ lambda do |results|
241
+ results = base_normalize.call(results)
242
+ P4Util.normalize_describe_files(results)
243
+ results
244
+ end
202
245
  when 'dirs'
203
246
  make_normalizer(DIRS_MAP, offset)
204
247
  when 'files'
@@ -292,6 +335,52 @@ module P4WebAPI
292
335
  end
293
336
  end
294
337
 
338
+ FILE_KEYS = %w(depotFile action type rev digest fileSize)
339
+
340
+ # Each file entry in the base describe tagged output contains several
341
+ # fields, suffixed with an index value.
342
+ #
343
+ # P4 Ruby returns the individual 'index fields' already collated by the
344
+ # key type.
345
+ def self.normalize_describe_files(results)
346
+ results.each do |r|
347
+ # We have to collect each index we discover as we iterate over the keys
348
+ idx_2_file = {}
349
+
350
+ FILE_KEYS.each do |key|
351
+ if r.key?(key)
352
+ r[key].each_index do |idx|
353
+ mapped_key = P4Util.map_describe_file_key(key)
354
+
355
+ idx_2_file[idx] = {} unless idx_2_file.key?(idx)
356
+ idx_2_file[idx][mapped_key] = r[key][idx]
357
+ end
358
+ r.delete(key)
359
+ end
360
+ end
361
+
362
+ r['Files'] = idx_2_file.values
363
+ end
364
+ results
365
+ end
366
+
367
+ def self.map_describe_file_key(key)
368
+ case key
369
+ when /^depotFile$/
370
+ return 'DepotFile'
371
+ when /^action$/
372
+ return 'Action'
373
+ when /^type$/
374
+ return 'Type'
375
+ when /^rev$/
376
+ return 'Revision'
377
+ when /^fileSize$/
378
+ return 'FileSize'
379
+ when /^digest$/
380
+ return 'Digest'
381
+ end
382
+ end
383
+
295
384
  # Returns true if .to_i will actually convert this string to an integer
296
385
  def self.i?(str)
297
386
  (str =~ /\A[-+]?\d+\z/)
@@ -2,5 +2,5 @@
2
2
  # format, with a RubyGems-style suffix for 'prereleases'. Please use your branch
3
3
  # as the prerelease label.
4
4
  module P4WebAPI
5
- VERSION = '2014.2.0.pre2'
5
+ VERSION = '2014.2.0.pre4'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: p4_web_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2014.2.0.pre2
4
+ version: 2014.2.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perforce Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-01 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -218,7 +218,18 @@ extra_rdoc_files: []
218
218
  files:
219
219
  - bin/p4_web_api
220
220
  - lib/p4_web_api.rb
221
+ - lib/p4_web_api/app/changes.rb
222
+ - lib/p4_web_api/app/commands.rb
223
+ - lib/p4_web_api/app/files.rb
224
+ - lib/p4_web_api/app/protections.rb
225
+ - lib/p4_web_api/app/sessions.rb
226
+ - lib/p4_web_api/app/specs.rb
227
+ - lib/p4_web_api/app/streams.rb
228
+ - lib/p4_web_api/app/triggers.rb
229
+ - lib/p4_web_api/app/users.rb
221
230
  - lib/p4_web_api/auth.rb
231
+ - lib/p4_web_api/change_helper.rb
232
+ - lib/p4_web_api/helpers.rb
222
233
  - lib/p4_web_api/p4_error.rb
223
234
  - lib/p4_web_api/p4_util.rb
224
235
  - lib/p4_web_api/version.rb