mirror of
				https://codeberg.org/h3xx/simplify_static_dir
				synced 2024-08-14 23:57:24 +00:00 
			
		
		
		
	Re-write squasher
Add ability to skip over sections (ignore) vs. completely remove them (remove).
This commit is contained in:
		
							parent
							
								
									1582920286
								
							
						
					
					
						commit
						9dc3e4578c
					
				
					 6 changed files with 38 additions and 16 deletions
				
			
		|  | @ -8,9 +8,9 @@ Object for abstracting management of a hashed filesystem | ||||||
| 
 | 
 | ||||||
| =cut | =cut | ||||||
| 
 | 
 | ||||||
| # :squash-ignore-start: | # :squash-remove-start: | ||||||
| require Directory::Simplify::File; | require Directory::Simplify::File; | ||||||
| # :squash-ignore-end: | # :squash-remove-end: | ||||||
| 
 | 
 | ||||||
| sub new { | sub new { | ||||||
|     my $class = shift; |     my $class = shift; | ||||||
|  |  | ||||||
|  | @ -4,9 +4,9 @@ use strict; | ||||||
| use warnings; | use warnings; | ||||||
| use overload '""' => 'as_string'; | use overload '""' => 'as_string'; | ||||||
| 
 | 
 | ||||||
| # :squash-ignore-start: | # :squash-remove-start: | ||||||
| require Directory::Simplify::Utils; | require Directory::Simplify::Utils; | ||||||
| # :squash-ignore-end: | # :squash-remove-end: | ||||||
| 
 | 
 | ||||||
| sub new { | sub new { | ||||||
|     my $class = shift; |     my $class = shift; | ||||||
|  |  | ||||||
|  | @ -6,10 +6,10 @@ use overload '""' => 'as_string'; | ||||||
| use File::Basename qw/ dirname /; | use File::Basename qw/ dirname /; | ||||||
| use File::Compare qw/ compare /; | use File::Compare qw/ compare /; | ||||||
| 
 | 
 | ||||||
| # :squash-ignore-start: | # :squash-remove-start: | ||||||
| require Directory::Simplify::Instruction::CopyTimestamp; | require Directory::Simplify::Instruction::CopyTimestamp; | ||||||
| require Directory::Simplify::Instruction::Hardlink; | require Directory::Simplify::Instruction::Hardlink; | ||||||
| # :squash-ignore-end: | # :squash-remove-end: | ||||||
| 
 | 
 | ||||||
| sub new { | sub new { | ||||||
|     my $class = shift; |     my $class = shift; | ||||||
|  |  | ||||||
|  | @ -4,9 +4,9 @@ use strict; | ||||||
| use warnings; | use warnings; | ||||||
| use overload '""' => 'as_string'; | use overload '""' => 'as_string'; | ||||||
| 
 | 
 | ||||||
| # :squash-ignore-start: | # :squash-remove-start: | ||||||
| require Directory::Simplify::Utils; | require Directory::Simplify::Utils; | ||||||
| # :squash-ignore-end: | # :squash-remove-end: | ||||||
| 
 | 
 | ||||||
| sub new { | sub new { | ||||||
|     my $class = shift; |     my $class = shift; | ||||||
|  |  | ||||||
|  | @ -104,7 +104,7 @@ use File::Find qw/ find /; | ||||||
| use Getopt::Std qw/ getopts /; | use Getopt::Std qw/ getopts /; | ||||||
| use Pod::Usage qw/ pod2usage /; | use Pod::Usage qw/ pod2usage /; | ||||||
| 
 | 
 | ||||||
| # :squash-ignore-start: | # :squash-remove-start: | ||||||
| # (this prepends to the load path) | # (this prepends to the load path) | ||||||
| use FindBin qw//; | use FindBin qw//; | ||||||
| use lib $FindBin::RealBin; | use lib $FindBin::RealBin; | ||||||
|  | @ -113,7 +113,7 @@ require Directory::Simplify::File; | ||||||
| require Directory::Simplify::FileHash; | require Directory::Simplify::FileHash; | ||||||
| require Directory::Simplify::Instruction::Generator; | require Directory::Simplify::Instruction::Generator; | ||||||
| require Directory::Simplify::Utils; | require Directory::Simplify::Utils; | ||||||
| # :squash-ignore-end: | # :squash-remove-end: | ||||||
| 
 | 
 | ||||||
| sub HELP_MESSAGE { | sub HELP_MESSAGE { | ||||||
|     my $fh = shift; |     my $fh = shift; | ||||||
|  |  | ||||||
							
								
								
									
										34
									
								
								util/squash
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								util/squash
									
										
									
									
									
								
							|  | @ -18,17 +18,35 @@ for my $arg (@ARGV) { | ||||||
|     warn "Reading $filename\n"; |     warn "Reading $filename\n"; | ||||||
|     open my $fh, '<', $filename or die "Can't open $filename: $!"; |     open my $fh, '<', $filename or die "Can't open $filename: $!"; | ||||||
|     my $in_pod = 0; |     my $in_pod = 0; | ||||||
|     my $in_ignore_section = 0; |     my $in_section = ''; | ||||||
|  |     my $ignore_lines = 0; | ||||||
|     while (<$fh>) { |     while (<$fh>) { | ||||||
|         if (/#.*:squash-ignore-start:$/) { |         if (/#.*:squash-ignore-start:$/) { | ||||||
|             $in_ignore_section = 1; |             $in_section = 'ignore'; | ||||||
|             next; |             $ignore_lines = 1; | ||||||
|         } elsif (/#.*:squash-ignore-end:$/) { |         } elsif (/#.*:squash-ignore-end:$/) { | ||||||
|             $in_ignore_section = 0; |             $in_section = ''; | ||||||
|  |             $ignore_lines = 1; | ||||||
|  |         } | ||||||
|  |         if ($ignore_lines > 0) { | ||||||
|  |             $ignore_lines--; | ||||||
|             next; |             next; | ||||||
|         } |         } | ||||||
|         next if $in_ignore_section; | 
 | ||||||
|         next if /#.*:squash-ignore-line:$/; |         if ($in_section eq 'ignore') { | ||||||
|  |             $code .= $_; | ||||||
|  |             next; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (/#.*:squash-remove-start:$/) { | ||||||
|  |             $in_section = 'remove'; | ||||||
|  |             next; | ||||||
|  |         } elsif (/#.*:squash-remove-end:$/) { | ||||||
|  |             $in_section = ''; | ||||||
|  |             next; | ||||||
|  |         } | ||||||
|  |         next if $in_section eq 'remove'; | ||||||
|  |         next if /#.*:squash-remove-line:$/; | ||||||
| 
 | 
 | ||||||
|         next if /^\s*1;$/; |         next if /^\s*1;$/; | ||||||
| 
 | 
 | ||||||
|  | @ -49,6 +67,10 @@ for my $arg (@ARGV) { | ||||||
|         s{\s*##.+critic.*}{}; |         s{\s*##.+critic.*}{}; | ||||||
|         $code .= $_; |         $code .= $_; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     # Warn if there were unterminated :squash-*: sections | ||||||
|  |     warn "$filename: Unterminated :squash-$in_section-start: section" if $in_section; | ||||||
|  | 
 | ||||||
|     close $fh; |     close $fh; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue