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-26 14:48:09 PDT
Message User: sunny256
Date: 2005/04/26 14:48:09

Modified:
   svnutils/trunk/src/svndiff

Log:
 r120 | sunny256 | 2005-04-26 21:07:18 +0000 (Tue, 26 Apr 2005) | 9 lines
 
 Added functionality for reading a configuration file in XML format with
 personal settings so there is no need to hardcode values in the code.
 Only the diff program can be specified at the moment.
 
 * /trunk/src/svndiff
   (read_rcfile, print_leftover, txt_to_xml, xml_to_txt): New
     subroutines.
   POD updates.

File Changes:

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

File [changed]: svndiff
Url: http://svnutils.tigr​is.org/source/browse​/svnutils/trunk/src/​svndiff?r1=1.18&​r2=1.19
Delta lines: +134 -4
---------------------
--- svndiff 26 Apr 2005 21:47:26 -0000 1.18
+++ svndiff 26 Apr 2005 21:48:07 -0000 1.19
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 #===================​====================​====================​============
-# $Id: svndiff 119 2005-04-26 20:58:54Z sunny256 $
+# $Id: svndiff 120 2005-04-26 21:07:18Z sunny256 $
 # Uses a specified diff program for viewing differences in a Subversion
 # versioned directory tree.
 #
@@ -21,12 +21,28 @@
 
 my $Debug = 0;
 
-# Change this to the default diff command to use
+# Default value, can be overridden in ~/.svndiffrc
 my $Cmd = "vimdiff";
 
 our $progname = $0;
 $progname =~ s#^(.*)/(.+?)$#$2#;
 
+my $rc_file = defined($ENV{SVNDIFFRC}) ? $ENV{SVNDIFFRC} : "";
+
+unless (length($rc_file)) {
+ if (defined($ENV{HOME})) {
+ $rc_file = "$ENV{HOME}/.svndiffrc";
+ } else {
+ warn("Both SVNDIFFRC and HOME environment variables not defined, " .
+ "unable to read rc file.\n" .
+ "Using default values. To override, " .
+ "define the SVNDIFFRC variable.\n"
+ );
+ }
+}
+
+length($rc_file) && read_rcfile($rc_file);
+
 getopts('Cc:e:hp:r:') || die("$progname: Option error. Use -h for help.\n");
 
 # Change this if the svn executable is non-standard and you don’t want
@@ -216,6 +232,90 @@
     # }}}
 } # mysyst()
 
+sub read_rcfile {
+ # {{{
+ my $File = shift;
+
+ D("read_rcfile(\"$File\")");
+ if (open(RcFP, "<$File")) {
+ my $all_rc = join("", <RcFP>);
+ close(RcFP);
+ D("\$all_rc \x7B\x7B\x7B\n$​all_rc\n\x7D\x7D​x7D");
+
+ my $el_top = $all_rc;
+ $el_top =~ s/<!--.*?-->//gsx;
+
+ $el_top =~
+ s{
+ <svndiffrc\b(.*?​)>(.*?)</svndi​ffrc>
+ }
+ {
+ my $el_svndiffrc = $2;
+ D("Inside <svndiffrc>​</svndiffrc>");
+ D("\$el_svndiffrc \x7B\x7B\x7B\n$​el_svndiffrc\n\x7D​\x7D\x7D");
+ $el_svndiffrc =~
+ s{
+ <defaults\b(.*?)​>(.*?)</defaul​ts>
+ }
+ {
+ my $el_defaults = $2;
+ D("Inside <defaults><​/defaults>");
+ D("\$el_defaults \x7B\x7B\x7B\n$​el_defaults\n\x7D​x7D\x7D");
+ $el_defaults =~
+ s{
+ <diffprog\b(.*?)​>(.*?)</diffpr​og>
+ }
+ {
+ $Cmd = xml_to_txt($2);
+ D("read_rcfile(): \$Cmd = \"$Cmd\"");
+ "";
+ }sex;
+ print_leftover($el_defaults, "defaults");
+ }sex;
+ print_leftover($el_svndiffrc, "svndiffrc");
+ }sex;
+ print_leftover($el_top, "top");
+ } else {
+ warn("$progname: $File: Can't open rc file for read\n");
+ }
+ # }}}
+} # read_rcfile()
+
+sub print_leftover {
+ # Print all non-whitespace in a string, used to spot erroneous XML. {{{
+ $Debug || return("");
+ my ($Txt, $Element) = @_;
+ $Txt =~ s/^\s+//gs;
+ $Txt =~ s/\s+$//gs;
+ $Txt =~ s/\s+/ /g;
+ defined($Element) || ($Element = "[unknown]");
+ if ($Txt =~ /\S/) {
+ warn("Leftover: $Element: \"$Txt\"\n");
+ }
+ return("");
+ # }}}
+} # print_leftover()
+
+sub txt_to_xml {
+ # {{{
+ my $Txt = shift;
+ $Txt =~ s/&/&amp;/gs;
+ $Txt =~ s/</&lt;/gs;
+ $Txt =~ s/>/&gt;/gs;
+ return($Txt);
+ # }}}
+} # txt_to_xml()
+
+sub xml_to_txt {
+ # {{{
+ my $Txt = shift;
+ $Txt =~ s/&lt;/</gs;
+ $Txt =~ s/&gt;/>/gs;
+ $Txt =~ s/&amp;/&/gs;
+ return($Txt);
+ # }}}
+} # xml_to_txt()
+
 sub usage {
     # Send the help message to stdout {{{
     my $Retval = shift;
@@ -253,7 +353,7 @@
 
 =head1 REVISION
 
-$Id: svndiff 119 2005-04-26 20:58:54Z sunny256 $
+$Id: svndiff 120 2005-04-26 21:07:18Z sunny256 $
 
 =head1 SYNOPSIS
 
@@ -301,6 +401,36 @@
 
 =back
 
+=head1 FILES
+
+=over 4
+
+=item F<~/.svndiffrc>
+
+A configuration file where you can store your own settings.
+It is a standard XML file with this structure:
+
+ <svndiffrc>
+ <defaults>
+ <diffprog>vimd​iff</diffprog>​
+ </defaults>
+ </svndiffrc>
+
+(Whitespace is optional and more options will come.)
+
+The string inside the C<diffprog> can be set to whatever your diff
+program is called as, the default string is "vimdiff".
+
+=back
+
+=head1 ENVIRONMENT VARIABLES
+
+=over 4
+
+=item I<SVNDIFFRC>
+
+Path to a configuration file in another location than F<~/.svndiffrc> .
+
 =head1 AUTHOR
 
 Made by Øyvind A. Holm S<E<lt>sunny _AT_ sunbase.orgE<gt>>.
@@ -336,4 +466,4 @@
 # }}}
 
 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
-# End of file $Id: svndiff 119 2005-04-26 20:58:54Z sunny256 $
+# End of file $Id: svndiff 120 2005-04-26 21:07:18Z sunny256 $

« 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-26 14:48:09 PDT
Messages per page: