List Info

Thread: diff output




diff output
user name
2008-03-11 14:55:30
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("#=", 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
p4rubyperforce.com

http://maillist.perforce.com/mailman/listinfo/p4ruby

Re: diff output
user name
2008-03-12 12:37:39
I am going to suggest a different interpretation of this situation:
"I have noticed that p4.run(9;diff'...........) gives me output that is not that usable, at least not directly.  It's like p4.run(9;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 < jeffperforcegmail.com">jeffperforcegmail.com> wrote:
I was surprised that p4.run(&quot;diff&quot;, "...&quot;) 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 'p49;

p4 = P4.new
Hash[*ARGV].each_pair { |key, value|
  p4.send(&quot;#=", value)
}
p4.connect

last_elem = nil
p4.run("diff", "-du&quot;, "...&quot;).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(&quot; "))
        }
     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&quot;, "...&quot;).each { |elem|
  if elem[";output&quot;]
     # write the diff header
     %w(- +).each { |sig|
        puts([sig*3, elem[";clientFile"]].join(" "))
     }

     # write diff lines
     puts(elem[";output&quot;])
  end
}

--Jeff
_______________________________________________
p4ruby mailing list
p4rubyperforce.com">p4rubyperforce.com
http://maillist.perforce.com/mailman/listinfo/p4ruby



--
---
Jeff Bowles - jeff.a.bowlesgmail.com">jeff.a.bowlesgmail.com
Re: diff output
user name
2008-03-12 12:44:04
Here is an example of overlaying a "run_describe&quot; to make it more usable for a situation specific to my application.  This might be general enough for someone else, and might not, but shows a very reasonable way to overlap a p4.run(&quot;describe"............) call. Note that p4.run_describe(.......) does the postprocessing but p4.run(9;describe&#39;.......) does not.

Again, use the interface to make it right - the P4Perl intention, as Tony explained it when he did it, was that you could build on top of this as you needed but that it would get out of your way if you wanted.

I have done similar things for "p4.run_depots&quot; (to call 'p4.run("depots") once, and then cache the results for the rest of the run of the application) and "p4.run_print&quot; (since the output of 'p4.run("print".....)' gives me chunks of the file that need to be reassembled.

 &nbsp;  -Jeff  Bowles


require "P4&quot;

# vim: set ts=4: ;
class P4
def run_describe(*args)
#
# Like 'run_filelog', we use this to get
# useful information back from 'p4 describe&#39;.
#
# The result is a hash:
# user / time / client /desc /change
# are like output of "p4.run('describe')", but
# also included in the hash is:
# revisions
# These are of type P4Revision and have some
# redundant information, but have parsed the
# 'p4 describe&#39; nonsense into meaningful sets
# of (file, revision, action, type) rows.
#
raw = self.run(&#39;describe', args.flatten)
results = raw.collect do
|h|
result = {}
['time', 'user&#39;, 'client', 'desc&#39;, 'change'].each do
|s|
result[s] = h[s]
end
result['revisions'] = []
next if  h[&#39;rev'] == nil

h[';rev'].each_index do
|i|
df = P4DepotFile.new(h[9;depotFile'][i])
r = df.new_revision
r.revno = h['rev'][i]
r.action = h['action'][i]
r.type = h['type'][i]
r.desc = h['desc']
r.time = h['time'].to_i
r.user = h['user']
r.client = h['client']
r.change = h['change'].to_i
result['revisions'].push(r)
end
result
end
results
end
&nbsp; &nbsp;
Re: diff output
user name
2008-03-12 14:00:03
On Wed, Mar 12, 2008 at 1:44 PM, Jeff A. Bowles <jabpobox.com> wrote:
> Here is an example of overlaying a
"run_describe" to make it more usable for
> a situation specific to my application.  This might be
general enough for
> someone else, and might not, but shows a very
reasonable way to overlap a
> p4.run("describe"............) call. Note
that p4.run_describe(.......) does
> the postprocessing but p4.run('describe'.......) does
not.
>
> Again, use the interface to make it right - the P4Perl
intention, as Tony
> explained it when he did it, was that you could build
on top of this as you
> needed but that it would get out of your way if you
wanted.
>
>
> I have done similar things for
"p4.run_depots" (to call
'p4.run("depots")
> once, and then cache the results for the rest of the
run of the application)
> and "p4.run_print" (since the output of
'p4.run("print".....)' gives me
> chunks of the file that need to be reassembled.

I understand there may be a need to massage the output into
some
desired form, but my point is a somewhat separate issue.

We have an array of hashes.  Each hash already contains the
parsed
version of the raw perforce output.  Each hash contains the
information for a specific file.  One file, one hash.

Except this is not the case.  Some elements in the array are
strings
which pertain to the previous hash.  Remember, the perforce
output has
already been parsed.  Those strings should not be floating
around
aimlessly.  They are tied to a specific file.  They should
be included
in the hash which describes the file to which they belong.

--Jeff
_______________________________________________
p4ruby mailing list
p4rubyperforce.com

http://maillist.perforce.com/mailman/listinfo/p4ruby

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )