6 messages in com.perforce.p4ruby[p4ruby] diff output| From | Sent On | Attachments |
|---|---|---|
| bob p4 | 11 Mar 2008 12:55 | |
| Jeff A. Bowles | 12 Mar 2008 10:37 | |
| Jeff A. Bowles | 12 Mar 2008 10:43 | |
| bob p4 | 12 Mar 2008 11:59 | |
| Jeff J. | 13 Mar 2008 14:27 | |
| Andy Koch | 14 Apr 2008 15:07 |
| Subject: | [p4ruby] diff output![]() |
|---|---|
| From: | Jeff A. Bowles (ja...@pobox.com) |
| Date: | 03/12/2008 10:37:16 AM |
| List: | com.perforce.p4ruby |
I am going to suggest a different interpretation of this situation:
"I have noticed that p4.run('diff'...........) gives me output that is not that usable, at least not directly. It's like p4.run('print'...........) in that it faithfully executes the Perforce API but gives output that needs to be post-processed. So, I have found that the P4Perl implementation allows me to define my own 'p4.run_diff' (or 'p4.run_print') that does 'the right thing', and would like to offer the newly coded run_diff method as a possible addition to the P4Perl implementation."
So, make yourself a "run_diff" method and use it and publicize it.
The "p4.run" method gets you the C++ API call, with a small amount of post-processing but not much. (Specifically, the 'fetch" methods fix up Views much better than the raw C++ API call.)
I will send, in a separate email, examples of a couple of such run_blah methods.
-Jeff Bowles
On Tue, Mar 11, 2008 at 12:55 PM, bob p4 <jeffperforce at gmail.com> wrote:
I was surprised that p4.run("diff", "...") gives an array containing a mixture of hashes and diff lines. I expected all hashes with the diff lines under the "output" key or some such.
One of my pet peeves about perforce is that its diff output cannot immediately be fed into patch. The following script produces a proper patch format.
require 'p4'
p4 = P4.new Hash[*ARGV].each_pair { |key, value| p4.send("#{key}=", value) } p4.connect
last_elem = nil p4.run("diff", "-du", "...").each { |elem| if elem.is_a?(String) # encountered a diff line ... I hope ...
if last_elem.is_a?(Hash) # write the diff header %w(- +).each { |sig| puts([sig*3, last_elem["clientFile"]].join(" ")) } end
# write a diff line puts(elem) end last_elem = elem }
It's not really a big deal that the p4ruby-diff behaves as it does, it's just that remembering the last element and checking the type seems rather clunky. I expected something along the lines of,
p4.run("diff", "-du", "...").each { |elem| if elem["output"] # write the diff header %w(- +).each { |sig| puts([sig*3, elem["clientFile"]].join(" ")) }
# write diff lines puts(elem["output"]) end }
--Jeff
_______________________________________________ p4ruby mailing list p4ruby at perforce.com http://maillist.perforce.com/mailman/listinfo/p4ruby
--
--- Jeff Bowles - jeff.a.bowles at gmail.com




