chiark / gitweb /
Quilt output: Honour and strip Gbp-pq headers
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 9 Oct 2016 00:12:37 +0000 (01:12 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 10 Oct 2016 00:01:10 +0000 (01:01 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/changelog
dgit

index 61b7765bb7a6edd32c01daae8e1aa8e0b4e9f46c..e97cb3c1a644eb88b7e908bfe97a49a82ae5fbaf 100644 (file)
@@ -31,6 +31,8 @@ dgit (1.5~~) unstable; urgency=medium
   * When generating quilt patches from git commits, make patches that
     look quite like git-format-patch output (rather than strange things
     based on an obselete interpretation of DEP-3).
+  * When generating quilt patches from git commits, honour (and strip)
+    any Gbp-Pq headers (that we understand).
   * Several dgit-generated commits now have slightly better annotations
     from dgit about what it was doing.
 
diff --git a/dgit b/dgit
index 8d13d15a4e305238bea9b621cc39f8e0bf809c08..50011cce1bde6c9ea94ce28dd0530a99db2b09f3 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -3990,12 +3990,56 @@ sub quiltify ($$$$) {
        $strip_nls->();
 
        my $title = $1;
-       my $patchname = $title;
-       $patchname =~ s/[.:]$//;
-       $patchname =~ y/ A-Z/-a-z/;
-       $patchname =~ y/-a-z0-9_.+=~//cd;
-       $patchname =~ s/^\W/x-$&/;
-       $patchname = substr($patchname,0,40);
+       my $patchname;
+       my $patchdir;
+
+       my $gbp_check_suitable = sub {
+           $_ = shift;
+           my ($what) = @_;
+
+           eval {
+               die "contains unexpected slashes\n" if m{//} || m{/$};
+               die "contains leading punctuation\n" if m{^\W} || m{/\W};
+               die "contains bad character(s)\n" if m{[^-a-z0-9_.+=~/]}i;
+               die "too long" if length > 200;
+           };
+           return $_ unless $@;
+           print STDERR "quiltifying commit $cc:".
+               " ignoring/dropping Gbp-Pq $what: $@";
+           return undef;
+       };
+
+       if ($msg =~ s/^ (?: gbp(?:-pq)? : \s* name \s+ |
+                          gbp-pq-name: \s* )
+                      (\S+) \s* \n //ixm) {
+           $patchname = $gbp_check_suitable->($1, 'Name');
+       }
+       if ($msg =~ s/^ (?: gbp(?:-pq)? : \s* topic \s+ |
+                          gbp-pq-topic: \s* )
+                      (\S+) \s* \n //ixm) {
+           $patchdir = $gbp_check_suitable->($1, 'Topic');
+       }
+
+       $strip_nls->();
+
+       if (!defined $patchname) {
+           $patchname = $title;
+           $patchname =~ s/[.:]$//;
+           $patchname =~ y/ A-Z/-a-z/;
+           $patchname =~ y/-a-z0-9_.+=~//cd;
+           $patchname =~ s/^\W/x-$&/;
+           $patchname = substr($patchname,0,40);
+       }
+       if (!defined $patchdir) {
+           $patchdir = '';
+       }
+       if (length $patchdir) {
+           $patchname = "$patchdir/$patchname";
+       }
+       if ($patchname =~ m{^(.*)/}) {
+           mkpath "debian/patches/$1";
+       }
+
        my $index;
        for ($index='';
             stat "debian/patches/$patchname$index";