Re: [Xen-devel] [PATCH v5] scripts/add_maintainers.pl: New script

2018-05-15 Thread Ian Jackson
Lars Kurth writes ("Re: [PATCH v5] scripts/add_maintainers.pl: New script"):
> Acked-by: Lars Kurth 
> Although it should probably mention --get-maintainers in the help message

Good point.

Ian.

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v5] scripts/add_maintainers.pl: New script

2018-05-15 Thread Lars Kurth
Acked-by: Lars Kurth 
Although it should probably mention --get-maintainers in the help message
Lars

On 15/05/2018, 18:12, "Ian Jackson"  wrote:

(Fixed the Subject line.)

Ian Jackson writes ("[PATCH] scripts/add_maintainers.pl: New script"):
> Changes since v4:
> - Strip some trailing whitespace from the code
> - writefile() now uses the .tmp-and-rename pattern to avoid data loss
> - Provide --get-maintainers= option to specify replacement for
>   get_maintainers.pl.  This is useful for Ian's usecase, since it
>   allows --get-maintainers=true, to avoid adding any MAINTAINERS-based
>   info anywhere while still adding other CCs (eg from -t) everywhere.
> - Refactor normalize() somewhat so that it uses only %seen, and
>   does not any longer modify its argument arrays.
> - De-dupe case-insensitively (by making normalize use lc).

Here's the diff for my changes.

diff --git a/scripts/add_maintainers.pl b/scripts/add_maintainers.pl
index b4134e9..0f4a4cf 100755
--- a/scripts/add_maintainers.pl
+++ b/scripts/add_maintainers.pl
@@ -223,6 +223,7 @@ if (!GetOptions(
 't|tags'   => \$tags,
 'tagscc'   => \$tagscc,
 'a|arg=s'  => \@get_maintainer_args,
+'get-maintainers=s' => \$get_maintainer,
 'verbose'  => \$verbose,
 'h|help'   => \$help,
 )) {
@@ -345,7 +346,7 @@ if ($has_cover_letter) {
 my @ccpatch;# Cc: entries in *.patch
 
 print "Processing: ".basename($cover_letter_file)."\n";
-
+
 # Read all lines with CC & TO from the patch file such that subsequent
 # calls don't lead to duplication
 gettagsfrompatch($cover_letter_file, \@headerpatch, \@ccpatch);
@@ -467,21 +468,20 @@ sub hastag ($$) {
 }
 
 sub normalize ($$) {
-# This function is used to normalize lists of tags or CC / TO lists
-# - It removes duplicates in the input arrays
-# - It ensures that elements in the second list are not in the first
 my ($ra, $rb) = @_;
+# This function is used to normalize lists of tags or CC / TO lists
+# It returns a list of the unique elements
+# in @$ra, excluding any which are in @$rb.
+# Comparisons are case-insensitive.
 my @aonly = ();
 my %seen;
 my $item;
 
-@$ra = uniq @$ra;
-@$rb = uniq @$rb;
 foreach $item (@$rb) {
-$seen{$item} = 1;
+$seen{lc($item)} = 1;
 }
 foreach $item (@$ra) {
-unless ($seen{$item}) {
+unless ($seen{lc($item)}++) {
 # it's not in %seen, so add to @aonly
 push @aonly, $item;
 }
@@ -506,10 +506,11 @@ sub readfile ($) {
 sub writefile ($$) {
 my ($content, $file) = @_;
 my $fh;
-open($fh, ">", $file)
- or die "Could not open file '$file' $!";
+open($fh, ">", "$file.tmp")
+ or die "Could not open file '$file.tmp' $!";
 print $fh $content or die $!;
 close $fh or die $!;
+rename "$file.tmp", $file or die "Could not rename '$file' into place 
$!";
 }
 
 sub insert () {


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v5] scripts/add_maintainers.pl: New script

2018-05-15 Thread Ian Jackson
(Fixed the Subject line.)

Ian Jackson writes ("[PATCH] scripts/add_maintainers.pl: New script"):
> Changes since v4:
> - Strip some trailing whitespace from the code
> - writefile() now uses the .tmp-and-rename pattern to avoid data loss
> - Provide --get-maintainers= option to specify replacement for
>   get_maintainers.pl.  This is useful for Ian's usecase, since it
>   allows --get-maintainers=true, to avoid adding any MAINTAINERS-based
>   info anywhere while still adding other CCs (eg from -t) everywhere.
> - Refactor normalize() somewhat so that it uses only %seen, and
>   does not any longer modify its argument arrays.
> - De-dupe case-insensitively (by making normalize use lc).

Here's the diff for my changes.

diff --git a/scripts/add_maintainers.pl b/scripts/add_maintainers.pl
index b4134e9..0f4a4cf 100755
--- a/scripts/add_maintainers.pl
+++ b/scripts/add_maintainers.pl
@@ -223,6 +223,7 @@ if (!GetOptions(
 't|tags'   => \$tags,
 'tagscc'   => \$tagscc,
 'a|arg=s'  => \@get_maintainer_args,
+'get-maintainers=s' => \$get_maintainer,
 'verbose'  => \$verbose,
 'h|help'   => \$help,
 )) {
@@ -345,7 +346,7 @@ if ($has_cover_letter) {
 my @ccpatch;# Cc: entries in *.patch
 
 print "Processing: ".basename($cover_letter_file)."\n";
-
+
 # Read all lines with CC & TO from the patch file such that subsequent
 # calls don't lead to duplication
 gettagsfrompatch($cover_letter_file, \@headerpatch, \@ccpatch);
@@ -467,21 +468,20 @@ sub hastag ($$) {
 }
 
 sub normalize ($$) {
-# This function is used to normalize lists of tags or CC / TO lists
-# - It removes duplicates in the input arrays
-# - It ensures that elements in the second list are not in the first
 my ($ra, $rb) = @_;
+# This function is used to normalize lists of tags or CC / TO lists
+# It returns a list of the unique elements
+# in @$ra, excluding any which are in @$rb.
+# Comparisons are case-insensitive.
 my @aonly = ();
 my %seen;
 my $item;
 
-@$ra = uniq @$ra;
-@$rb = uniq @$rb;
 foreach $item (@$rb) {
-$seen{$item} = 1;
+$seen{lc($item)} = 1;
 }
 foreach $item (@$ra) {
-unless ($seen{$item}) {
+unless ($seen{lc($item)}++) {
 # it's not in %seen, so add to @aonly
 push @aonly, $item;
 }
@@ -506,10 +506,11 @@ sub readfile ($) {
 sub writefile ($$) {
 my ($content, $file) = @_;
 my $fh;
-open($fh, ">", $file)
- or die "Could not open file '$file' $!";
+open($fh, ">", "$file.tmp")
+ or die "Could not open file '$file.tmp' $!";
 print $fh $content or die $!;
 close $fh or die $!;
+rename "$file.tmp", $file or die "Could not rename '$file' into place $!";
 }
 
 sub insert () {

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel