diff options
author | Raphaël Hertzog <hertzog@debian.org> | 2010-06-10 16:20:41 +0200 |
---|---|---|
committer | Raphaël Hertzog <hertzog@debian.org> | 2010-06-10 17:10:00 +0200 |
commit | 2b204533b8a2a95ca0d3796978368f9fd3d82b9c (patch) | |
tree | 5bd3de801792a703af514cf4adca93856e90c813 /scripts/Dpkg | |
parent | 9278ba135233d63d7f0869cbd6ea8df0800987f3 (diff) | |
download | dpkg-2b204533b8a2a95ca0d3796978368f9fd3d82b9c.tar.gz |
dpkg-source: new --unapply-patches option
This option is used by source formats 2.0 and 3.0 (quilt) to unapply
patches after a successful build. It's useful for people who manage their
packages in a VCS repository and prefer to have patches unapplied, even
after a package build.
Given that this option is a matter of personal taste, do not allow it
in debian/source/options so that the resulting source package cannot
have this behaviour by default and so that all source packages behave
in a consistent way: patches applied by default is a major feature
of the new formats.
Diffstat (limited to 'scripts/Dpkg')
-rw-r--r-- | scripts/Dpkg/Source/Package/V2.pm | 27 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Package/V3/quilt.pm | 23 |
2 files changed, 50 insertions, 0 deletions
diff --git a/scripts/Dpkg/Source/Package/V2.pm b/scripts/Dpkg/Source/Package/V2.pm index 787d6acd6..3c7082121 100644 --- a/scripts/Dpkg/Source/Package/V2.pm +++ b/scripts/Dpkg/Source/Package/V2.pm @@ -53,6 +53,8 @@ sub init_options { unless exists $self->{'options'}{'preparation'}; $self->{'options'}{'skip_patches'} = 0 unless exists $self->{'options'}{'skip_patches'}; + $self->{'options'}{'unapply_patches'} = 0 + unless exists $self->{'options'}{'unapply_patches'}; $self->{'options'}{'skip_debianization'} = 0 unless exists $self->{'options'}{'skip_debianization'}; $self->{'options'}{'create_empty_orig'} = 0 @@ -76,6 +78,9 @@ sub parse_cmdline_option { } elsif ($opt =~ /^--skip-patches$/) { $self->{'options'}{'skip_patches'} = 1; return 1; + } elsif ($opt =~ /^--unapply-patches$/) { + $self->{'options'}{'unapply_patches'} = 1; + return 1; } elsif ($opt =~ /^--skip-debianization$/) { $self->{'options'}{'skip_debianization'} = 1; return 1; @@ -206,6 +211,23 @@ sub apply_patches { close(APPLIED); } +sub unapply_patches { + my ($self, $dir, %opts) = @_; + my @patches = reverse($self->get_patches($dir, %opts)); + return unless scalar(@patches); + my $timestamp = time(); + my $applied = File::Spec->catfile($dir, "debian", "patches", ".dpkg-source-applied"); + foreach my $patch (@patches) { + my $path = File::Spec->catfile($dir, "debian", "patches", $patch); + info(_g("unapplying %s"), $patch) unless $opts{"quiet"}; + my $patch_obj = Dpkg::Source::Patch->new(filename => $path); + $patch_obj->apply($dir, force_timestamp => 1, + timestamp => $timestamp, + add_options => [ '-E', '-R' ]); + } + unlink($applied); +} + sub can_build { my ($self, $dir) = @_; return 1 if $self->find_original_tarballs(include_supplementary => 0); @@ -219,6 +241,11 @@ sub before_build { $self->check_patches_applied($dir) if $self->{'options'}{'preparation'}; } +sub after_build { + my ($self, $dir) = @_; + $self->unapply_patches($dir) if $self->{'options'}{'unapply_patches'}; +} + sub prepare_build { my ($self, $dir) = @_; $self->{'diff_options'} = { diff --git a/scripts/Dpkg/Source/Package/V3/quilt.pm b/scripts/Dpkg/Source/Package/V3/quilt.pm index bb9030005..ad352d32e 100644 --- a/scripts/Dpkg/Source/Package/V3/quilt.pm +++ b/scripts/Dpkg/Source/Package/V3/quilt.pm @@ -227,6 +227,29 @@ sub apply_patches { close(APPLIED); } +sub unapply_patches { + my ($self, $dir, %opts) = @_; + + $opts{'verbose'} = 1 unless defined $opts{'verbose'}; + + my $pc_applied = File::Spec->catfile($dir, ".pc", "applied-patches"); + my @applied = $self->read_patch_list($pc_applied); + $opts{"timestamp"} = time(); + foreach my $patch (reverse @applied) { + my $path = File::Spec->catfile($dir, "debian", "patches", $patch); + my $obj = Dpkg::Source::Patch->new(filename => $path); + + info(_g("unapplying %s"), $patch) if $opts{"verbose"}; + $obj->apply($dir, timestamp => $opts{"timestamp"}, + force_timestamp => 1, remove_backup => 0, + options => [ '-R', '-s', '-t', '-N', '-p1', + '-u', '-V', 'never', '-g0', '-E', + '--no-backup-if-mismatch' ]); + erasedir(File::Spec->catdir($dir, ".pc", $patch)); + } + unlink($pc_applied); +} + sub prepare_build { my ($self, $dir) = @_; $self->SUPER::prepare_build($dir); |