Attachment 'mklog.pl'

Download

   1 #!/usr/bin/perl
   2 # $Id: mklog 11 2007-05-21 21:36:28Z drow $
   3 #
   4 # This script parses a .diff file generated with 'diff -up' or 'diff -cp'
   5 # and writes a skeleton ChangeLog file to stdout. It does not try to be
   6 # very smart when parsing function names, but it produces a reasonable
   7 # approximation.
   8 
   9 # Change these settings to reflect your profile. 
  10 $name = "Your Name";
  11 $addr = "your\@email.address";
  12 $date = `date +%Y-%m-%d`; chop ($date);
  13 
  14 
  15 #-----------------------------------------------------------------------------
  16 # Program starts here. You should not need to edit anything below this
  17 # line.
  18 #-----------------------------------------------------------------------------
  19 if ( $#ARGV != 0 ) {
  20     $prog = `basename $0`; chop ($prog);
  21     print "usage: $prog file.diff\n\n";
  22     print "Adds a ChangeLog template to the start of file.diff\n";
  23     print "It assumes that file.diff has been created with -up or -cp.\n";
  24     exit 1;
  25 }
  26 
  27 $diff = $ARGV[0];
  28 $dir = `dirname $diff`; chop ($dir);
  29 $base = `basename $diff`; chop ($base);
  30 $cl = `mktemp /tmp/$base.XXXXXX` || exit 1; chop ($cl);
  31 $hdrline = "$date  $name  <$addr>";
  32 
  33 open (CLFILE, ">$cl") or die "Could not open file $cl for writing";
  34 
  35 print CLFILE "$hdrline\n\n";
  36 
  37 # For every file in the .diff print all the function names in ChangeLog
  38 # format.
  39 $bof = 0;
  40 open (DFILE, $diff) or die "Could not open file $diff for reading";
  41 while (<DFILE>) {
  42     # Check if we found a new file.
  43     if ((/^Index: (.*)$/ || /^\+\+\+ ([^\t]*)\t([0-9].*|\((revision .*|local|working copy)\))$/)
  44 	&& ($filename ne $1)){
  45 	# If we have not seen any function names in the previous file (ie,
  46 	# $bof == 1), we just write out a ':' before starting the next
  47 	# file.
  48 	if ($bof == 1) {
  49 	    print CLFILE ":\n";
  50 	}
  51 	$filename = $1;
  52 	print CLFILE "\t* $filename";
  53 	$bof = 1;
  54 	undef %seen_names;
  55     }
  56 
  57     # If we find a new function, print it in brackets.  Special case if
  58     # this is the first function in a file.  
  59     #
  60     # Note that we don't try too hard to find good matches.  This should
  61     # return a superset of the actual set of functions in the .diff file.
  62     #
  63     # The first two patterns work with context diff files (diff -c). The
  64     # third pattern works with unified diff files (diff -u).
  65 
  66     my $linestart = "[-a-zA-Z0-9_.]+";
  67     if (/^\*\*\*\*\*\** ($linestart)/
  68         || /^[\-\+\!] ($linestart)[ \t]*\(.*/
  69 	|| /^@@ .* @@ ($linestart)/)
  70       {
  71 	$fn = $1;
  72 	if ($seen_names{$fn} == 0) {
  73 	    # If this is the first function in the file, we display it next
  74 	    # to the filename, so we need an extra space before the opening
  75 	    # brace.
  76 	    if ($bof) {
  77 		print CLFILE " ";
  78 		$bof = 0;
  79 	    } else {
  80 		print CLFILE "\t";
  81 	    }
  82 
  83 	    print CLFILE "($fn):\n";
  84 	    $seen_names{$fn} = 1;
  85 	}
  86     }
  87 }
  88 
  89 # If we have not seen any function names (ie, $bof == 1), we just
  90 # write out a ':'. This happens when there is only one file with no
  91 # functions.
  92 if ($bof == 1) {
  93     print CLFILE ":\n";
  94 }
  95 
  96 print CLFILE "\n";
  97 close (DFILE);
  98 
  99 # Concatenate the ChangeLog template and the original .diff file.
 100 system ("cat $diff >>$cl && mv $cl $diff") == 0
 101     or die "Could not add the ChangeLog entry to $diff";
 102 
 103 exit 0;

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.