From 88701150ea41b1f89b2381c95cd035c36a0118e5 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Mon, 6 Mar 2023 07:11:58 +0100 Subject: [PATCH] remove gitpan and Git::CPAN::Patch::Import The gitpan script does not get installed. It serves essentially no purpose in the shipped tarball. Git::CPAN::Patch::Import exists only for the gitpan script, so it is similarly useless. It shares no code with the rest of the dist, so there is no reason to ship them together. It adds several additional prereqs that serve no purpose to the installed code. One of the prereqs, BackPAN::Index, is broken on many machines and is unmaintained. Preserving gitpan is best done as a separate dist. --- MANIFEST | 1 - contrib/gitpan | 386 ------------------- cpanfile | 13 - lib/Git/CPAN/Patch/Command/Import.pm | 1 - lib/Git/CPAN/Patch/Import.pm | 540 --------------------------- project.vim | 1 - t/00-load.t | 1 - 7 files changed, 943 deletions(-) delete mode 100644 contrib/gitpan delete mode 100644 lib/Git/CPAN/Patch/Import.pm diff --git a/MANIFEST b/MANIFEST index d6e0e3a..e870445 100644 --- a/MANIFEST +++ b/MANIFEST @@ -25,7 +25,6 @@ lib/Git/CPAN/Patch/Command/Sources.pm lib/Git/CPAN/Patch/Command/Squash.pm lib/Git/CPAN/Patch/Command/Update.pm lib/Git/CPAN/Patch/Command/Which.pm -lib/Git/CPAN/Patch/Import.pm lib/Git/CPAN/Patch/Release.pm lib/Git/CPAN/Patch/Role/Git.pm lib/Git/CPAN/Patch/Role/Patch.pm diff --git a/contrib/gitpan b/contrib/gitpan deleted file mode 100644 index 5cf279d..0000000 --- a/contrib/gitpan +++ /dev/null @@ -1,386 +0,0 @@ -#!/usr/bin/perl - -# Do a complete git-ificaiton of BackPAN. Or give it just a few modules. - -use strict; -use warnings; -use v5.10; - -use Git::CPAN::Patch::Import; -use File::chdir; -use Getopt::Long; - -# Github currently limits repo names to 100 characters -use constant MAX_LENGTH_GITHUB_REPO_NAME => 100; - -my %Dists_To_Skip = map { $_ => 1 } qw( - perl - parrot - parrot-cfg -); - -# Defaults -my %opts = ( - update => 1, -); -GetOptions( - \%opts, - "backpan:s", - "login=s", - "token=s", - "author=s", - "github!", - "random=i", - "pattern=s", - "sort!", - "repodir=s", - "tempdir=s", - "update", - "since=s" -); - -my @dists; -if( @ARGV ) { - @dists = @ARGV; -} -else { - my $backpan = Git::CPAN::Patch::Import->backpan_index; - - my $dists = $backpan->dists; - - if( $opts{since} ) { - $dists = $dists->search( latest_date => \">= $opts{since}" ); - } - - if( $opts{random} ) { - my $num = $opts{random}; - - $dists = $dists->search( undef, { order_by => \'random()', rows => $num } ); - } - elsif( $opts{sort} ) { - $dists = $dists->search( undef, { order_by => 'name' } ); - } - - if( $opts{author} ) { - $dists = $dists->search({ "releases.cpanid" => $opts{author} }, - { join => "releases", distinct => 1 }); - } - - @dists = $dists->all; - - if( $opts{pattern} ) { - @dists = grep /$opts{pattern}/, @dists; - } -} - - -@dists = filter_dists(@dists); - -@dists = sort { lc $a cmp lc $b } @dists if $opts{sort}; - -my %backpan_init_opts; -$backpan_init_opts{"backpan"} = [split /,/, $opts{backpan}] if $opts{backpan}; -$backpan_init_opts{"tempdir"} = $opts{tempdir} if $opts{tempdir}; -$backpan_init_opts{"update"} = $opts{update}; - -say "Looking at @{[ scalar @dists ]} dists"; - -local $CWD = $opts{repodir} if defined $opts{repodir}; -for my $dist (@dists) { - next if $Dists_To_Skip{$dist}; - - # MARCEL has -0.01.tar.gz - # Should probably be filtered out by Parse::BACKPAN or - # made into a dist called empty string. - next if $dist =~ /^-[\d.]+$/; - - if( $opts{github} ) { - if( !$opts{update} and does_repo_exist("gitpan", $dist) ) { - print "$dist already exists on github, skipping\n"; - next; - } - } - - my $repo_dir = Git::CPAN::Patch::Import::import_from_backpan( - $dist, - { %backpan_init_opts, "mkdir" => "", init_repo => 1 } - ); - - unless( $repo_dir) { - say "No repository created for $dist. Skipping"; - next; - } - - local $CWD = $repo_dir; - - system "rm .git/hooks/*.sample"; - system "git", "gc"; - - if( $opts{github} ) { - my $repo = "$dist"; - if( !$opts{update} or !does_repo_exist_on_github($opts{login}, $dist) ) { - my $response = github_action("create_repo", { - login => $opts{login}, - token => $opts{token}, - name => $dist, - description => "Release history of $dist", - homepage => "http://search.cpan.org/dist/$dist/", - public => 1, - }); - - $repo = $response->{repository}{name}; - } - - # Sometimes we re-clone from gitpan and so the origin is wrong - system "git", "remote", "rm", "origin"; - system "git", "remote", "add", "origin", "git\@github-gitpan:gitpan/$repo.git"; - - # sometimes github doesn't have the repo ready immediately after create_repo - # returns, so if push fails try it again. - do_with_back_off(6, sub { - system "git", "push", "origin", "master"; - return $? == 0; - }); - system "git", "push", "origin", "--tags"; - } - - # Delete everything but the .git/ directory to save space - # We name the directory specifically to avoid accidentally - # deleting everything should we be in the wrong cwd - system "rm -rf $repo_dir/*"; -} - - -use LWP::UserAgent; -use HTTP::Request::Common qw(POST); -use JSON::XS; - -sub _do_github_action { - state $ua = LWP::UserAgent->new; - - state $actions = { - create_repo => sub { 'repos/create' }, - delete_repo => sub { 'repos/delete' }, - repo_info => sub { - my $opts = shift; - sprintf 'repos/show/%s/%s', - $opts->{user}, - $opts->{name} - }, - }; - - my $action = shift; - my $opts = shift; - - my $url = "http://github.com/api/v2/json/"; - $url .= $actions->{$action}->($opts); - - my $req = POST $url, [ - %$opts - ]; - - # Sometimes github gets confused but sorts it out quickly - my $response = do_with_back_off(4, sub { - my $response = $ua->request($req); - return if $response->code == 500; - return $response; - }); - - my $content = $response->content; - print "Github said: $content\n"; - - return decode_json($content); -} - - -sub github_action { - my @args = @_; - - my $response = do_with_back_off(6, sub { - my $response = _do_github_action(@args); - - return if is_too_many_requests($response); - return $response; - }); - - return $response; -} - - -sub is_too_many_requests { - my $response = shift; - return $response->{error} && ($response->{error}[0]{error} =~ /too many requests/); -} - - -sub does_repo_exist { - my $user = shift; - my $repo = shift; - - # This is far faster than asking github about every one - return 1 if -e "$repo/.git/refs/remotes/origin/"; - - return does_repo_exist_on_github($user, $repo); -} - -sub does_repo_exist_on_github { - my $user = shift; - my $repo = shift; - - my $response = github_action("repo_info", { - user => $user, - name => $repo - }); - return 0 if $response->{error}; - return 1; -} - - -sub filter_dists { - # filter out garbage the BackPAN index picks up - return grep !/^[\d._\-]+(\.U)?$/, - # filter out dists too long to go into github, rather - # than put them in with the wrong name. I have a ticket - # in with github to increase the max - grep { length $_ <= MAX_LENGTH_GITHUB_REPO_NAME } - @_; -} - - -sub do_with_back_off { - my($number, $code) = @_; - - my $ret; - for my $backoff (1..$number) { - $ret = $code->(); - last if $ret; - - sleep 2**$backoff; - } - - die "Command failed after $number back off and retries" unless $ret; - return $ret; -} - - -__END__ - -=head1 NAME - -gitpan - Import all of BackPAN to github - -=head1 SYNOPSIS - - gitpan [options] [dist] [dist] ... - -=head1 DESCRIPTION - -gitpan is a script to import large chunks (or all of) BackPAN into git -and github. It allows you to select BackPAN distributions to import -and control importing to github. - -=head1 OPTIONS - -=head2 Distribution Selection - -By default, gitpan will import every distribution on BackPAN. You can -override this by passing it a list of distributions on the command -line or the following. - -=head3 --author - -Import all the options of a particular author. Give it their CPAN id. -For example - - gitpan --author=MSCHWERN - -=head3 --random - -Pick N random distributions. - - gitpan --random=100 - -=head3 --pattern - -Pick all distributions matching the given pattern. - - # Import all the D's. - gitpan --pattern='^[Dd]' - -=head3 --sort - -Sort the distributions before processing - -=head3 --since - -Pick only distributions which have changed since the given time. - -Time is given in Unix epoch time. - - gitpan --since=1200000000 - - -=head2 Github - -=head3 --github - -If this option is passed, it will create a repository on github and -push the repo. - -=head3 --login - -Your github login name, only necessary if --github is set. - -=head3 --token - -Your github API token, only necessary if --github is set. - - -=head2 BackPAN - -=head3 --backpan - -A comma seperated list of URLs to BackPAN. Handy to have a URL to a -local mirror for fast retrieval and one to a remote mirror for -completeness. - -For example - - --backpan=file:///var/local/backpan,http://backpan.perl.org - -Defaults to http://backpan.perl.org/ - -=head2 Building - -=head3 --tempdir - -The temporary directory gitpan uses. - -Defaults to whatever L does. - -=head3 --repodir - -Where gitpan will look for and place local copies of the repositories. - -=head3 --update - -Whether or not to update existing repositories. - -Defaults to true. - - -=head1 EXAMPLE - -Here is how gitpan does its importing. - - gitpan --github --login=gitpan --token=wouldntyoulikeotknow \ - --backpan=file:///var/local/backpan \ - --tempdir=$PWD/gitpan-build/temp --repodir=$PWD/gitpan-build/repos \ - --pattern='^[Ff]' --sort - -That says to use file:///var/local/backpan as the BackPAN mirror (a -local repo), build in gitpan-build/ (a case-sensitive disk image), -create repositories on gitpan's account on github, and import all the -distributions starting with "F" or "f" in order. - -=cut diff --git a/cpanfile b/cpanfile index 1400d04..df93913 100644 --- a/cpanfile +++ b/cpanfile @@ -2,27 +2,15 @@ # Do not edit this file directly. To change prereqs, edit the `dist.ini` file. requires "Archive::Any" => "0"; -requires "Archive::Extract" => "0"; -requires "BackPAN::Index" => "0"; requires "CPAN::Meta" => "0"; requires "CPAN::ParseDistribution" => "0"; -requires "CPANPLUS" => "0"; -requires "Cwd" => "0"; -requires "DateTime" => "0"; -requires "File::Basename" => "0"; requires "File::Copy" => "0"; -requires "File::Find" => "0"; -requires "File::Path" => "0"; -requires "File::Spec::Functions" => "0"; requires "File::Temp" => "0"; requires "File::chdir" => "0"; -requires "File::chmod" => "0"; requires "Git::Repository" => "0"; requires "Git::Repository::Plugin::AUTOLOAD" => "0"; requires "HTTP::Tiny" => "0"; -requires "LWP::UserAgent" => "0"; requires "List::Pairwise" => "0"; -requires "MetaCPAN::API" => "0"; requires "MetaCPAN::Client" => "0"; requires "Moose" => "0"; requires "Moose::Role" => "0"; @@ -30,7 +18,6 @@ requires "MooseX::App" => "1.21"; requires "MooseX::App::Command" => "0"; requires "MooseX::App::Role" => "0"; requires "MooseX::SemiAffordanceAccessor" => "0"; -requires "Path::Class" => "0"; requires "Path::Tiny" => "0"; requires "Pod::Usage" => "0"; requires "autodie" => "0"; diff --git a/lib/Git/CPAN/Patch/Command/Import.pm b/lib/Git/CPAN/Patch/Command/Import.pm index b1dcb73..49ca176 100644 --- a/lib/Git/CPAN/Patch/Command/Import.pm +++ b/lib/Git/CPAN/Patch/Command/Import.pm @@ -6,7 +6,6 @@ use 5.20.0; use strict; use warnings; use Git::Repository; -use Git::CPAN::Patch::Import; use File::chdir; use Git::CPAN::Patch::Release; use Path::Tiny qw/ path /; diff --git a/lib/Git/CPAN/Patch/Import.pm b/lib/Git/CPAN/Patch/Import.pm deleted file mode 100644 index 802ed3b..0000000 --- a/lib/Git/CPAN/Patch/Import.pm +++ /dev/null @@ -1,540 +0,0 @@ -package Git::CPAN::Patch::Import; - -use 5.10.0; - -use strict; -use warnings; - -{ - no warnings; -use 5.010; - -use File::chmod (); # must be before 'autodie' to hush the warnings - -use autodie; - -use Archive::Extract; -$Archive::Extract::PREFER_BIN = 1; - -use File::Find; -use File::Basename; -use File::Spec::Functions; -use File::Temp qw(tempdir); -use File::Path; -use File::chdir; -use Path::Class qw/ file /; -use Cwd qw/ getcwd /; -use version; -use Git::Repository; -use DateTime; - -use CPANPLUS; -use BackPAN::Index; - -} - -our $BackPAN_URL = "http://backpan.perl.org/"; -our $PERL_GIT_URL = 'git://perl5.git.perl.org/perl.git'; - -sub backpan_index { - state $backpan = do { - say "Loading BackPAN index (this may take a while)"; - BackPAN::Index->new; - }; - return $backpan; -} - -sub cpanplus { - state $cpanplus = CPANPLUS::Backend->new; - return $cpanplus; -} - -# Make sure we can read tarballs and change directories -sub _fix_permissions { - my $dir = shift; - - File::chmod::chmod "u+rx", $dir; - find(sub { - -d $_ ? File::chmod::chmod "u+rx", $_ : File::chmod::chmod "u+r", $_; - }, $dir); -} - -sub init_repo { - my $module = shift; - my $opts = shift; - - my $dirname = "."; - if ( defined $opts->{mkdir} ) { - ( $dirname = $opts->{mkdir} || $module ) =~ s/::/-/g; - - if( -d $dirname ) { - die "$dirname already exists\n" unless $opts->{update}; - } - else { - say "creating directory $dirname"; - - # mkpath() does not play nice with overloaded objects - mkpath "$dirname"; - } - } - - { - local $CWD = $dirname; - - if ( -d '.git' ) { - if ( !$opts->{force} and !$opts->{update} ) { - die "Aborting: git repository already present.\n", - "use '--force' if it's really what you want to do\n"; - } - } - else { - Git::Repository->run('init'); - } - } - - return File::Spec->rel2abs($dirname); -} - - -sub releases_in_git { - my $repo = Git::Repository->new; - return unless contains_git_revisions(); - my @releases = map { m{\bgit-cpan-version:\s*(\S+)}x; $1 } - grep /^\s*git-cpan-version:/, - $repo->run(log => '--pretty=format:%b'); - return @releases; -} - - -sub rev_exists { - my $rev = shift; - my $repo = Git::Repository->new; - - return eval { $repo->run( 'rev-parse', $rev ); }; -} - - -sub contains_git_revisions { - return unless -d ".git"; - return rev_exists("HEAD"); -} - - -sub import_one_backpan_release { - my $release = shift; - my $opts = shift; - my $backpan_urls = $opts->{backpan} || $BackPAN_URL; - - # allow multiple backpan URLs to be supplied - $backpan_urls = [ $backpan_urls ] unless (ref($backpan_urls) eq 'ARRAY'); - - my $repo = Git::Repository->new; - - my( $last_commit, $last_version ); - - # figure out if there is already an imported module - if ( $last_commit = eval { $repo->run("rev-parse", "-q", "--verify", "cpan/master") } ) { - $last_version = $repo->run("cpan-last-version"); - } - - my $tmp_dir = File::Temp->newdir( - $opts->{tempdir} ? (DIR => $opts->{tempdir}) : () - ); - - my $archive_file = catfile($tmp_dir, $release->filename); - mkpath dirname $archive_file; - - my $response; - for my $backpan_url (@$backpan_urls) { - my $release_url = $backpan_url . "/" . $release->prefix; - - say "Downloading $release_url"; - $response = get_from_url($release_url, $archive_file); - last if $response->is_success; - - say " failed @{[ $response->status_line ]}"; - } - - if( !$response->is_success ) { - say "Fetch failed. Skipping."; - return; - } - - if( !-e $archive_file ) { - say "$archive_file is missing. Skipping."; - return; - } - - say "extracting distribution"; - my $ae = Archive::Extract->new( archive => $archive_file ); - unless( $ae->extract( to => $tmp_dir ) ) { - say "Couldn't extract $archive_file to $tmp_dir because ".$ae->error; - say "Skipping"; - return; - } - - my $dir = $ae->extract_path; - if( !$dir ) { - say "The archive is empty, skipping"; - return; - } - _fix_permissions($dir); - - my $tree = do { - # don't overwrite the user's index - local $ENV{GIT_INDEX_FILE} = catfile($tmp_dir, "temp_git_index"); - local $ENV{GIT_DIR} = catfile( getcwd(), '.git' ); - local $ENV{GIT_WORK_TREE} = $dir; - - local $CWD = $dir; - - my $write_tree_repo = Git::Repository->new( work_tree => $dir ) ; - - $write_tree_repo->run( qw(add -v --force .) ); - $write_tree_repo->run( "write-tree" ); - }; - - # Create a commit for the imported tree object and write it into - # refs/remotes/cpan/master - local %ENV = %ENV; - $ENV{GIT_AUTHOR_DATE} ||= $release->date; - - my $author = __PACKAGE__->cpanplus->author_tree($release->cpanid); - $ENV{GIT_AUTHOR_NAME} ||= $author->author; - $ENV{GIT_AUTHOR_EMAIL} ||= $author->email; - - my @parents = grep { $_ } $last_commit; - - - # commit message - my $name = $release->dist; - my $version = $release->version || ''; - my $message = join ' ', ( $last_version ? "import" : "initial import of"), "$name $version from CPAN\n"; - $message .= <<"END"; - -git-cpan-module: $name -git-cpan-version: $version -git-cpan-authorid: @{[ $author->cpanid ]} -git-cpan-file: @{[ $release->prefix ]} - -END - - my $commit = $repo->run( { input => $message }, 'commit-tree', $tree, - map { ( -p => $_ ) } @parents ); - - # finally, update the fake branch and create a tag for convenience - my $dist = $release->dist; - print $repo->run('update-ref', '-m' => "import $dist", 'refs/heads/cpan/master', $commit ); - - if( $version ) { - my $tag = $version; - $tag =~ s{^\.}{0.}; # git does not like a leading . as a tag name - $tag =~ s{\.$}{}; # nor a trailing one - if( $repo->run( "tag", "-l" => $tag ) ) { - say "Tag $tag already exists, overwriting"; - } - print $repo->run( "tag", "-f" => $tag, '--no-sign', $commit ); - say "created tag '$tag' ($commit)"; - } -} - - -sub get_from_url { - my($url, $file) = @_; - - require LWP::UserAgent; - my $ua = LWP::UserAgent->new; - - my $req = HTTP::Request->new( GET => $url ); - my $res = $ua->request($req, $file); - - return $res; -} - - -sub import_from_backpan { - my ( $distname, $opts ) = @_; - - $distname =~ s/::/-/g; - - # handle --mkdir and raise an error if the target directory has already been git-initialized - my $repo_dir = init_repo($distname, $opts); - - local $CWD = $repo_dir; - - my $backpan = __PACKAGE__->backpan_index; - my $dist = $backpan->dist($distname) - or die "Error: no distributions found. ", - "Are you sure you spelled the module name correctly?\n"; - - fixup_repository(); - - my %existing_releases; - %existing_releases = map { $_ => 1 } releases_in_git() if $opts->{update}; - my $release_added = 0; - for my $release ($dist->releases->search( undef, { order_by => "date" } )) { - next if $existing_releases{$release->version}; - - # skip .ppm files - next if $release->filename =~ m{\.ppm\b}; - - say "importing $release"; - import_one_backpan_release( - $release, - $opts, - ); - $release_added++; - } - - if( !$release_added ) { - if( !keys %existing_releases ) { - say "Empty repository for $dist. Deleting."; - - # We can't delete it if we're inside it. - $CWD = ".."; - rmtree $repo_dir; - - return; - } - else { - say "No updates for $dist."; - return; - } - } - - my $repo = Git::Repository->new; - if( !rev_exists("master") ) { - print $repo->run('checkout', '-t', '-b', 'master', 'cpan/master'); - } - else { - print $repo->run('checkout', 'master', '.'), - $repo->run('merge', 'cpan/master'); - } - - return $repo_dir; -} - - -sub fixup_repository { - my $repo = Git::Repository->new; - - return unless -d ".git"; - - # We do our work in cpan/master, it might not exist if this - # repo was cloned from gitpan. - if( !rev_exists("cpan/master") and rev_exists("master") ) { - print $repo->run('branch', '-t', 'cpan/master', 'master'); - } -} - -use MetaCPAN::API; -my $mcpan = MetaCPAN::API->new; - -sub find_release { - my $input = shift; - - return eval { $mcpan->release( - distribution => $mcpan->module($input)->{distribution} - ) } - || eval { $mcpan->release( distribution => $input ) } - || die "could not find release for '$input' on metacpan\n"; - -} - -sub main { - my $module = shift; - my $opts = shift; - - if ( delete $opts->{backpan} ) { - return import_from_backpan( $module, $opts ); - } - - my $repo = Git::Repository->new; - - my ( $last_commit, $last_version ); - - # figure out if there is already an imported module - if ( $last_commit = eval { $repo->run("rev-parse", "-q", "--verify", "cpan/master") } ) { - $module ||= $repo->run("cpan-which"); - $last_version = $repo->run("cpan-last-version"); - } - - die("Usage: git-cpan import Foo::Bar\n") unless $module; - - # first we figure out a module object from the module argument - - my $release = find_release($module); - - # based on the version number it figured out for us we decide whether or not to - # actually import. - - my $name = $release->{name}; - my $version = $release->{version}; - my $dist = $release->{distribution}; - - if ( $dist eq 'perl' ) { - say "$name is a core modules, ", - "clone perl from $PERL_GIT_URL instead."; - exit; - } - - my $prettyname = $dist . ( " ($module)" x ( $dist ne $module ) ); - - if ( $last_version and $opts->{checkversion} ) { - # if last_version is defined this is an update - my $imported = version->new($last_version); - my $will_import = version->new($release->{version}); - - die "$name has already been imported\n" if $imported == $will_import; - - die "imported version $imported is more recent than $will_import, can't import\n" - if $imported > $will_import; - - say "updating $prettyname from $imported to $will_import"; - - } else { - say "importing $prettyname"; - } - - require LWP::UserAgent; - - my $ua = LWP::UserAgent->new; - - # download the dist and extract into a temporary directory - my $tmp_dir = tempdir( CLEANUP => 0 ); - - say "downloading $dist"; - - my $tarball = file( $tmp_dir, $release->{archive} ); - - $ua->mirror( - $release->{download_url} => $tarball - ) or die "couldn't fetch tarball\n"; - - say "extracting distribution"; - - my $archive = Archive::Extract->new( archive => $tarball ); - $archive->extract( to => $tmp_dir ); - - my $dist_dir = $archive->extract_path - or die "extraction failed\n"; - - # create a tree object for the CPAN module - # this imports the source code without touching the user's working directory or - # index - - my $tree = do { - # don't overwrite the user's index - local $ENV{GIT_INDEX_FILE} = catfile($tmp_dir, "temp_git_index"); - local $ENV{GIT_DIR} = catfile( getcwd(), '.git' ); - local $ENV{GIT_WORK_TREE} = $dist_dir; - - local $CWD = $dist_dir; - - my $write_tree_repo = Git::Repository->new( work_tree => $dist_dir ); - - $write_tree_repo->run( qw(add -v --force .) ); - $write_tree_repo->run( "write-tree" ); - }; - - # create a commit for the imported tree object and write it into - # refs/heads/cpan/master - - { - local %ENV = %ENV; - - my $author_obj = $mcpan->author($release->{author}); - - # try to find a date for the version using the backpan index - # secondly, if the CPANPLUS author object is a fake one (e.g. when importing a - # URI), get the user object by using the ID from the backpan index - unless ( $ENV{GIT_AUTHOR_DATE} ) { - my $mtime = eval { - DateTime->from_epoch( epoch => $release->{stat}{mtime})->ymd; - }; - - warn $@ if $@; - - # CPAN::Checksums makes YYYY-MM-DD dates, but GIT_AUTHOR_DATE - # doesn't support that. - $mtime .= 'T00:00::00' - if $mtime =~ m/\A (\d\d\d\d) - (\d\d?) - (\d\d?) \z/x; - - if ( $mtime ) { - $ENV{GIT_AUTHOR_DATE} = $mtime; - } else { - my %dists; - - if ( $opts->{backpan} ) { - # we need the backpan index for dates - my $backpan = __PACKAGE__->backpan_index; - - %dists = map { $_->filename => $_ } - $backpan->releases($release->{name}); - } - - if ( my $bp_dist = $dists{$dist} ) { - - $ENV{GIT_AUTHOR_DATE} = $bp_dist->date; - - if ( $author_obj->isa("CPANPLUS::Module::Author::Fake") ) { - $author_obj = $mcpan->author_tree($bp_dist->cpanid); - } - } else { - say "Couldn't find upload date for $dist"; - - if ( $author_obj->isa("CPANPLUS::Module::Author::Fake") ) { - say "Couldn't find author for $dist"; - } - } - } - } - - # create the commit object - $ENV{GIT_AUTHOR_NAME} = $author_obj->{name} unless $ENV{GIT_AUTHOR_NAME}; - $ENV{GIT_AUTHOR_EMAIL} = $author_obj->{email}[0] unless $ENV{GIT_AUTHOR_EMAIL}; - - my @parents = ( grep { $_ } $last_commit, @{ $opts->{parent} || [] } ); - - my $message = join ' ', - ( $last_version ? "import" : "initial import of" ), - "$name $version from CPAN\n"; - $message .= <<"END"; - -git-cpan-module: $name -git-cpan-version: $version -git-cpan-authorid: @{[ $author_obj->{pauseid} ]} - -END - - my $commit = $repo->run( - { input => $message }, - 'commit-tree', $tree, map { ( -p => $_ ) } @parents ); - - # finally, update the fake remote branch and create a tag for convenience - - print $repo->run('update-ref', '-m' => "import $dist", 'refs/remotes/cpan/master', $commit ); - - print $repo->run( tag => $version, '--no-sign', $commit ); - - say "created tag '$version' ($commit)"; - } - -} - -1; - -__END__ - -=head1 NAME - -Git::CPAN::Patch::Import - The meat of git-cpan-import - -=head1 DESCRIPTION - -This is the guts of Git::CPAN::Patch::Import moved here to make it callable -as a function so git-backpan-init goes faster. - -=cut - -1; diff --git a/project.vim b/project.vim index e07f090..60fbfb7 100644 --- a/project.vim +++ b/project.vim @@ -173,7 +173,6 @@ distro Files=. { .perlcriticrc distrelease.yml MANIFEST.SKIP - blib/libdoc/Git::CPAN::Patch::Import.3 blib/libdoc/Git::CPAN::Patch.3 contrib/gitpan Build diff --git a/t/00-load.t b/t/00-load.t index de6712e..2347ad5 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -4,7 +4,6 @@ use warnings; use Test2::V1 -Pip; use Git::CPAN::Patch; -use Git::CPAN::Patch::Import; pass "can load the main modules";