2014-08-02 Tom de Vries <tom@codesourcery.com>
* mklog: Add --inline option.
@@ -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