1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
package ChangeLogEntry;
# ************************************************************
# Description : Create a ChangeLog entry based on modified files.
# Author : Chad Elliott
# Create Date : 6/18/2002
# $Id: ChangeLogEntry.pm 94634 2011-10-06 12:58:32Z johnnyw $
# ************************************************************
# ************************************************************
# Pragmas
# ************************************************************
use strict;
use File::Basename;
use FileLocatorFactory;
# ************************************************************
# Subroutine Section
# ************************************************************
sub new {
my($class) = shift;
my($name) = shift;
my($email) = shift;
my($self) = bless {'name' => $name,
'email' => $email,
}, $class;
return $self;
}
sub escape_regex_special {
my($self) = shift;
my($name) = shift;
$name =~ s/([\+\-\\\$\[\]\(\)\.])/\\$1/g;
return $name;
}
sub sortFileList {
my($self) = shift;
return sort {
if ($a =~ /\.h$/) {
my($base) = $a;
$base =~ s/\.h//;
$base = $self->escape_regex_special($base);
if ($b =~ /^$base\./) {
return -1;
}
else {
return $a cmp $b;
}
}
elsif ($a =~ /\.i(nl)?$/) {
my($base) = $a;
$base =~ s/\.i(nl)?$//;
$base = $self->escape_regex_special($base);
if ($b =~ /^$base\.cpp/) {
return -1;
}
else {
return $a cmp $b;
}
}
elsif ($a =~ /\.cpp?$/) {
my($base) = $a;
$base =~ s/\.cpp?$//;
$base = $self->escape_regex_special($base);
if ($b =~ /^$base\./) {
return 1;
}
else {
return $a cmp $b;
}
}
return $a cmp $b;
} @_;
}
sub create {
my($self) = shift;
my(@dirs) = @_;
my($fl) = FileLocatorFactory::create();
my($modif,
$remov,
$confl,
$unknown,
$error) = $fl->locate(@dirs);
my($entry) = scalar(gmtime());
if (defined $$confl[0]) {
$entry = "ERROR: The following files have conflicts:\n";
foreach my $file (@$confl) {
$entry .= "$file\n";
}
}
else {
my($prefix) = ' * ';
## Correct the timezone (if there is any)
my($tz) = 'UTC';
$entry =~ s/(:\d\d\s+)(.*)(\d\d\d\d)$/$1$tz $3/;
## Add the name and email address
$entry .= " $self->{'name'} <$self->{'email'}>\n\n";
my($previous) = undef;
foreach my $file ($self->sortFileList(@$modif)) {
my($directory) = dirname($file);
if (defined $previous && $previous ne $directory) {
$entry .= "\n";
}
$entry .= "$prefix$file:\n";
$previous = $directory;
}
$previous = '';
my($removed) = 0;
foreach my $file ($self->sortFileList(@$remov)) {
my($directory) = dirname($file);
if (defined $previous && $previous ne $directory) {
$entry .= "\n";
}
$entry .= "$prefix$file:\n";
$previous = $directory;
$removed++;
}
if ($removed) {
$entry .= "\n Removed " .
($removed > 1 ? 'these files' : 'this file') . ".\n";
}
$entry .= "\n";
}
if (!defined $$modif[0] && !defined $$remov[0]) {
$entry = undef;
}
return $entry, $unknown, $error;
}
1;
|