logo

utils

Old programs, got split in utils-std and utils-extra git clone https://anongit.hacktivis.me/git/utils.git/

post-update.reuse (1315B)


  1. #!/usr/bin/env perl
  2. # reuse lint appropriate for git-hook (short summary, no output on success)
  3. # SPDX-FileCopyrightText: 2025 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. use JSON;
  6. use Cwd;
  7. use builtin qw(reftype);
  8. use strict;
  9. my $base = getcwd;
  10. if ($base =~ /\.git$/) {
  11. $base =~ s/\.git$/\.work/;
  12. chdir $base or die "chdir failed: $!";
  13. }
  14. open(FH, '-|', 'reuse lint -j') or die "Failed to execute reuse: $!";
  15. undef $/; # slurp
  16. my $reuse_json = decode_json(<FH>);
  17. # ignore reuse exit status
  18. if (not close(FH) and $!) {
  19. die "Error closing reuse pipe: $!"
  20. }
  21. if ($reuse_json->{"summary"}->{"compliant"} != JSON::true) {
  22. my $obj = $reuse_json->{"non_compliant"};
  23. foreach my $key (keys %{$obj}) {
  24. my $v = $obj->{$key};
  25. my $ref_type = reftype($v);
  26. if ($ref_type eq 'ARRAY') {
  27. my $n = scalar @{$v};
  28. if($n == 1) {
  29. print "reuse: ", $key, ": [\"" , $v->[0], "\"]\n";
  30. } elsif ($n > 1) {
  31. print "reuse: ", $key, ": @ " , $n, "\n";
  32. }
  33. } elsif ($ref_type eq 'HASH') {
  34. my @k = keys %{$v};
  35. my $n = scalar @k;
  36. if($n == 1) {
  37. print "reuse: ", $key, ": {\"" , $k[0], "\": …}\n";
  38. } elsif ($n > 1) {
  39. print "reuse: ", $key, ": % " , $n, "\n";
  40. }
  41. } else {
  42. print "reuse: ", $key, ": [", $ref_type ,"] " , $v, "\n";
  43. }
  44. }
  45. }