p4tools 0.1.4.1 → 0.2.0.0

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.
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  source 'https://rubygems.herokuapp.com/'
4
4
 
5
5
  gem 'P4Ruby-mingwx86', '~> 2014.1'
6
- gem 'rake'
6
+ gem 'rake'
7
+ gem 'awesome_print'
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ GEM
3
3
  remote: https://rubygems.herokuapp.com/
4
4
  specs:
5
5
  P4Ruby-mingwx86 (2014.1)
6
+ awesome_print (1.2.0)
6
7
  rake (10.3.1)
7
8
 
8
9
  PLATFORMS
@@ -10,4 +11,5 @@ PLATFORMS
10
11
 
11
12
  DEPENDENCIES
12
13
  P4Ruby-mingwx86 (~> 2014.1)
14
+ awesome_print
13
15
  rake
data/LICENSE ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ {description}
294
+ Copyright (C) {year} {fullname}
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ {signature of Ty Coon}, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/Rakefile CHANGED
@@ -5,18 +5,33 @@ def gem_name
5
5
  @gem_name ||= "#{P4Tools::PROJECT_NAME}-#{P4Tools::VERSION}"
6
6
  end
7
7
 
8
+ def build_gem
9
+ system("gem build #{P4Tools::PROJECT_NAME}.gemspec")
10
+ end
11
+
12
+ def delete_gem
13
+ File.delete("#{gem_name}.gem")
14
+ end
15
+
8
16
  task :check_version do
9
17
  abort 'Update version before release!' unless %x{git tag -l #{gem_name}}.empty?
10
18
  end
11
19
 
12
20
  task :release => [:check_version] do
13
- if system("gem build #{P4Tools::PROJECT_NAME}.gemspec")
21
+ if build_gem
14
22
  system "git tag #{gem_name}"
15
23
  system 'git push --tags'
16
24
  system "gem push #{gem_name}.gem"
17
25
 
18
- File.delete("#{gem_name}.gem")
26
+ delete_gem
19
27
  end
28
+ end
29
+
30
+ task :update do
31
+ if build_gem
32
+ system "gem install #{gem_name}.gem"
20
33
 
34
+ delete_gem
35
+ end
21
36
  end
22
37
 
@@ -0,0 +1,52 @@
1
+ module P4Tools
2
+ class Describe
3
+
4
+ def self.run(arguments)
5
+ Describe.new(arguments).run
6
+ end
7
+
8
+ def self.set_options(opts)
9
+ opts.set do
10
+ help 'Provides information about changelists and the changelists files.'
11
+ help ''
12
+ help 'Options:'
13
+ help ''
14
+ arg :submitted, 'Find pending CL number, based on submitted CL number.', :short => '-s', :type => :ints
15
+ arg :pending, 'Find submitted CL number, based on pending CL number.', :short => '-p', :type => :ints
16
+ end
17
+ end
18
+
19
+
20
+ def initialize(args)
21
+ @pending = args[:pending]
22
+ @submitted = args[:submitted]
23
+
24
+ @p4 = P4Tools.connection
25
+ end
26
+
27
+ def run
28
+ if !@submitted.nil?
29
+ numbers = find_pending
30
+ report(numbers)
31
+ elsif !@pending.nil?
32
+ numbers = find_submitted
33
+ report(numbers)
34
+ end
35
+ end
36
+
37
+ def find_submitted
38
+ @p4.run_describe('-s', '-O', @pending)
39
+ end
40
+
41
+ def find_pending
42
+ @p4.run_describe('-s', @submitted)
43
+ end
44
+
45
+ def report(numbers)
46
+ numbers.each { |num|
47
+ p "pending: #{num['oldChange']}, submitted: #{num['change']}"
48
+ }
49
+ end
50
+
51
+ end
52
+ end
data/lib/commands/move.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module P4Tools
2
2
  class Move
3
- include CommandUtils
4
3
 
5
4
  def self.run(arguments)
6
5
  Move.new(arguments).run
@@ -23,21 +22,32 @@ module P4Tools
23
22
 
24
23
 
25
24
  def initialize(args)
26
- @args = args
25
+ @workspace = args[:workspace]
26
+ @switch = args[:switch]
27
+ @changelists = args[:changelists]
28
+ @revert = args[:revert]
29
+ @shelve = args[:shelve]
30
+
27
31
  @p4 = P4Tools.connection
28
- workspaces = @args[:switch]
32
+ end
33
+
34
+ def run
35
+ prepare_workspaces
36
+ move_changelists
37
+ end
29
38
 
30
- if workspaces
31
- validate_workspaces(workspaces)
39
+ def prepare_workspaces
40
+ if @switch
41
+ validate_workspaces(@switch)
32
42
 
33
- @workspaces = Hash[workspaces.permutation.to_a]
43
+ @workspaces = Hash[@switch.permutation.to_a]
34
44
  end
35
45
  end
36
46
 
37
- def run
38
- @args[:changelists].each do |changelist|
47
+ def move_changelists
48
+ @changelists.each do |changelist|
39
49
  @changelist = changelist
40
- @is_not_empty = !empty_changelist?(@changelist)
50
+ @is_not_empty = !CommandUtils.empty_changelist?(@changelist)
41
51
 
42
52
  shelve
43
53
  revert
@@ -48,17 +58,14 @@ module P4Tools
48
58
  end
49
59
  end
50
60
 
51
-
52
- private
53
-
54
61
  def shelve
55
- if @args[:shelve] && @is_not_empty
62
+ if @shelve && @is_not_empty
56
63
  @p4.run_shelve('-f', '-c', @changelist)
57
64
  end
58
65
  end
59
66
 
60
67
  def revert
61
- if @args[:revert] && @is_not_empty && all_files_shelved?(@changelist, true)
68
+ if @revert && @is_not_empty && CommandUtils.changelist_shelved?(@changelist)
62
69
  @p4.run_revert('-w', '-c', @changelist, '//...')
63
70
  end
64
71
  end
@@ -70,7 +77,7 @@ module P4Tools
70
77
 
71
78
  @workspaces[current]
72
79
  else
73
- @args[:workspace]
80
+ @workspace
74
81
  end
75
82
  end
76
83
 
@@ -1,33 +1,8 @@
1
1
  module P4Tools
2
2
  class Revert
3
- extend CommandUtils
4
3
 
5
4
  def self.run(arguments)
6
- p4 = P4Tools.connection
7
- parameters = []
8
- parameters.push('-w') if arguments[:delete_added_files]
9
- check_shelve = arguments[:check_shelve]
10
-
11
- if arguments[:changelists]
12
- parameters.push('-c').push('').push('//...')
13
-
14
- arguments[:changelists].each do |changelist|
15
- if check_shelve && !all_files_shelved?(changelist, true)
16
- raise(StandardError, "Not all files are shelved in changelist: #{changelist}")
17
- end
18
-
19
- parameters[-2] = changelist
20
- p4.run_revert(parameters)
21
- end
22
- else
23
- if check_shelve
24
- raise(ArgumentError, "The check shelve option only works with changelists!")
25
- end
26
-
27
- parameters.push(*arguments[:files])
28
- p4.run_revert(parameters)
29
- end
30
-
5
+ Revert.new(arguments).run
31
6
  end
32
7
 
33
8
  def self.set_options(opts)
@@ -42,5 +17,60 @@ module P4Tools
42
17
  arg :files, 'The absolute path of the files to delete.', :short => '-f', :type => :strings
43
18
  end
44
19
  end
20
+
21
+
22
+ def initialize(args)
23
+ @delete_added_files = args[:delete_added_files]
24
+ @check_shelve = args[:check_shelve]
25
+ @changelists = args[:changelists]
26
+ @files = args[:files]
27
+
28
+ @p4 = P4Tools.connection
29
+ end
30
+
31
+ def run
32
+ if !@changelists.nil?
33
+ revert_changelists
34
+ elsif !@files.nil?
35
+ revert_files
36
+ end
37
+ end
38
+
39
+ def revert_files
40
+ check_shelved_files(@files)
41
+
42
+ parameters = []
43
+ if @delete_added_files
44
+ parameters.push('-w')
45
+ end
46
+
47
+ parameters.push(*@files)
48
+ @p4.run_revert(parameters)
49
+ end
50
+
51
+ def revert_changelists
52
+ @changelists.each do |changelist|
53
+ check_shelved_changelist(changelist)
54
+
55
+ if @delete_added_files
56
+ @p4.run_revert('-w', '-c', changelist, '//...')
57
+ else
58
+ @p4.run_revert('-c', changelist, '//...')
59
+ end
60
+ end
61
+ end
62
+
63
+ def check_shelved_changelist(changelist)
64
+ if @check_shelve && !CommandUtils.changelist_shelved?(changelist)
65
+ raise(StandardError, "Not all files are shelved in changelist: #{changelist}")
66
+ end
67
+ end
68
+
69
+ def check_shelved_files(files)
70
+ if @check_shelve && !CommandUtils.files_shelved?(files)
71
+ raise(StandardError, "Not all files are shelved from list: #{files}")
72
+ end
73
+ end
74
+
45
75
  end
46
76
  end
@@ -1,6 +1,5 @@
1
1
  module P4Tools
2
2
  class Shelve
3
- include CommandUtils
4
3
 
5
4
  def self.run(arguments)
6
5
  Shelve.new(arguments).run
@@ -12,42 +11,80 @@ module P4Tools
12
11
  help ''
13
12
  help 'Options:'
14
13
  help ''
15
- arg :files, 'The absolute path of the files to shelve.', :short => '-f', :type => :strings, :required => true
16
- arg :changelist, 'The changelist number to shelve, if not given, then create a new one.', :short => '-c', :type => :int
14
+ arg :files, 'The absolute path of the files to shelve.', :short => '-f', :type => :strings
15
+ arg :changelist, 'The changelist to shelve.', :short => '-c', :type => :int
16
+ arg :tochangelist, 'The changelist number to shelve, if not given, then create a new one.', :short => '-t', :type => :int
17
+ arg :checkfiles, 'List the unshelved files.', :short => '-i', :type => :strings
18
+ arg :checkcls, 'List the unshelved files in changelist.', :short => '-l', :type => :ints
17
19
  end
18
20
  end
19
21
 
20
22
 
21
23
  def initialize(args)
22
24
  @files = args[:files]
23
- @shelve_changelist = args[:changelist] || create_new_changelist("Shelve container for files:\n\n#{@files.join("\n")}")
25
+ @from_changelist = args[:changelist]
26
+ @to_changelist = args[:tochangelist]
27
+ @checkfiles = args[:checkfiles]
28
+ @checkcls = args[:checkcls]
29
+
24
30
  @p4 = P4Tools.connection
25
31
  end
26
32
 
27
33
  def run
28
- current_changelist = get_current_changelist
29
-
30
- move_to(@shelve_changelist)
31
- shelve
32
- move_to(current_changelist)
34
+ if !@files.nil?
35
+ from_changelist = CommandUtils.pending_changelist_for_file(@files.first)
36
+ shelve_to_cl(from_changelist, get_to_changelist)
37
+ elsif !@from_changelist.nil?
38
+ @files = CommandUtils.opened_files(@from_changelist)
39
+ shelve_to_cl(@from_changelist, get_to_changelist)
40
+ elsif !@checkfiles.nil?
41
+ check_files(@checkfiles)
42
+ elsif !@checkcls.nil?
43
+ check_changelists(@checkcls)
44
+ end
33
45
  end
34
46
 
47
+ def check_files(files)
48
+ unshelved = CommandUtils.unshelved_files(files)
35
49
 
36
- private
50
+ if unshelved.empty?
51
+ puts 'All files shelved.'
52
+ else
53
+ puts unshelved.join($/)
54
+ end
55
+ end
37
56
 
38
- def get_current_changelist
39
- file_info = @p4.run_opened('-u', @p4.user, @files.first).first
40
- file_info['change']
57
+ def check_changelists(changelists)
58
+ changelists.each { |cl|
59
+ files = CommandUtils.unshelved_files_in_changelist(cl)
60
+ if files.empty?
61
+ puts "#{cl}: All files shelved."
62
+ else
63
+ puts "#{cl}: "
64
+ puts files.join($/)
65
+ puts
66
+ end
67
+ }
41
68
  end
42
69
 
43
- def shelve
44
- @p4.run_shelve('-f', '-c', @shelve_changelist, @files)
70
+ def shelve_to_cl(from_changelist, to_changelist)
71
+ move_to(to_changelist)
72
+ shelve(to_changelist)
73
+ move_to(from_changelist)
74
+ end
75
+
76
+ def shelve(changelist)
77
+ @p4.run_shelve('-f', '-c', changelist, @files)
45
78
  end
46
79
 
47
80
  def move_to(changelist)
48
81
  @p4.run_reopen('-c', changelist, @files)
49
82
  end
50
83
 
84
+ def get_to_changelist
85
+ @to_changelist || CommandUtils.create_new_changelist("Shelve container for files:\n\n#{@files.join("\n")}")
86
+ end
87
+
51
88
  end
52
89
 
53
90
  end
data/lib/p4_tools.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'P4'
2
2
  require_relative 'p4tools/environment'
3
- require_relative 'p4tools/p4_delegate'
4
3
  require_relative 'p4tools/utils/utils'
5
4
  require_relative 'p4tools/utils/command_utils'
6
5
  require_relative 'p4tools/parsers/command_parser'
@@ -16,7 +15,6 @@ module P4Tools
16
15
  entries = CommandParser.new(args).parse
17
16
  global_arguments = entries.shift.arguments
18
17
 
19
- setup_perforce_config(global_arguments[:p4config])
20
18
  create_perforce_connection
21
19
 
22
20
  begin
@@ -31,13 +29,10 @@ module P4Tools
31
29
  def self.set_options(opts)
32
30
  opts.set do
33
31
  help 'Simple command line tool to run custom perforce actions through subcommands.'
34
- help 'For more information, please check the help page of the command.'
32
+ help 'For more information, please check the help page of the subcommand.'
35
33
  help ''
36
34
  help "Available subcommands are:\n #{SUB_COMMANDS.join("\n ")}"
37
35
  help ''
38
- help 'Global options:'
39
- help ''
40
- arg :p4config, 'Absolute path of the P4CONFIG file.', :short => '-p', :type => :string
41
36
  end
42
37
  end
43
38
 
@@ -66,19 +61,8 @@ module P4Tools
66
61
  command.run(arguments)
67
62
  end
68
63
  end
69
-
70
- # @param [String] config_path
71
- # @return [void]
72
- def setup_perforce_config(config_path)
73
- if config_path
74
- ENV['P4CONFIG'] = config_path
75
- elsif ENV['P4CONFIG'].nil?
76
- ENV['P4CONFIG'] = CONFIG_ROOT + '/p4.ini'
77
- end
78
- end
79
64
  end
80
65
 
81
-
82
66
  if __FILE__ == $PROGRAM_NAME
83
67
  run
84
68
  end
@@ -3,16 +3,12 @@ ROOT = File.expand_path('..', File.dirname(__FILE__))
3
3
  # The absolute path of the folder which contains the command files
4
4
  COMMANDS_ROOT = ROOT + '/commands'
5
5
  # The absolute path of the folder which contains the custom command files
6
- CUSTOM_COMMANDS_ROOT = ROOT + '/commands/custom'
6
+ CUSTOM_COMMANDS_ROOT = COMMANDS_ROOT + '/custom'
7
7
  # The absolute path of the folder which contains the configuration files
8
8
  CONFIG_ROOT = ROOT + '/config'
9
- # Special command to simply delegate everything to p4.run
10
- P4_COMMAND = 'p4'
11
9
  # Array of command names, read from the COMMAND_ROOT folder
12
10
  SUB_COMMANDS = Dir[COMMANDS_ROOT + '/*.rb'].collect { |file|
13
11
  File.basename(file, '.rb')
14
12
  }
15
- SUB_COMMANDS.push(P4_COMMAND)
16
-
17
13
 
18
14
  $LOAD_PATH.unshift(CUSTOM_COMMANDS_ROOT, COMMANDS_ROOT)
@@ -26,14 +26,13 @@ module P4Tools
26
26
  # @return [void]
27
27
  def parse_commands
28
28
  while command = @raw_args.shift
29
- if command == P4_COMMAND
30
- entry = CommandEntry.new(P4Delegate, parse_p4_arguments)
31
- @parsed_args.push(entry)
32
- else
33
- command_module = load_module_for_command(command)
34
- entry = CommandEntry.new(command_module, parse_arguments(command_module))
35
- @parsed_args.push(entry)
29
+ unless SUB_COMMANDS.include?(command)
30
+ raise(ArgumentError, "The following subcommand does not exist: '#{command}'")
36
31
  end
32
+
33
+ command_module = load_module_for_command(command)
34
+ entry = CommandEntry.new(command_module, parse_arguments(command_module))
35
+ @parsed_args.push(entry)
37
36
  end
38
37
  end
39
38
 
@@ -52,24 +51,6 @@ module P4Tools
52
51
  }
53
52
  end
54
53
 
55
- # @return [Hash<Symbol, Object>]
56
- def parse_p4_arguments
57
- P4Delegate.help if @raw_args.empty?
58
-
59
- args = []
60
- i = 0
61
- current = @raw_args[i]
62
-
63
- begin
64
- i += 1
65
- args.push(current)
66
- current = @raw_args[i]
67
- end while !SUB_COMMANDS.include?(current) && i < @raw_args.length
68
-
69
- @raw_args = @raw_args[i .. -1]
70
- {:raw => args}
71
- end
72
-
73
54
  # @param [String] command
74
55
  # @return [Module]
75
56
  def load_module_for_command(command)
data/lib/p4tools/spec.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module P4Tools
2
2
  PROJECT_NAME = 'p4tools'
3
- VERSION = '0.1.4.1'
3
+ VERSION = '0.2.0.0'
4
4
  end
@@ -3,26 +3,69 @@ require_relative 'validators/shelve_validator'
3
3
  module P4Tools
4
4
  module CommandUtils
5
5
 
6
+ # @param [Array<String>] files
7
+ # @param [Boolean] check_diff
8
+ # @return [Boolean]
9
+ def self.files_shelved?(files, check_diff=true)
10
+ ShelveValidator.new.find_unshelved_files(files, check_diff).empty?
11
+ end
12
+
6
13
  # @param [Integer] changelist
7
14
  # @param [Boolean] check_diff
8
15
  # @return [Boolean]
9
- def all_files_shelved?(changelist, check_diff=false)
10
- validator = ShelveValidator.new(changelist, check_diff)
11
- validator.valid?
16
+ def self.changelist_shelved?(changelist, check_diff=true)
17
+ files = opened_files(changelist)
18
+ ShelveValidator.new.find_unshelved_files(files, check_diff).empty?
19
+ end
20
+
21
+ # @param [Array<String>] files
22
+ # @param [Boolean] check_diff
23
+ # @return [Array<String>]
24
+ def self.unshelved_files(files, check_diff=true)
25
+ ShelveValidator.new.find_unshelved_files(files, check_diff)
26
+ end
27
+
28
+ # @param [Integer] changelist
29
+ # @param [Boolean] check_diff
30
+ # @return [Array<String>]
31
+ def self.unshelved_files_in_changelist(changelist, check_diff=true)
32
+ files = opened_files(changelist)
33
+ ShelveValidator.new.find_unshelved_files(files, check_diff)
12
34
  end
13
35
 
14
36
  # @param [Integer] changelist
15
37
  # @return [Boolean]
16
- def empty_changelist?(changelist)
38
+ def self.empty_changelist?(changelist)
17
39
  p4 = P4Tools.connection
18
- opened_files = p4.run(%W{ describe -s #{changelist} })[0]['depotFile']
40
+ opened_files = p4.run_describe('-s', changelist).first['depotFile']
19
41
  opened_files.nil?
20
42
  end
21
43
 
44
+ # @param [String] file
45
+ # @return [Integer]
46
+ def self.pending_changelist_for_file(file)
47
+ p4 = P4Tools.connection
48
+ p4.run_opened(file).first['change']
49
+ end
50
+
51
+ # @param [Integer] changelist
52
+ # @return [Array<String>]
53
+ def self.shelved_files(changelist)
54
+ p4 = P4Tools.connection
55
+ p4.run_describe('-s', '-S', changelist).first['depotFile']
56
+ end
57
+
58
+ # @param [Integer] changelist
59
+ # @return [Array<String>]
60
+ def self.opened_files(changelist)
61
+ p4 = P4Tools.connection
62
+ p4.run_describe('-s', changelist).first['depotFile']
63
+ end
64
+
22
65
  # @param [String] description
23
66
  # @return [String]
24
67
  # The number of the new changelist
25
- def create_new_changelist(description='Created with P4Tools.')
68
+ def self.create_new_changelist(description='Created with P4Tools.')
26
69
  p4 = P4Tools.connection
27
70
 
28
71
  p4.input = {
@@ -30,7 +73,7 @@ module P4Tools
30
73
  'Description' => description,
31
74
  }
32
75
 
33
- confirmation = p4.run('change', '-i').first
76
+ confirmation = p4.run_change('-i').first
34
77
  confirmation.match(/\d+/)[0]
35
78
  end
36
79
  end
@@ -1,37 +1,51 @@
1
1
  module P4Tools
2
2
  class ShelveValidator
3
3
 
4
- def initialize(changelist, check_diff)
5
- @changelist = changelist
6
- @check_diff = check_diff
7
- end
4
+ # @return [Array<String>]
5
+ def find_unshelved_files(files, check_diff)
6
+ return false if files.nil?
8
7
 
9
- # @return [Boolean]
10
- def valid?
8
+ @opened_files = files
9
+ @check_diff = check_diff
11
10
  @p4 = P4Tools.connection
12
- @opened_files = @p4.run(%W{ describe -s #{@changelist} })[0]['depotFile']
13
- @shelved_files = @p4.run(%W{ describe -s -S #{@changelist} })[0]['depotFile']
14
11
 
15
- @opened_files.nil? || (!@shelved_files.nil? && all_opened_files_shelved? && files_are_identical?)
16
- end
12
+ @cl = CommandUtils.pending_changelist_for_file(@opened_files[0])
13
+ @shelved_files = CommandUtils.shelved_files(@cl)
14
+
15
+ if @shelved_files.nil?
16
+ return files
17
+ end
17
18
 
18
- private
19
+ unshelved_files = find_not_shelved_files
20
+ unless unshelved_files.empty?
21
+ return unshelved_files
22
+ end
23
+
24
+ find_diff_files
25
+ end
19
26
 
20
27
  # @return [Boolean]
21
- def all_opened_files_shelved?
22
- (@opened_files - @shelved_files).empty?
28
+ def find_not_shelved_files
29
+ @opened_files - @shelved_files
23
30
  end
24
31
 
25
32
  # @return [Boolean]
26
- def files_are_identical?
27
- identical = true
33
+ def find_diff_files
34
+ return [] unless @check_diff
28
35
 
29
- if @check_diff
30
- shelve_revisions = @opened_files.map { |file| file + "@=#{@changelist}" }
31
- identical = @p4.run_diff('-Od', *shelve_revisions).empty?
32
- end
36
+ shelve_revisions = []
37
+ @p4.run_opened(*@opened_files).each { |file|
38
+ unless deleted?(file)
39
+ shelve_revisions.push("#{file['depotFile']}@=#{@cl}")
40
+ end
41
+ }
33
42
 
34
- identical
43
+ @p4.run_diff('-f', '-se', *shelve_revisions)
35
44
  end
45
+
46
+ def deleted?(file)
47
+ file['action'].include?('delete')
48
+ end
49
+
36
50
  end
37
51
  end
data/p4tools.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.files = `git ls-files`.split($/).delete_if {|file| file =~ %r{^gem/|^lib/commands/custom/}}
13
13
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
14
  gem.require_paths = ['lib']
15
+ gem.license = 'GPL-2'
15
16
 
16
17
  gem.add_runtime_dependency('P4Ruby-mingwx86', '~> 2014.1')
17
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: p4tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4.1
4
+ version: 0.2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-02 00:00:00.000000000 Z
12
+ date: 2014-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: P4Ruby-mingwx86
@@ -53,15 +53,15 @@ files:
53
53
  - .gitignore
54
54
  - Gemfile
55
55
  - Gemfile.lock
56
+ - LICENSE
56
57
  - Rakefile
57
58
  - bin/p4tools
59
+ - lib/commands/describe.rb
58
60
  - lib/commands/move.rb
59
61
  - lib/commands/revert.rb
60
62
  - lib/commands/shelve.rb
61
- - lib/config/README
62
63
  - lib/p4_tools.rb
63
64
  - lib/p4tools/environment.rb
64
- - lib/p4tools/p4_delegate.rb
65
65
  - lib/p4tools/parsers/command_entry.rb
66
66
  - lib/p4tools/parsers/command_options.rb
67
67
  - lib/p4tools/parsers/command_parser.rb
@@ -72,7 +72,8 @@ files:
72
72
  - lib/p4tools/utils/validators/shelve_validator.rb
73
73
  - p4tools.gemspec
74
74
  homepage: https://github.com/ncsibra/P4Tools
75
- licenses: []
75
+ licenses:
76
+ - GPL-2
76
77
  post_install_message:
77
78
  rdoc_options: []
78
79
  require_paths:
data/lib/config/README DELETED
@@ -1 +0,0 @@
1
- Put your 'p4.ini' file to this folder to load automatically during script run.
@@ -1,34 +0,0 @@
1
- module P4Tools
2
- class P4Delegate
3
-
4
- def self.run(arguments)
5
- @p4 = P4Tools.connection
6
- command = arguments[:raw]
7
-
8
- if help?(command)
9
- help
10
- else
11
- @p4.run(command)
12
- end
13
- end
14
-
15
- def self.set_options(opts)
16
- end
17
-
18
- def self.help
19
- $stdout.puts "\n"
20
- $stdout.puts "Special command which delegate every argument to the perforce 'run()' method."
21
- $stdout.puts 'This way it will behave as the command line client of perforce(p4).'
22
- $stdout.puts "So if in the command line using a command like 'p4 revert -w -c 1234', you can use it in the exact same way with p4tools, e.g.: 'p4tools p4 revert -w -c 1234'"
23
- $stdout.puts "For more information check the perforce command reference: http://www.perforce.com/perforce/doc.current/manuals/cmdref"
24
- exit
25
- end
26
-
27
- def self.help?(command)
28
- %w(--help -h).include?(command[0])
29
- end
30
-
31
- private_class_method :help?
32
-
33
- end
34
- end