diff mbox

Keep patch file permissions in mklog

Message ID 53DD3AB2.9040901@mentor.com
State New
Headers show

Commit Message

Tom de Vries Aug. 2, 2014, 7:23 p.m. UTC
On 01-08-14 09:18, Yury Gribov wrote:
> On 08/01/2014 10:52 AM, Tom de Vries wrote:
>> This patch adds a script contrib/mklog-in-patch, which uses mklog to
>> generate the skeleton log, but generates the log at the start of the
>> patch as mklog did before (which is how I like to use it).
>
> Yeah, we had some argument about this but kind of agreed that separate log is
> preferred.
>
>> I can also try to add an --inline option to mklog instead.
>
> I'd prefer this.
>

This patch implements an --inline option to mklog.

I've used the --inline option to prepend the skeleton log to this patch.

OK for trunk?

Thanks,
- Tom

Comments

Yury Gribov Aug. 4, 2014, 6:45 a.m. UTC | #1
Thanks! My 2 (actually 4) cents below.

 > +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?

 > +	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.

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

Could we use more descriptive name?

 > +	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...

-Y
diff mbox

Patch

2014-08-02  Tom de Vries  <tom@codesourcery.com>

	* mklog: Add --inline option.

diff --git a/contrib/mklog b/contrib/mklog
index 3d17dc5..ba075cf 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -56,19 +56,27 @@  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")) {
+	$diff = $ARGV[1];
+	$inline = 1;
+	if ($diff eq "-") {
+	        die "Reading from - and using -i are not compatible";
+	}
+} 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.
 When file.diff is -, read standard input.
 EOF
     exit 1;
+} else {
+	$diff = $ARGV[0];
 }
 
-$diff = $ARGV[0];
 $dir = `dirname $diff`; chop ($dir);
 $basename = `basename $diff`; chop ($basename);
 $hdrline = "$date  $name  <$addr>";
@@ -273,8 +281,32 @@  foreach (@diff_lines) {
 # functions.
 $cl_entries{$clname} .= $change_msg ? "$change_msg\n" : ":\n";
 
+if ($inline) {
+	$tmp = `mktemp`;
+	chomp ($tmp);
+	open (FILE1, '>', $tmp) or die "Could not open temp file";
+} else {
+    *FILE1 = STDOUT;
+}
+
+# Print the log
 foreach my $clname (keys %cl_entries) {
-	print "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
+	print FILE1 "$clname:\n\n$hdrline\n\n$cl_entries{$clname}\n";
+}
+
+
+# Prepend the log to the patch
+if ($inline) {
+	close (FILE1);
+
+	system ("cat $diff >>$tmp") == 0
+		or die "Could not append patch to temp file";
+
+	# 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) == 1 or die "Could not remove temp file";
 }
 
 exit 0;
-- 
1.9.1