This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Keep patch file permissions in mklog


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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]