Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convertion to Git::Repository (patch from BooK)

  • Loading branch information...
commit 7b971cf99f16b378a40d0fc274002a27b461846e 1 parent 936ca92
@yanick yanick authored
Showing with 43 additions and 76 deletions.
  1. +43 −76 lib/Git/CPAN/Patch/Import.pm
View
119 lib/Git/CPAN/Patch/Import.pm
@@ -20,7 +20,7 @@ use File::Path;
use File::chdir;
use Cwd qw/ getcwd /;
use version;
-use Git;
+use Git::Repository;
use CLASS;
use CPANPLUS;
@@ -89,30 +89,24 @@ sub init_repo {
sub releases_in_git {
- my $repo = Git->repository;
+ 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->command(log => '--pretty=format:%b');
+ $repo->run(log => '--pretty=format:%b');
return @releases;
}
sub rev_exists {
my $rev = shift;
- my $repo = Git->repository;
+ my $repo = Git::repository->new;
- return eval {
- git_cmd_try {
- $repo->command(["rev-parse", $rev], {STDERR=>1});
- } "fail"
- };
+ return eval { $repo->run( 'rev-parse', $rev ); };
}
sub contains_git_revisions {
- my $repo = Git->repository;
-
return unless -d ".git";
return rev_exists("HEAD");
}
@@ -132,13 +126,13 @@ sub import_one_backpan_release {
die "your Git.pm doesn't have a command_bidi_pipe()"
unless defined &Git::command_bidi_pipe;
- my $repo = Git->repository;
+ my $repo = Git::repository->new;
my( $last_commit, $last_version );
# figure out if there is already an imported module
- if ( $last_commit = eval { $repo->command_oneline("rev-parse", "-q", "--verify", "cpan/master") } ) {
- $last_version = $repo->command_oneline("cpan-last-version");
+ 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(
@@ -192,10 +186,10 @@ sub import_one_backpan_release {
local $CWD = $dir;
- my $write_tree_repo = Git->repository;
+ my $write_tree_repo = Git::repository->new;
- $write_tree_repo->command_noisy( qw(add -v --force .) );
- $write_tree_repo->command_oneline( "write-tree" );
+ print $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
@@ -210,17 +204,11 @@ sub import_one_backpan_release {
my @parents = grep { $_ } $last_commit;
- # FIXME $repo->command_bidi_pipe is broken
- my ( $pid, $in, $out, $ctx ) = Git::command_bidi_pipe(
- "commit-tree", $tree,
- map { ( -p => $_ ) } @parents,
- );
-
# commit message
my $name = $release->dist;
my $version = $release->version || '';
- $out->print( join ' ', ( $last_version ? "import" : "initial import of" ), "$name $version from CPAN\n" );
- $out->print( <<"END" );
+ my $message = join ' ', ( $last_version ? "import" : "initial import of"), "$name $version from CPAN\n";
+ $message .- <<"END";
git-cpan-module: $name
git-cpan-version: $version
@@ -229,28 +217,21 @@ git-cpan-file: @{[ $release->prefix ]}
END
- # we need to send an EOF to git in order for it to actually finalize the commit
- # this kludge makes command_close_bidi_pipe not barf
- close $out;
- open $out, '<', \my $buf;
-
- chomp(my $commit = <$in>);
-
- Git::command_close_bidi_pipe($pid, $in, $out, $ctx);
-
+ 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;
- $repo->command_noisy('update-ref', '-m' => "import $dist", 'refs/heads/cpan/master', $commit );
+ 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->command( "tag", "-l" => $tag ) ) {
+ if( $repo->run( "tag", "-l" => $tag ) ) {
say "Tag $tag already exists, overwriting";
}
- $repo->command_noisy( "tag", "-f" => $tag, $commit );
+ print $repo->run( "tag", "-f" => $tag, $commit );
say "created tag '$tag' ($commit)";
}
}
@@ -319,14 +300,14 @@ sub import_from_backpan {
}
}
- my $repo = Git->repository;
+ my $repo = Git::Repository->new;
if( !rev_exists("master") ) {
print STDERR "Line 324: about to checkout\n";
- $repo->command_noisy('checkout', '-t', '-b', 'master', 'cpan/master');
+ print $repo->run('checkout', '-t', '-b', 'master', 'cpan/master');
}
else {
- $repo->command_noisy('checkout', 'master', '.');
- $repo->command_noisy('merge', 'cpan/master');
+ print $repo->run('checkout', 'master', '.'),
+ $repo->run('merge', 'cpan/master');
}
return $repo_dir;
@@ -334,14 +315,14 @@ sub import_from_backpan {
sub fixup_repository {
- my $repo = Git->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") ) {
- $repo->command_noisy('branch', '-t', 'cpan/master', 'master');
+ print $repo->run('branch', '-t', 'cpan/master', 'master');
}
}
@@ -358,14 +339,14 @@ sub main {
my $full_hist;
- my $repo = Git->repository;
+ my $repo = Git::Repository->new;
my ( $last_commit, $last_version );
# figure out if there is already an imported module
- if ( $last_commit = eval { $repo->command_oneline("rev-parse", "-q", "--verify", "cpan/master") } ) {
- $module ||= $repo->command_oneline("cpan-which");
- $last_version = $repo->command_oneline("cpan-last-version");
+ 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;
@@ -430,10 +411,10 @@ sub main {
local $CWD = $dir;
- my $write_tree_repo = Git->repository;
+ my $write_tree_repo = Git::Repository->new;
- $write_tree_repo->command_noisy( qw(add -v --force .) );
- $write_tree_repo->command_oneline( "write-tree" );
+ print $write_tree_repo->run( qw(add -v --force .) );
+ print $write_tree_repo->run( "write-tree" );
};
@@ -501,15 +482,8 @@ sub main {
my @parents = ( grep { $_ } $last_commit, @{ $opts->{parent} || [] } );
- # FIXME $repo->command_bidi_pipe is broken
- my ( $pid, $in, $out, $ctx ) = Git::command_bidi_pipe(
- "commit-tree", $tree,
- map { ( -p => $_ ) } @parents,
- );
-
- # commit message
- $out->print( join ' ', ( $last_version ? "import" : "initial import of" ), "$name $version from CPAN\n" );
- $out->print( <<"END" );
+ my $message = join ' ', ( $last_version ? "import" : "initial import of" ), "$name $version from CPAN\n" );
+ $message .= <<"END";
git-cpan-module: $name
git-cpan-version: $version
@@ -517,22 +491,15 @@ git-cpan-authorid: @{[ $author_obj->cpanid ]}
END
-
- # we need to send an EOF to git in order for it to actually finalize the commit
- # this kludge makes command_close_bidi_pipe not barf
- close $out;
- open $out, '<', \my $buf;
-
- chomp(my $commit = <$in> || '');
-
- Git::command_close_bidi_pipe($pid, $in, $out, $ctx);
-
+ my $commit = $repo->run(
+ { input => $message },
+ 'commit-tree', $tree, map { ( -p => $_ ) } @parents;
# finally, update the fake remote branch and create a tag for convenience
- $repo->command_noisy('update-ref', '-m' => "import $dist", 'refs/remotes/cpan/master', $commit );
+ print $repo->run('update-ref', '-m' => "import $dist", 'refs/remotes/cpan/master', $commit );
- $repo->command_noisy( tag => $version, $commit );
+ print $repo->run( tag => $version, $commit );
say "created tag '$version' ($commit)";
}
@@ -550,22 +517,22 @@ sub import_from_gitpan {
my $dist = $module_obj->name;
$dist =~ s/::/-/g;
- my $repo = Git->repository;
+ my $repo = Git::Repository->new;
my $url = "git://github.com/gitpan/${dist}.git";
- unless ( "gitpan\n" ~~ $repo->command('remote') ) {
+ unless ( "gitpan\n" ~~ $repo->run('remote') ) {
# no gitpan remote? create it!
# but first, does it exist?
die "no repo found at $url\n"
- unless eval { $repo->command( 'ls-remote', $url ) };
+ unless eval { $repo->run( 'ls-remote', $url ) };
- $repo->command_noisy( 'remote', 'add', 'gitpan', $url );
+ print $repo->run( 'remote', 'add', 'gitpan', $url );
}
- $repo->command_noisy(qw/ fetch gitpan /);
+ print $repo->run(qw/ fetch gitpan /);
}
Please sign in to comment.
Something went wrong with that request. Please try again.