[p4ruby] diff output

Jeff A. Bowles jab at pobox.com
Wed Mar 12 10:37:39 PDT 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://maillist.perforce.com/pipermail/p4ruby/attachments/20080312/88de45b3/attachment-0001.html>


More information about the p4ruby mailing list