Discussion:
[p4] diff2 + added files?
Sohail Somani
2007-12-04 01:00:56 UTC
Permalink
Hi,

Is there any way to convince the p4 command to give me a unified diff
between two branches such that added and deleted files show up in the
output? For the life of me, I can't figure it out.

Thanks!
--
Sohail Somani
http://uint32t.blogspot.com
Looney, James B
2007-12-04 16:01:18 UTC
Permalink
I usually do that using labels. I'll create a label in one workspace
(usually our mainline) and the second in a branch. Then use p4 diff2 -q
//***@mainline_label //***@branch_label

If you're scripting it, I'd recommend adding the -G (marshaling) as it
makes the file organizing a LOT easier since it'll tell you which files
were added/deleted/modified without you having to parse each line
yourself. The -q just suppresses the actual diff output and the header
info for identical files.

-James
-----Original Message-----
Sent: Monday, December 03, 2007 6:01 PM
Subject: [p4] diff2 + added files?
Hi,
Is there any way to convince the p4 command to give me a unified diff
between two branches such that added and deleted files show up in the
output? For the life of me, I can't figure it out.
Thanks!
--
Sohail Somani
http://uint32t.blogspot.com
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
Sohail Somani
2007-12-04 17:01:07 UTC
Permalink
Post by Looney, James B
I usually do that using labels. I'll create a label in one workspace
(usually our mainline) and the second in a branch. Then use p4 diff2 -q
If you're scripting it, I'd recommend adding the -G (marshaling) as it
makes the file organizing a LOT easier since it'll tell you which files
were added/deleted/modified without you having to parse each line
yourself. The -q just suppresses the actual diff output and the header
info for identical files.
Thanks for your reply.

Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and *deleted*
files. So say hello.txt was added with text "Hello, World", I'd want to
see:

==== <none> - //.../hello.txt
+ Hello, World

Similarly, if the file was deleted, I'd want to see:

==== //.../hello.txt - <none>
- Hello, World

For all the text files. Right now, I can only see:

==== <none> - //.../hello.txt
==== //.../hello.txt - <none>

i.e., no content.
--
Sohail Somani
http://uint32t.blogspot.com
Looney, James B
2007-12-04 19:39:40 UTC
Permalink
I should've read your first post more carefully.

In that case, I don't know of a way to do that without scripting it
and adding in the additional content yourself depending on whether
the file's been added/deleted.
-----Original Message-----
Sent: Tuesday, December 04, 2007 10:01 AM
Subject: Re: [p4] diff2 + added files?
Post by Looney, James B
I usually do that using labels. I'll create a label in one
workspace
Post by Looney, James B
(usually our mainline) and the second in a branch. Then
use p4 diff2 -q
Post by Looney, James B
If you're scripting it, I'd recommend adding the -G
(marshaling) as it
Post by Looney, James B
makes the file organizing a LOT easier since it'll tell you
which files
Post by Looney, James B
were added/deleted/modified without you having to parse each line
yourself. The -q just suppresses the actual diff output
and the header
Post by Looney, James B
info for identical files.
Thanks for your reply.
Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and
*deleted*
files. So say hello.txt was added with text "Hello, World",
I'd want to
==== <none> - //.../hello.txt
+ Hello, World
==== //.../hello.txt - <none>
- Hello, World
==== <none> - //.../hello.txt
==== //.../hello.txt - <none>
i.e., no content.
--
Sohail Somani
http://uint32t.blogspot.com
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
Daniel Neades
2007-12-05 14:02:44 UTC
Permalink
Post by Sohail Somani
Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and *deleted*
files.
I don't know which platform you're on, but if it is Windows or Mac OS X,
our (commercial) Araxis Merge application can access Perforce
repositories directly and, for example, perform a folder comparison
between different branches (or the same branch at different points in
time) directly within the depot.
Tetlow, Gordon
2007-12-05 18:19:24 UTC
Permalink
Here is a Perl script that does what you want. I've had it for years and
it's been incredibly useful. Basically, it turns diff2 into a GNU style
patch.

Sorry for any wrapping.

-gordon

#!/usr/bin/perl

# new usage: ./p4patch
# Usage: p4 diff2 -du base_view your_view

use POSIX (strftime);
use File::Basename;

die "Usage: $0 [srcpath] [dstpath]\n" if ( $#ARGV ne 1 );

my $src_depot = shift;
my $dst_depot = shift;

my $src_base=dirname($src_depot);
my $dst_base=dirname($dst_depot);

$cmd = "p4 diff2 -du $src_depot $dst_depot";
open(P, "$cmd |") || die $!;

$time = localtime();
$time = strftime "%a %b %e %H:%M:%S %Y", localtime;
$time = strftime "%Y/%m/%d %T", localtime;

while (<P>) {
($f1, $f2, $r) = m|^==== (.+) - (.+) ====? ?(.*)| or print, next;
next if $r eq 'identical';

($src, $srcrev) = ($f1 =~ m|$src_base/([^#]*)#(\d+)|);
($dst, $dstrev) = ($f2 =~ m|$dst_base/([^#]*)#(\d+)|);
print "Index: $dst\n";
print '=' x 75 . "\n";

if ($r eq '') {
print `p4 print -q $f2 | diff -Nc /dev/null - | sed "s#^---
-#--- $dst#"`
if ($f1 =~ /<\s*none\s*>/);
print `p4 print -q $f1 | diff -Nc - /dev/null | sed
"s#^[*][*][*] -#*** $src#"`
if ($f2 =~ /<\s*none\s*>/);
next;
}

print "--- $src\t$time\t#$srcrev\n";
print "+++ $dst\t$time\n";
}

-----Original Message-----
From: perforce-user-***@perforce.com
[mailto:perforce-user-***@perforce.com] On Behalf Of Sohail Somani
Sent: Tuesday, December 04, 2007 9:01 AM
To: perforce-***@perforce.com
Subject: Re: [p4] diff2 + added files?
Post by Looney, James B
I usually do that using labels. I'll create a label in one workspace
(usually our mainline) and the second in a branch. Then use p4 diff2 -q
If you're scripting it, I'd recommend adding the -G (marshaling) as it
makes the file organizing a LOT easier since it'll tell you which files
were added/deleted/modified without you having to parse each line
yourself. The -q just suppresses the actual diff output and the header
info for identical files.
Thanks for your reply.

Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and *deleted*
files. So say hello.txt was added with text "Hello, World", I'd want to
see:

==== <none> - //.../hello.txt
+ Hello, World

Similarly, if the file was deleted, I'd want to see:

==== //.../hello.txt - <none>
- Hello, World

For all the text files. Right now, I can only see:

==== <none> - //.../hello.txt
==== //.../hello.txt - <none>

i.e., no content.
--
Sohail Somani
http://uint32t.blogspot.com
_______________________________________________
perforce-user mailing list - perforce-***@perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
Sohail Somani
2007-12-05 18:30:13 UTC
Permalink
Post by Tetlow, Gordon
Here is a Perl script that does what you want. I've had it for years and
it's been incredibly useful. Basically, it turns diff2 into a GNU style
patch.
And they say Perl is a write-only language! Thanks for the script, it
looks like it will do the job.
--
Sohail Somani
http://uint32t.blogspot.com
Jeff A. Bowles
2007-12-14 10:24:28 UTC
Permalink
You might find //guest/jeff_bowles/scripts/difflabel.* useful, also.
That's in the public perforce depot.

-Jeff Bowles
Post by Sohail Somani
Post by Tetlow, Gordon
Here is a Perl script that does what you want. I've had it for years and
it's been incredibly useful. Basically, it turns diff2 into a GNU style
patch.
And they say Perl is a write-only language! Thanks for the script, it
looks like it will do the job.
--
Sohail Somani
http://uint32t.blogspot.com
_______________________________________________
http://maillist.perforce.com/mailman/listinfo/perforce-user
--
---
Jeff Bowles - ***@gmail.com
Sohail Somani
2008-01-11 19:21:45 UTC
Permalink
Post by Tetlow, Gordon
Here is a Perl script that does what you want. I've had it for years and
it's been incredibly useful. Basically, it turns diff2 into a GNU style
patch.
Sorry for any wrapping.
Finally ran the script (on Linux.) Works great! Thanks.
--
Sohail Somani
http://uint32t.blogspot.com
Ken Williams
2007-12-04 19:37:00 UTC
Permalink
Post by Sohail Somani
Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and *deleted*
files.
In other words, similar to the -N flag from Gnu diff.

I don't know of any built-in way. None of the following work:

p4 diff2 -u
p4 diff2 -u -dN
p4 diff2 -duN

The best I can think of is to pipe the output of 'p4 diff2 -du' (NOT -u) to
a process that will turn lines like "==== <none> - //depot/foo#9 ====' into
the '+' lines you want, and remove the rest of the "====" lines.

-Ken
--
Ken Williams
Research Scientist
The Thomson Corporation
Eagan, MN
Sohail Somani
2007-12-04 19:52:39 UTC
Permalink
Post by Ken Williams
Post by Sohail Somani
Unfortunately, I don't think I was clear enough! What I want to do is
take a diff of the two branches for the purposes of code review. So I
want all the added and removed content, including *added* and *deleted*
files.
In other words, similar to the -N flag from Gnu diff.
[snip]

I think they didn't work because p4 diff2 uses some built-in diff
Post by Ken Williams
The best I can think of is to pipe the output of 'p4 diff2 -du' (NOT -u)
to a process that will turn lines like "==== <none> - //depot/foo#9
====' into the '+' lines you want, and remove the rest of the "===="
lines.
That seems to be the only thing to do.

Thank you for your help.
--
Sohail Somani
http://uint32t.blogspot.com
David Weintraub
2007-12-05 03:37:17 UTC
Permalink
Post by Sohail Somani
Hi,
Is there any way to convince the p4 command to give me a unified diff
between two branches such that added and deleted files show up in the
output? For the life of me, I can't figure it out.
Don't know if this helps you, but the regular Unix diff (well, the GNU
version) does a diff between two directories. If you have a workspace with
both branches in it, you could use that to diff the two branches:
$ cd ~/p4views/myview
$ diff -R -u MyProd/BRANCH_1 MyProd/BRANCH_2

If you're on Windows, download Cygwin. If you're on Solaris or HP/UX, try
the diffdir or dirdiff commands.

--
David Weintraub
***@gmail.com
Loading...