[devscripts] 02/02: mk-origtargz: Warn about unmatched Files-Excluded patterns

James McCoy jamessan at debian.org
Thu Oct 30 03:46:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch master
in repository devscripts.

commit 2d6a8bb3e2f9723f87d02eecf12deafd6035b6e3
Author: James McCoy <jamessan at debian.org>
Date:   Wed Oct 29 23:43:38 2014 -0400

    mk-origtargz: Warn about unmatched Files-Excluded patterns
    
    Closes: #766641
    Signed-off-by: James McCoy <jamessan at debian.org>
---
 debian/changelog        |  2 ++
 scripts/mk-origtargz.pl | 25 ++++++++++++++++++-------
 test/test_mk-origtargz  | 24 ++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index bbee55a..8f8ce7f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,8 @@ devscripts (2.14.11) UNRELEASED; urgency=medium
   [ James McCoy ]
   * debcommit: Correctly show --strip-message is the default in --help.
     (Closes: #766885)
+  * mk-origtargz: Warn about unmatched Files-Excluded patterns.  (Closes:
+    #766641)
 
  -- Paul Wise <pabs at debian.org>  Sun, 19 Oct 2014 17:27:24 +0800
 
diff --git a/scripts/mk-origtargz.pl b/scripts/mk-origtargz.pl
index 6419900..1723135 100755
--- a/scripts/mk-origtargz.pl
+++ b/scripts/mk-origtargz.pl
@@ -420,13 +420,22 @@ if (@exclude_globs) {
     chomp @files;
 
     # find out what to delete
-    my @exclude_regexes = map { glob_to_regex($_) } @exclude_globs;
-    my $regex = '^(?:[^/]*/)?' # Possible leading directory, ignore it
-	      . '(?:' . join('|', @exclude_regexes) . ')' # User patterns
-	      . '(?:/.*)?$'; # Possible trailing / for a directory
+    my @exclude_info = map { { glob => $_, used => 0, regex => glob_to_regex($_) } } @exclude_globs;
     for my $filename (@files) {
-	if ($filename =~ m/$regex/) {
-	    push @to_delete, $filename;
+	for my $info (@exclude_info) {
+	    if ($filename =~ m@^(?:[^/]*/)?        # Possible leading directory, ignore it
+				(?:$info->{regex}) # User pattern
+				(?:/.*)?$          # Possible trailing / for a directory
+			      @x) {
+		push @to_delete, $filename;
+		$info->{used} = 1;
+	    }
+	}
+    }
+
+    for my $info (@exclude_info) {
+	if (!$info->{used}) {
+	    warn "No files matched excluded pattern: $info->{glob}\n";
 	}
     }
 
@@ -559,7 +568,9 @@ sub glob_to_regex {
     for my $c ($glob =~ m/(.)/gs) {
 	if ($c eq '.' || $c eq '(' || $c eq ')' || $c eq '|' ||
 	    $c eq '+' || $c eq '^' || $c eq '$' || $c eq '@' || $c eq '%' ||
-	    $c eq '{' || $c eq '}' || $c eq '[' || $c eq ']') {
+	    $c eq '{' || $c eq '}' || $c eq '[' || $c eq ']' ||
+	    # Escape '#' since we're using /x in the pattern match
+	    $c eq '#') {
 	    $regex .= "\\$c";
 	}
 	elsif ($c eq '*') {
diff --git a/test/test_mk-origtargz b/test/test_mk-origtargz
index 1bf4083..ad5a729 100755
--- a/test/test_mk-origtargz
+++ b/test/test_mk-origtargz
@@ -134,6 +134,18 @@ END
 
 }
 
+makeUnmatchedExcludeCopyright() {
+	cat <<'END' > $TMPDIR/foo/debian/copyright
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Files-Excluded: exclude-this*
+ .exclude-this*
+ exclude-dir1
+ exclude-dir2
+ ;?echo?strange-file;?#
+ nomatch
+END
+}
+
 expected_stderr_after_removal="WARNING: Files-Excluded pattern (exclude-dir2/) should not have a trailing /"
 
 expected_files_after_removal=$(sort <<END
@@ -516,4 +528,16 @@ $PROGNAME: error: tar --list --auto-compress --file ../foo_0.1.orig.tar.xz gave
 		 ../foo-0.1.tar.gz --repack --compression xz
 }
 
+testUnmatchedExclusion() {
+	makeTarBall gz
+	makeDebianDir
+	makeUnmatchedExcludeCopyright
+	run_mk_origtargz foo "No files matched excluded pattern: nomatch" \
+		"Successfully repacked ../foo-0.1.tar.gz as ../foo_0.1.orig.tar.gz, deleting 19 files from it." \
+		 ../foo-0.1.tar.gz
+	assertTrue "result does not exist" "[ -e $TMPDIR/foo_0.1.orig.tar.gz ]"
+	assertType application/gzip $TMPDIR/foo_0.1.orig.tar.gz
+	assertEquals "file contents" "$expected_files_after_removal" "$(tar taf $TMPDIR/foo_0.1.orig.tar.gz | sort)"
+}
+
 . shunit2

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/devscripts.git



More information about the devscripts-devel mailing list