summaryrefslogtreecommitdiff
path: root/perl5
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-03-23 10:50:40 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-03-23 12:02:03 -0700
commit38719ce6dee40964aa4056c4b11073eb895831e9 (patch)
tree82ea17a1d7fe31fd6bf61dbf718684b20cdc8648 /perl5
parent174e546a1e9572e760834d87a4dc68b6547838d1 (diff)
downloaddotfiles-38719ce6dee40964aa4056c4b11073eb895831e9.tar.gz
locmaint: build and use a hash of Debian source trees under ~/src
Also, look at other branches to find the source package name. This deals with repos where the toplevel dir is not the source package name and where the master branch doesn't have debian/, such as my ~/src/p5-* repos.
Diffstat (limited to 'perl5')
-rw-r--r--perl5/Local/Homedir.pm64
1 files changed, 46 insertions, 18 deletions
diff --git a/perl5/Local/Homedir.pm b/perl5/Local/Homedir.pm
index 148c6e17..9959cb76 100644
--- a/perl5/Local/Homedir.pm
+++ b/perl5/Local/Homedir.pm
@@ -29,9 +29,12 @@ use Cwd;
use File::Find;
use File::Spec::Functions;
use Exporter 'import';
+use File::Temp qw(tempfile);
our @EXPORT = qw( normalise_mrconfig src_register_all src_cleanup );
+our %debian_source_repos;
+
sub normalise_mrconfig {
my $master = $ENV{HOME} . "/src/dotfiles/.mrconfig.in";
my $target = $ENV{HOME} . "/.mrconfig";
@@ -121,26 +124,51 @@ sub src_register_all {
sub src_cleanup {
return unless eval "use Dpkg::Changelog::Parse; use Dpkg::Version; 1";
- my @debian_source_repos;
- find({wanted => sub {
- my $dir = $_;
- my $ch = catfile($dir, "debian", "changelog");
- return unless -f $ch;
- my $changelog_entry = changelog_parse(file => $ch);
- push @debian_source_repos,
- {source => $changelog_entry->{source},
- dir => catfile(getcwd(), $dir)};
- }, preprocess => sub {
- # once we've found a source package, don't search inside
- # for more source packages
- return (-f catfile("debian", "changelog")) ? () : @_;
- }}, "$ENV{HOME}/src");
- foreach my $debian_source_repo (@debian_source_repos) {
+ find({
+ wanted => sub {
+ my $dir = $_;
+ my $ch = catfile($dir, "debian", "changelog");
+
+ # if no changelog on the current branch, see if there is
+ # one on another relevant branch (this covers ~/src/p5-*)
+ unless (-f $ch) {
+ return unless is_repo($dir);
+ my @branches
+ = grep
+ m#^refs/(?:heads/debian$|(?:heads|remotes/dgit)/dgit/)#,
+`git -C $dir for-each-ref --format='%(refname)' refs/heads/ refs/remotes/dgit/`;
+ chomp @branches;
+ my $branch;
+ for (@branches) {
+ $branch = $_, last
+ if grep m#debian/changelog#,
+ `git -C $dir ls-tree $_ debian/changelog`;
+ }
+ return unless $branch;
+ (my $fh, $ch) = tempfile UNLINK => 1;
+ open my $ph, "-|", "git", "-C", $dir, "cat-file", "blob",
+ "$branch:debian/changelog";
+ print $fh $_ for <$ph>;
+ close $fh;
+ }
+
+ my $changelog_entry = changelog_parse(file => $ch);
+ $debian_source_repos{ $changelog_entry->{source} }
+ = catfile getcwd, $dir;
+ },
+ preprocess => sub {
+ # once we've found a source package, don't search inside
+ # for more source packages
+ return (-f catfile("debian", "changelog")) ? () : @_;
+ }
+ },
+ "$ENV{HOME}/src"
+ );
+ while (my ($source, $dir) = each %debian_source_repos) {
# binary package names may not be source package names, so
# have to handle those separately
- unlink glob catfile($debian_source_repo->{dir}, "..", "*.deb");
- my $prefix = catfile($debian_source_repo->{dir}, "..",
- $debian_source_repo->{source} . "_");
+ unlink glob catfile $dir, "..", "*.deb";
+ my $prefix = catfile $dir, "..", $source . "_";
unlink glob $prefix . "*" . $_
for ".dsc", ".diff.gz", ".upload", ".inmulti", ".changes",
".build", ".buildinfo", ".debian.tar.*", "[0-9~].tar.*";