From 582c66c37b6519604a15b284e6db4c5003a37e05 Mon Sep 17 00:00:00 2001 From: Michael Pyne Date: Sat, 24 Nov 2012 22:38:42 -0500 Subject: [PATCH] modularize: Move BzrUpdate to separate file (Updater::Bzr). Only one module I know of uses this, it seemed to work fine in testing. --- kdesrc-build | 100 ++----------------------------------- modules/ksb/Updater/Bzr.pm | 94 ++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 96 deletions(-) create mode 100644 modules/ksb/Updater/Bzr.pm diff --git a/kdesrc-build b/kdesrc-build index 6a8f1b3..1f94b25 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -56,6 +56,7 @@ use Sys::Hostname; use Storable 'dclone'; use IO::Handle; use Data::Dumper; + use ksb::IPC; use ksb::Debug; use ksb::Util; @@ -979,100 +980,6 @@ EOM } # }}} -# package BzrUpdate {{{ -# Support the bazaar source control manager for libdbusmenu-qt -{ - package BzrUpdate; - - use ksb::Debug; - use ksb::Util; - use ksb::Updater; - - # Our superclass - our @ISA = qw(ksb::Updater); - - # scm-specific update procedure. - # May change the current directory as necessary. - # Should return a count of files changed (or commits, or something similar) - sub updateInternal - { - my $self = assert_isa(shift, 'BzrUpdate'); - my $module = assert_isa($self->module(), 'Module'); - - # Full path to source directory on-disk. - my $srcdir = $module->fullpath('source'); - my $bzrRepoName = $module->getOption('repository'); - - # Or whatever regex is appropriate to strip the bzr URI protocol. - $bzrRepoName =~ s/^bzr:\/\///; - - if (! -e "$srcdir/.bzr") { - # Cmdline assumes bzr will create the $srcdir directory and then - # check the source out into that directory. - my @cmd = ('bzr', 'branch', $bzrRepoName, $srcdir); - - # Exceptions are used for failure conditions - if (log_command($module, 'bzr-branch', \@cmd) != 0) { - die make_exception('Internal', "Unable to checkout $module!"); - } - - # TODO: Filtering the output by passing a subroutine to log_command - # should give us the number of revisions, or we can just somehow - # count files. - my $newRevisionCount = 0; - return $newRevisionCount; - } - else { - # Update existing checkout. The source is currently in $srcdir - p_chdir($srcdir); - - if (log_command($module, 'bzr-up', ['bzr', 'up']) != 0) { - die make_exception('Internal', "Unable to update $module!"); - } - - # I haven't looked at bzr up output yet to determine how to find - # number of affected files or number of revisions skipped. - my $changeCount = 0; - return $changeCount; - } - - return 0; - } - - sub name - { - return 'bzr'; - } - - # This is used to track things like the last successfully installed - # revision of a given module. - sub currentRevisionInternal - { - my $self = assert_isa(shift, 'BzrUpdate'); - my $module = $self->module(); - my $result; - - # filter_program_output can throw exceptions - eval { - p_chdir($module->fullpath('source')); - - ($result, undef) = filter_program_output(undef, 'bzr', 'revno'); - chomp $result if $result; - }; - - if ($@) { - error ("Unable to run r[b[bzr], is bazaar installed?"); - error (" -- Error was: r[$@]"); - return undef; - } - - return $result; - } - - 1; -} -# }}} - # package SvnUpdate {{{ { package SvnUpdate; @@ -2818,6 +2725,7 @@ EOF use ksb::Debug; use ksb::Util; use ksb::Updater::Git; + use ksb::Updater::Bzr; use Storable 'dclone'; use Carp 'confess'; @@ -2977,7 +2885,7 @@ EOF # Overload repository to allow bzr URLs? if ($repository =~ /^bzr:\/\//) { - $self->{scm_obj} = BzrUpdate->new($self); + $self->{scm_obj} = ksb::Updater::Bzr->new($self); } # If it needs a repo it's git. Everything else is svn for now. @@ -3001,7 +2909,7 @@ EOF when('metadata') { $newType = KDEProjectMetadataUpdate->new($self); } when('l10n') { $newType = l10nSystem->new($self); } when('svn') { $newType = SvnUpdate->new($self); } - when('bzr') { $newType = BzrUpdate->new($self); } + when('bzr') { $newType = ksb::Updater::Bzr->new($self); } default { $newType = undef; } } diff --git a/modules/ksb/Updater/Bzr.pm b/modules/ksb/Updater/Bzr.pm new file mode 100644 index 0000000..73c92d7 --- /dev/null +++ b/modules/ksb/Updater/Bzr.pm @@ -0,0 +1,94 @@ +package ksb::Updater::Bzr; + +# Support the bazaar source control manager for libdbusmenu-qt + +use strict; +use warnings; +use v5.10; + +use ksb::Debug; +use ksb::Util; +use ksb::Updater; + +# Our superclass +our @ISA = qw(ksb::Updater); + +# scm-specific update procedure. +# May change the current directory as necessary. +# Should return a count of files changed (or commits, or something similar) +sub updateInternal +{ + my $self = assert_isa(shift, 'ksb::Updater::Bzr'); + my $module = assert_isa($self->module(), 'Module'); + + # Full path to source directory on-disk. + my $srcdir = $module->fullpath('source'); + my $bzrRepoName = $module->getOption('repository'); + + # Or whatever regex is appropriate to strip the bzr URI protocol. + $bzrRepoName =~ s/^bzr:\/\///; + + if (! -e "$srcdir/.bzr") { + # Cmdline assumes bzr will create the $srcdir directory and then + # check the source out into that directory. + my @cmd = ('bzr', 'branch', $bzrRepoName, $srcdir); + + # Exceptions are used for failure conditions + if (log_command($module, 'bzr-branch', \@cmd) != 0) { + die make_exception('Internal', "Unable to checkout $module!"); + } + + # TODO: Filtering the output by passing a subroutine to log_command + # should give us the number of revisions, or we can just somehow + # count files. + my $newRevisionCount = 0; + return $newRevisionCount; + } + else { + # Update existing checkout. The source is currently in $srcdir + p_chdir($srcdir); + + if (log_command($module, 'bzr-up', ['bzr', 'up']) != 0) { + die make_exception('Internal', "Unable to update $module!"); + } + + # I haven't looked at bzr up output yet to determine how to find + # number of affected files or number of revisions skipped. + my $changeCount = 0; + return $changeCount; + } + + return 0; +} + +sub name +{ + return 'bzr'; +} + +# This is used to track things like the last successfully installed +# revision of a given module. +sub currentRevisionInternal +{ + my $self = assert_isa(shift, 'ksb::Updater::Bzr'); + my $module = $self->module(); + my $result; + + # filter_program_output can throw exceptions + eval { + p_chdir($module->fullpath('source')); + + ($result, undef) = filter_program_output(undef, 'bzr', 'revno'); + chomp $result if $result; + }; + + if ($@) { + error ("Unable to run r[b[bzr], is bazaar installed?"); + error (" -- Error was: r[$@]"); + return undef; + } + + return $result; +} + +1;