Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /svnutils/trunk/src/

svnutils
Discussion topic

Back to topic list

CVS update: /svnutils/trunk/src/

Author sunny256
Full name Øyvind A. Holm
Date 2005-04-01 22:42:16 PST
Message User: sunny256
Date: 05/04/01 22:42:16

Modified:
 /svnutils/trunk/src/
  svndiff

Log:
 r112 | sunny256 | 2005-04-02 06:35:13 +0000 (Sat, 02 Apr 2005) | 10 lines
 
 Added the "-r" option to svndiff. It’s now possible to compare the
 working file against earlier revisions, or earlier revisions against
 each other.
 
 * /trunk/src/svndiff
   New variable: $opt_r.
   (diff_file): Accepts a third parameter which is the revision string as
     passed to the "-r" option.
   (usage, POD): Update the help text.

File Changes:

Directory: /svnutils/trunk/src/
===============================

File [changed]: svndiff
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​svndiff?r1=1.13&​r2=1.14
Delta lines: +67 -12
---------------------
--- svndiff 2 Apr 2005 06:41:06 -0000 1.13
+++ svndiff 2 Apr 2005 06:42:16 -0000 1.14
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: svndiff 111 2005-04-02 05:14:56Z sunny256 $
+# $Id: svndiff 112 2005-04-02 06:35:13Z sunny256 $
 # Uses a specified diff program for viewing differences in a Subversion
 # versioned directory tree.
 #
@@ -16,9 +16,9 @@
 $| = 1;
 
 use Getopt::Std;
-our ($opt_C, $opt_c, $opt_e, $opt_h, $opt_p) =
- ( 0, "", "", 0, "");
-getopts('Cc:e:hp:') || die("Option error. Use -h for help.\n");
+our ($opt_C, $opt_c, $opt_e, $opt_h, $opt_p, $opt_r) =
+ ( 0, "", "", 0, "", "");
+getopts('Cc:e:hp:r:') || die("Option error. Use -h for help.\n");
 
 # Change this to the default diff command to use
 my $Cmd = "vimdiff";
@@ -58,13 +58,14 @@
             } else {
                 warn("$progname: Error opening \"$CMD_SVN $Curr stat -q\" pipe");
             }
- diff_file($Curr, $has_conflict);
+ diff_file($Curr, $has_conflict, $opt_r);
         } else {
             D("$Curr is NOT a file.");
             warn("$progname: \"$Curr\" is not a file or doesn't exist\n");
         }
     }
 } else {
+ length($opt_r) && die("You need to specify one or more files when using the -r option\n");
     if (open(PipeFP, "$CMD_SVN stat -q |")) {
         my %has_conflict = ();
         while (<PipeFP>) {
@@ -90,23 +91,58 @@
 }
 
 sub diff_file {
- my ($File1, $has_conflict) = @_;
+ my ($File1, $has_conflict, $Revs) = @_;
     my $Path = "";
     my $File = $File1;
 
- D("diff_file(\"$File1\", \"$has_conflict\");\n");
+ D("diff_file(\"$File1\", \"$has_conflict\", \"$Revs\");\n");
 
     if ($File =~ m#^(.*/)(.+?)$#) {
         $Path = $1;
         $File = $2;
     }
 
- my $File2 = "$Path.svn/text-bas​e/$File.svn-base";
+ my $File2 = "";
+ my @rm_files = ();
+
+ if (length($opt_r)) {
+ my ($Rev1, $Rev2);
+ if ($opt_r =~ /^(\d+)$/) {
+ $Rev1 = $1;
+ $Rev2 = "";
+ } elsif ($opt_r =~ /^(\d+):(\d+)$/) {
+ $Rev1 = $1;
+ $Rev2 = $2;
+ } else {
+ die("Revision format error in -r option, use -h for help\n");
+ }
+ D("Rev1 = \"$Rev1\", Rev2 = \"$Rev2\"\n");
+ mysyst("$CMD_SVN cat -r$Rev1 $File1 >$File1.r$Rev1.tmp");
+ mysyst("$CMD_SVN cat -r$Rev2 $File1 >$File1.r$Rev2.tmp") if (length($Rev2));
+ if (length($Rev2)) {
+ $File2 = "$File1.r$Rev2.tmp";
+ $File1 = "$File1.r$Rev1.tmp";
+ push(@rm_files, $File1, $File2);
+ } else {
+ $File2 = "$File1.r$Rev1.tmp";
+ push(@rm_files, $File2);
+ }
+ } else {
+ $File2 = "$Path.svn/text-bas​e/$File.svn-base";
+ }
+
     D("File1 = \"$File1\"\n");
     D("File2 = \"$File2\"\n");
 
     (-e $File1) || (warn("$File1: File not found\n"), return);
- (-e $File2) || (warn("$File2: File not found, is not under version control\n"), return);
+ (-e $File2) || (warn("$File2: File not found" .
+ length($opt_r) ? ""
+ : ", is not under version " .
+ "control" .
+ "\n"
+ ),
+ return
+ );
 
     if ($Cmd eq "vimdiff") {
         mysyst("$Cmd $File1 $File2");
@@ -114,7 +150,12 @@
         mysyst("$Cmd $File2 $File1");
     }
 
- if ($has_conflict) {
+ for my $curr_rm (@rm_files) {
+ D("Removing tempfile \"$curr_rm\"...");
+ unlink($curr_rm) || warn("$progname: $curr_rm: Can't delete temporary file: $!");
+ }
+
+ if (!length($opt_r) && $has_conflict) {
         print("$progname: Write y and press ENTER if the conflict " .
               "in $File1 is resolved: ");
         if (<STDIN> =~ /^y$/i) {
@@ -162,6 +203,11 @@
 -e x Use x as the svn executable. Default: "$CMD_SVN".
 -h Show this help.
 -p x Use x as parameters to the diff program.
+-r x Run a $Cmd command against previous revisions:
+ 111:222
+ Compare r111 and r222.
+ 123
+ Compare your working file against r123.
 
 END
     exit($Retval);
@@ -180,7 +226,7 @@
 
 =head1 REVISION
 
-$Id: svndiff 111 2005-04-02 05:14:56Z sunny256 $
+$Id: svndiff 112 2005-04-02 06:35:13Z sunny256 $
 
 =head1 SYNOPSIS
 
@@ -217,6 +263,15 @@
 
 Print a brief help summary.
 
+=item B<-r> x
+
+Run the external diff command against previous revisions:
+
+ 111:222
+ Compare r111 and r222.
+ 123
+ Compare your working file against r123.
+
 =back
 
 =head1 AUTHOR
@@ -253,4 +308,4 @@
 # }}}
 
 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
-# End of file $Id: svndiff 111 2005-04-02 05:14:56Z sunny256 $
+# End of file $Id: svndiff 112 2005-04-02 06:35:13Z sunny256 $




--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@svnu​tils.tigris.org
For additional commands, e-mail: cvs-help at svnutils dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /svnutils/trunk/src/ sunny256 Øyvind A. Holm 2005-04-01 22:42:16 PST
Messages per page: