File: patlog.SH

package info (click to toggle)
dist 1%3A3.5-30-3.2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,720 kB
  • sloc: sh: 5,233; perl: 4,429; cpp: 208; makefile: 12; ansic: 4
file content (388 lines) | stat: -rwxr-xr-x 10,415 bytes parent folder | download | duplicates (2)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
case $CONFIG in
'')
	if test -f config.sh; then TOP=.;
	elif test -f ../config.sh; then TOP=..;
	elif test -f ../../config.sh; then TOP=../..;
	elif test -f ../../../config.sh; then TOP=../../..;
	elif test -f ../../../../config.sh; then TOP=../../../..;
	else
		echo "Can't find config.sh."; exit 1
	fi
	. $TOP/config.sh
	;;
esac
case "$0" in
*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
esac
echo "Extracting pat/patlog (with variable substitutions)"
cat >patlog <<!GROK!THIS!
$startperl
	eval "exec perl -S \$0 \$*"
		if \$running_under_some_shell;

# $Id: patlog.SH 20 2008-01-04 23:14:00Z rmanfredi $
#
#  Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
#  
#  You may redistribute only under the terms of the Artistic Licence,
#  as specified in the README file that comes with the distribution.
#  You may reuse parts of this distribution only within the terms of
#  that same Artistic Licence; a copy of which may be found at the root
#  of the source tree for dist 4.0.
#
# $Log: patlog.SH,v $
# Revision 3.0.1.2  1997/02/28  16:33:03  ram
# patch61: typo fix
#
# Revision 3.0.1.1  1994/10/29  16:42:26  ram
# patch36: created
#

\$defeditor='$defeditor';
\$version = '$VERSION';
\$patchlevel = '$PATCHLEVEL';
!GROK!THIS!
cat >>patlog <<'!NO!SUBS!'

$progname = &profile;	# Read ~/.dist_profile
require 'getopts.pl';
&usage unless &Getopts("hnruV");

if ($opt_V) {
	print STDERR "$progname $version PL$patchlevel\n";
	exit 0;
} elsif ($opt_h) {
	&usage;
}

&readpackage;

if (-f 'patchlevel.h') {
	open(PL,"patchlevel.h") || die "$progname: can't open patchlevel.h: $!\n";
	while (<PL>) {
		if (/^#define\s+PATCHLEVEL\s+(\d+)/) {
			$last = $1;
			$patchline = $.;	# Record PATCHLEVEL line
		}
	}
	die "$progname: malformed patchlevel.h file.\n" if $last eq '';
	$bnum = $last + 1;
}
else {
	$patchline = 1;
	$bnum = 1;
	$last = '';
}

chdir 'bugs' if -d 'bugs';

die "$progname: patch #$bnum already exists.\n" if -f "patch$bnum";

@patlist=<*.$bnum>;
die "$progname: no diff files for patch #$bnum.\n" if
	$patlist[0] =~ /^\*/ || $patlist[0] eq '';

# Set up a proper editor, for later perusal
$editor = $ENV{'VISUAL'};
$editor = $ENV{'EDITOR'} unless $editor;
$editor = $defeditor unless $editor;
$editor = 'vi' unless $editor;

# The following used to be done in patmake. Only we do not really need to
# compute the subject lines for the generated patch here, we do it nonetheless
# to avoid code duplication in patmake.

if (-s ".logs$bnum") {
	$logs = '';
	open(LOGS,".logs$bnum");
	while (<LOGS>) {
		unless ($logseen{$_}) {
			$logs .= $_;
			$logseen{$_}++;
			$logsnum++;			# One more log
		}
	}
	close LOGS;
	$subj = $logs;
	$logs =~ s/^patch\d+:\s*/\t/gm;
	$logs =~ s/\n/\n\n/gm;
	$subj =~ s/^patch\d+:\s*/Subject: /gm;
} else {
	$subj = "Subject: \n";
}

# Try to guess the priority of the patch
if (-s ".mods$bnum") {
	open(MODS, ".mods$bnum");
	while (<MODS>) {
		chop;
		unless ($fileseen{$_}) {
			$fileseen{$_}++;
			$modsnum++;			# One more modified file
		}
	}
	close MODS;
}
$modsnum++ unless $modsnum;		# Avoid divisions by zero
$mean = $logsnum / $modsnum;
if ($mean > 0.7 && $mean < 1.3) {
	$priority = "MEDIUM";
} elsif ($mean <= 0.7) {
	$priority = "HIGH";		# Small changes
} else {
	$priority = "LOW";		# Big changes
}

# Save priority for patmake
open(PRIORITY, ">.pri$bnum") || die "$progname: can't create .pri$bnum: $!\n";
print PRIORITY $priority, "\n";
close PRIORITY;

# Save subject lines for patmake
open(SUBJECTS, ">.subj$bnum") || die "$progname: can't create .subj$bnum: $!\n";
print SUBJECTS $subj;
close SUBJECTS;

#
# Generate description file, then edit it so that the user may fixup things.
#

unless (($opt_r && -f ".clog$bnum") || ($opt_u && &uptodate(".clog$bnum"))) {
	open(CHANGES, ">.clog$bnum") ||
		die "$progname: can't create .clog$bnum: $!\n";
	print CHANGES <<EOM;
Edition of the Description section for patch #$bnum.
Please leave those three lines here, they will be removed automatically.
------------------------------------------------------------------------
EOM
	print CHANGES $logs;
	close CHANGES;
}

# If they don't want to maintain a ChangeLog file, that's it. They'll get
# the old behaviour where the description is edited directly from within
# the generated patch.

exit(0) if $changelog =~ /^\s*$/;

system $editor, ".clog$bnum";

#
# Generate RCS log file.
#

if ($changercs) {
	unless (
		($opt_r && -f ".rlog$bnum") || ($opt_u && &uptodate(".rlog$bnum"))
	) {
		&buildlogs;
		open(RCS, ">.rlog$bnum") ||
			die "$progname: can't create .rlog$bnum: $!\n";
		print RCS <<EOM;
Edition of the RCS log section for $changelog (patch #$bnum).
Please leave those three lines here, they will be removed automatically.
------------------------------------------------------------------------
EOM
		foreach $key (sort keys %rcslog) {
			print RCS &format('* ' . $rcslog{$key}), "\n";
		}
		close RCS;
	}
	system $editor, ".rlog$bnum";
}

#
# Final logfile entry generation
#

chop($date=`date`);

unless (
	($opt_r && -f ".xlog$bnum") ||
	($opt_u && &uptodate(".xlog$bnum") && !&newertmp)
) {
	open(LOG, ">.xlog$bnum") || die "$progname: can't create .xlog$bnum: $!\n";
	print LOG <<EOM;
Edition of the $changelog entry for patch #$bnum.
Please leave those three lines here, they will be removed automatically.
------------------------------------------------------------------------
EOM
	print LOG "$date   $maintname <$maintloc>\n\n";
	print LOG ". Description:\n\n";
	&addlog(".clog$bnum");
	if ($changercs) {
		print LOG ". Files changed:\n\n";
		&addlog(".rlog$bnum");
	}
	close LOG;
}
system $editor, ".xlog$bnum";
exit(0) if $opt_n;

#
# Changelog file update, checking in and diff computation.
#

print "$progname: updating $changelog...\n";

chdir('..') || die "$progname: can't go back to ..: $!\n";
if (-f $changelog) {
	rename($changelog, "$changelog.bak") ||
		die "$progname: can't rename $changelog into $changelog.bak: $!\n";
}

open(LOG, ">$changelog") || die "$progname: can't create $changelog: $!\n";
&addlog("bugs/.xlog$bnum");
if (-f "$changelog.bak") {
	open(OLOG, "$changelog.bak") ||
		die "$progname: can't open $changelog.bak: $!\n";
	print LOG while <OLOG>;
	close OLOG;
}
close LOG;

print "$progname: checking in $changelog and computing diff...\n";

# It is safe to run a patcil and a patdiff now, since the Changelog file has
# been updated anyway: any log done while checking that file in will not
# appear in the patch log nor the Changelog.

system 'perl', '-S', 'patcil', '-p', $changelog;
system 'perl', '-S', 'patdiff', $changelog;

exit 0;		# All done.

# Returns true if .clog and .rlog (it it exists) are newer than .xlog.
sub newertmp {
	return 1 unless -f ".xlog$bnum";	# To force regeneration
	return 1 if &newer(".clog$bnum", ".xlog$bnum") ||
		(!$changercs || &newer(".rlog$bnum", ".xlog$bnum"));
	0;
}

# Returns true if $file is newer than the reference file $ref.
sub newer {
	local($file, $ref) = @_;
	(stat($file))[9] >= (stat($ref))[9];
}

# Retursn true if $file is up-to-date with respect to .logs and .mods.
sub uptodate {
	local($file) = @_;
	return 0 unless -f $file;	# Cannot be up-to-date if missing
	&newer($file, ".logs$bnum") && &newer($file, ".mods$bnum");
}

# Add file to the LOG descriptor, skipping the first three lines of that file.
sub addlog {
	local($file) = @_;
	open(FILE, $file) || die "$progname: can't reopen $file: $!\n";
	$_ = <FILE>; $_ = <FILE>; $_ = <FILE>;
	print LOG while <FILE>;
	close FILE;
}

# Build RCS logs, for each file listed in the %fileseen array, into %rcslog.
# Common RCS log messages are grouped under the same entry.
sub buildlogs {
	local($log);
	local(@files);
	local($first);
	local(%invertedlog);
	foreach $file (keys %fileseen) {
		$log = &rcslog($file);
		next if $log eq '';
		$invertedlog{$log} .= "$file ";
	}
	foreach $log (keys %invertedlog) {
		@files = split(' ', $invertedlog{$log});
		$first = (sort @files)[0];
		$rcslog{$first} = join(', ', @files) . ': ' . $log;
	}
}

# Grab log for a given file by parsing its $Log section. Only comments
# relevant to the patch are kept. This relies on the presence of the patchxx:
# leading string in front of each comment.
# If not sufficient (because people don't use patchxx prefixes), then we'll
# need a more sophisticated algorithm parsing revisions lines to see where we
# left of at the last patch.
sub rcslog {
	local($file) = @_;
	open(FILE, "../$file") || warn "$me: can't open $file: $!\n";
	local($_);
	local($comment, $len);
	local($pcomment) = "patch$bnum:";
	local($plen) = length($pcomment);
	local($c);
	local($lastnl) = 1;
	local($kept);			# Relevant part of the RCS comment which is kept
	file: while (<FILE>) {
		if (/^(.*)\$Log[:\$]/) {
			$comment = $1;
			$comment =~ s/\s+$//;	# Newer RCS chop spaces on emtpy lines
			$len = length($comment);
			while (<FILE>) {
				$c = substr($_, 0, $len);
				last file unless $c eq $comment;
				$_ = substr($_, $len, 9_999);
				if ($lastnl) {
					last file unless /^\s*Revision\s+\d/;
					$lastnl = 0;
				} elsif (/^\s*$/) {
					$lastnl = 1;
				} else {
					s/^\s*//;	# Older RCS will have space here
					$c = substr($_, 0, $plen);
					last file unless $c eq $pcomment;
					# Comment for that patch is kept after space cleanup
					$_ = substr($_, $plen, 9_999);
					s/^\s*//;
					s/\s*$//;
					$_ .= '.' unless /\.$/;
					s/^(.)/\U$1/;	# Ensure upper-cased to start sentence
					s/^/  / if $kept;
					$kept .= $_;	# Will be reformatted later on
				}
			}
		}
	}
	close FILE;
	$kept;
}

# Format line to fit in 80 columns (70 + 8 for the added leading tabs).
# Rudimentary parsing to break lines after a , or a space.
sub format {
	local($_) = @_;
	local($tmp);
	local($msg);
	while (length($_) > 70) {
		$tmp = substr($_, 0, 70);
		$tmp =~ s/^(.*)([,\s]).*/$1/;
		$msg .= "\t$tmp" . ($2 eq ',' ? ',' : '') . "\n";
		$_ = substr($_, length($tmp), 9_999);
		$_ =~ s/^\s+//;
	}
	$msg .= "\t$_\n";
	$msg;
}

sub usage {
	print STDERR <<EOM;
Usage: $progname [-hnruV]
  -h : print this message and exit.
  -n : not-really mode: force re-edit, but stop after updating.
  -r : reuse existing change file candidate entries (supersedes -u).
  -u : update mode, recreate files only when out of date.
  -V : print version number and exit.
EOM
	exit 1;
}

!NO!SUBS!
$grep -v '^;#' ../pl/package.pl >>patlog
$grep -v '^;#' ../pl/tilde.pl >>patlog
$grep -v '^;#' ../pl/profile.pl >>patlog
chmod +x patlog
$eunicefix patlog