[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 1/2] Add new add_maintainers.pl script to optimise the workflow when using git format-patch with get_maintainer.pl
The tool covers step 2 of the following workflow Without --overwrite Step 1: git format-patch ... -o <patchdir> ... Step 2: ./scripts/add_maintainers.pl -d <patchdir> This creates *.patchm files in <patchdir> Step 3: git send-email -to xen-devel@xxxxxxxxxxxxxxxxxxxx <patchdir>/*.patchm With --overwrite Step 1: git format-patch ... -o <patchdir> ... Step 2: ./scripts/add_maintainers.pl -d <patchdir> This overwrites *.patch files in <patchdir> but makes a backup Step 3: git send-email -to xen-devel@xxxxxxxxxxxxxxxxxxxx <patchdir>/*.patch It is not clear to me what the preferred default would be, so I went for the safer option (ok without --overwrite). I manually tested all options and the most common combinations on Mac. Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Jan Beulich <jbeulich@xxxxxxxx> Cc: Julien Grall <julien.grall@xxxxxxx> Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx> Cc: Tim Deegan <tim@xxxxxxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> Signed-off-by: Lars Kurth <lars.kurth@xxxxxxxxxx> --- scripts/add_maintainers.pl | 252 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100755 scripts/add_maintainers.pl diff --git a/scripts/add_maintainers.pl b/scripts/add_maintainers.pl new file mode 100755 index 0000000000..27ac74f339 --- /dev/null +++ b/scripts/add_maintainers.pl @@ -0,0 +1,252 @@ +#!/usr/bin/perl -w +# (c) 2018, Lars Kurth <lars.kurth@xxxxxxxxxx> +# +# Add maintainers to patches generated with git format-patch +# +# Usage: perl scripts/add_maintainers.pl [OPTIONS] -patchdir <patchdir> +# +# Prerequisites: Execute +# git format-patch ... -o <patchdir> ... +# +# ./scripts/get_maintainer.pl is present in the tree +# +# Licensed under the terms of the GNU GPL License version 2 + +use strict; + +use Getopt::Long qw(:config no_auto_abbrev); +use File::Basename; +use List::MoreUtils qw(uniq); + +# Arguments / Options +my $tool = $0; +my $toolversion = "1.0"; + +# Arguments / Options +my $version = 0; +my $help = 0; +my $patch_dir = 0; +my $patch_prefix = ""; +my $get_maintainer_args = ""; +my $verbose = 0; +my $overwrite = 0; +my $overwrite_ext = "m"; + +# Constants +my $CC = "Cc: "; # Note: git-send-mail requires Cc: +my $TO = "To: "; +my $AT = "@"; +my $cc_insert_before = "Signed-off-by:"; +my $to_insert_before = "Date:"; +my $cover_letter = "0000-cover-letter.patch"; +my $get_maintainer = "./scripts/get_maintainer.pl"; +my $patch_ext = ".patch"; +my $mailing_lists = $AT."lists."; + +my @lists; #Needed for <<EOT +my $usage = <<EOT; +USAGE: $tool [options] -patchdir <patchdir> +VERSION: $toolversion + +OPTIONS: +-------- + --p|prefix (e.g. --prefix v2) + Choose patch files with a specific prefix + --a|args + Arguments passed on to $get_maintainer + --v|verbose + Show more output + --version + Show version + --o|overwrite + Overwrites *.patch file (but makes a backup), whereas teh default + creates a new *.mpatch file + --h|help|usage + Show this help information + +WORKFLOW: +--------- + This script is intended to be used as part of the following workflow + + Without --overwrite + Step 1: git format-patch ... -o <patchdir> ... + Step 2: ./scripts/add_maintainers.pl -d <patchdir> + This creates *.patchm files in <patchdir> + Step 3: git send-email -to xen-devel@xxxxxxxxxxxxxxxxxxxx <patchdir>/*.patchm + + With --overwrite + Step 1: git format-patch ... -o <patchdir> ... + Step 2: ./scripts/add_maintainers.pl -d <patchdir> + This overwrites *.patch files in <patchdir> but makes a backup + Step 3: git send-email -to xen-devel@xxxxxxxxxxxxxxxxxxxx <patchdir>/*.patch +EOT + +if (!GetOptions( + 'd|patchdir=s' => \$patch_dir, + 'p|prefix=s' => \$patch_prefix, + 'o|overwrite' => \$overwrite, + 'a|args=s' => \$get_maintainer_args, + 'v|verbose' => \$verbose, + 'version' => \$version, + 'h|help|usage' => \$help, + )) { + die "$tool: invalid argument - use --help if necessary\n"; +} + +if ($help != 0) { + print $usage; + exit 0; +} + +if ($version != 0) { + print("$tool: version $toolversion\n"); + exit 0; +} + +if (! -e $get_maintainer) { + die "$tool: The tool requires $get_maintainer\n"; +} + +if (!$patch_dir) { + die "$tool: Directory -d|--patchdir not specified\n"; +} +if (! -e $patch_dir) { + die "$tool: Directory $patch_dir does not exist\n"; +} +if ($overwrite) { + $overwrite_ext = ""; +} + +# Get the list of patches +my $pattern = $patch_dir.'/'.$patch_prefix.'*'.$patch_ext; +my @patches = glob($pattern); +my $has_cover_letter = 0; +my $cover_letter_file; + +if (!scalar @patches) { + die "$tool: Directory $patch_dir contains no patches\n"; +} + +# Do the actual processing +my $file; +my @combined_to; +my @combined_cc; + +foreach my $file (@patches){ + if (index($file, $cover_letter) != -1) { + $has_cover_letter = 1; + $cover_letter_file = $file; + } else { + print "Processing: ".basename($file)."\n"; + my $fh; + my $cmd = $get_maintainer." ".$get_maintainer_args." < ".$file; + my @to; + my @cc; + + open($fh, "$cmd|") + or die "Failed to execute '$cmd'\n"; + while(<$fh>) { + chomp; + # Keep lists and CC's separately as we dont want them in + # the commit message under a Cc: line + if (index($_, $mailing_lists) != -1) { + push @to, $TO.$_; + push @combined_to, $TO.$_; + } else { + push @cc, $CC.$_; + push @combined_cc, $CC.$_; + } + } + close $fh; + + my $to = join("\n", uniq @to)."\n"; + my $cc = join("\n", uniq @cc)."\n"; + + # Insert snippets into files + # $cc before "Signed-off-by:" + insert_before($file , $cc, $cc_insert_before, 1); + # $to before suitable header line + insert_before($file , $to, $to_insert_before, 0); + } +} + +# Deal with the cover letter +if ($has_cover_letter) { + my $to = join("\n", uniq @combined_to)."\n"; + my $cc = join("\n", uniq @combined_cc)."\n"; + + print "Processing: ".basename($cover_letter_file)."\n"; + + # Insert snippets into files + # $to and $cc before suitable header line + insert_before($cover_letter_file, $to.$cc, $to_insert_before, 1); + + print "\nDon't forget to add the subject and message to ". + $cover_letter_file.$overwrite_ext."\n"; +} + +print "Then perform:\n". + "git send-email -to xen-devel".$AT."lists.xenproject.org ". + $patch_dir.'/'.$patch_prefix."*.patch".$overwrite_ext."\n"; + +exit 1; + +sub readfile { + my ($file) = @_; + my $fh; + my $content; + open($fh, "<", $file) + or die "Could not open file '$file' $!"; + $content = do { local $/; <$fh> }; + close $fh; + + return $content; +} + +sub writefile { + my ($content, $file) = @_; + my $fh; + open($fh, ">", $file) + or die "Could not open file '$file' $!"; + print $fh $content; + close $fh; + + return 1; +} + +sub insert_before { + my ($file, $ins, $before, $first) = @_; + my $content; + + # $first must always be set to one for the first + # in a series of multiple transformations. This is + # a little ugly, but allows us to handle backups + # and filename issues correctly. + + # Also, the different filename handling via + # $overwrite is entirely handled in this function. + if ($first) { + $content = readfile($file); + if ($overwrite) { + # Make a backup + writefile($content, $file."~"); + } + } else { + # Read from the previously modified file + $content = readfile($file.$overwrite_ext); + } + + # Split the string and generate new content + my $i = index($content, $before); + my $p1 = substr $content, 0, $i; + my $p2 = substr $content, $i; + # + writefile($p1.$ins.$p2, $file.$overwrite_ext); + + if ($verbose) { + print "\nInserted into ".basename($file).' before "$before"'. + "\n-----\n".$ins."-----\n"; + } + + return 1; +} -- 2.13.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |