On 04-08-14 08:45, Yury Gribov wrote:
Thanks! My 2 (actually 4) cents below.


Hi Yuri,

thanks for the review.

 > +if ($#ARGV == 1 && ("$ARGV[0]" eq "-i" || "$ARGV[0]" eq "--inline")) {
 > +    $diff = $ARGV[1];

Can we shift here and then just set $diff to $ARGV[0] unconditionally?


Done.

 > +    if ($diff eq "-") {
 > +            die "Reading from - and using -i are not compatible";
 > +    }

Hm, can't we dump ChangeLog to stdout in that case?
The limitation looks rather strange.


My original idea here was that --inline means 'in the patch file', which is not possible if the patch comes from stdin.

I've now interpreted it such that --inline prints to stdout what it would print to the patch file otherwise, that is, both log and patch. Printing just the log to stdout can be already be achieved by not using --inline.

 > +    open (FILE1, '>', $tmp) or die "Could not open temp file";

Could we use more descriptive name?


I've used the slightly more descriptive 'OUTPUTFILE'.

 > +    system ("cat $diff >>$tmp") == 0
 > +        or die "Could not append patch to temp file";
 > ...
 > +    unlink ($tmp) == 1 or die "Could not remove temp file";

The checks look like an overkill given that we don't check for result of 
mktemp...


I've added a check for the result of mktemp, and removed the unlink result check. I've left in the "Could not append patch to temp file" check because the patch file might be read-only.

OK for trunk?

Thanks,
- Tom

2014-08-04  Tom de Vries  <t...@codesourcery.com>

	* mklog: Add --inline option.

diff --git a/contrib/mklog b/contrib/mklog
index 3d17dc5..27a0929 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -56,10 +56,14 @@ if (-d "$gcc_root/.git") {
 # Program starts here. You should not need to edit anything below this
 # line.
 #-----------------------------------------------------------------------------
-if ($#ARGV != 0) {
+$inline = 0;
+if ($#ARGV == 1 && ("$ARGV[0]" eq "-i" || "$ARGV[0]" eq "--inline")) {
+	shift;
+	$inline = 1;
+} elsif ($#ARGV != 0) {
     $prog = `basename $0`; chop ($prog);
     print <<EOF;
-usage: $prog file.diff
+usage: $prog [ -i | --inline ] file.diff
 
 Generate ChangeLog template for file.diff.
 It assumes that patch has been created with -up or -cp.
@@ -273,8 +277,39 @@ foreach (@diff_lines) {
 # functions.
 $cl_entries{$clname} .= $change_msg ? "$change_msg\n" : ":\n";
 
+if ($inline && $diff ne "-") {
+	$tmp = `mktemp`;
+	if ($? != 0) {
+		die "Could not generate temp file";
+	}
+	chomp ($tmp);
+	open (OUTPUTFILE, '>', $tmp) or die "Could not open temp file $tmp";
+} else {
+	*OUTPUTFILE = STDOUT;
+}
+
+# Print the log
 foreach my $clname (keys %cl_entries) {
-	print "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
+	print OUTPUTFILE "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
+}
+
+# Append the patch to the log
+if ($inline) {
+	foreach (@diff_lines) {
+		print OUTPUTFILE "$_\n";
+	}
+}
+
+# Replace the patch with the temp file
+if ($inline && $diff ne "-") {
+	close (OUTPUTFILE);
+
+	# We're using cat rather than move, to keep permissions on $diff the
+	# same.
+	system ("cat $tmp >$diff") == 0
+		or die "Could not move temp file to patch file";
+
+	unlink ($tmp);
 }
 
 exit 0;
-- 
1.9.1

Reply via email to