Commit | Line | Data |
56b6dbe6 |
1 | use MooseX::Declare; |
2 | |
3 | class Gitalist::Git::Util { |
941bb5a1 |
4 | use File::Which; |
5 | use Git::PurePerl; |
ffdabc0a |
6 | use IPC::Run qw(run start); |
cdcdec92 |
7 | use Symbol qw(geniosym); |
941bb5a1 |
8 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
839da3d7 |
9 | |
82bc0f05 |
10 | has repository => ( |
44a9ed75 |
11 | isa => 'Gitalist::Git::Repository', |
b5b638f7 |
12 | handles => { gitdir => 'path' }, |
84f31a44 |
13 | is => 'bare', # No accessor |
14 | weak_ref => 1, # Weak, you have to hold onto me. |
82bc0f05 |
15 | predicate => 'has_repository', |
84f31a44 |
16 | ); |
941bb5a1 |
17 | has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 ); |
18 | sub _build__git { |
56b6dbe6 |
19 | my $git = File::Which::which('git'); |
20 | |
21 | if (!$git) { |
22 | die <<EOR; |
23 | Could not find a git executable. |
24 | Please specify the which git executable to use in gitweb.yml |
25 | EOR |
26 | } |
27 | |
28 | return $git; |
29 | } |
30 | |
defb0050 |
31 | has gpp => ( |
84f31a44 |
32 | isa => 'Git::PurePerl', is => 'ro', lazy => 1, |
38b9e5c8 |
33 | default => sub { |
34 | my $self = shift; |
82bc0f05 |
35 | confess("Cannot get gpp without repository") |
36 | unless $self->has_repository; |
38b9e5c8 |
37 | Git::PurePerl->new(gitdir => $self->gitdir); |
38 | }, |
84f31a44 |
39 | ); |
941bb5a1 |
40 | |
41 | method run_cmd (@args) { |
38b9e5c8 |
42 | unshift @args, ( '--git-dir' => $self->gitdir ) |
82bc0f05 |
43 | if $self->has_repository; |
32a371cc |
44 | # print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/; |
839da3d7 |
45 | run [$self->_git, @args], \my($in, $out, $err); |
941bb5a1 |
46 | |
839da3d7 |
47 | return $out; |
941bb5a1 |
48 | } |
4111e151 |
49 | |
aa7f1f92 |
50 | method run_cmd_fh (@args) { |
30db8f5b |
51 | my ($in, $out, $err) = (geniosym, geniosym, geniosym); |
aa7f1f92 |
52 | unshift @args, ('--git-dir' => $self->gitdir) |
82bc0f05 |
53 | if $self->has_repository; |
30db8f5b |
54 | # print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/; |
ffdabc0a |
55 | start [$self->_git, @args], |
30db8f5b |
56 | '<pipe', $in, |
cdcdec92 |
57 | '>pipe', $out, |
58 | '2>pipe', $err |
aa7f1f92 |
59 | or die "cmd returned *?"; |
5156786b |
60 | return $out; |
aa7f1f92 |
61 | } |
62 | |
32a371cc |
63 | method run_cmd_list (@args) { |
64 | my $cmdout = $self->run_cmd(@args); |
65 | return $cmdout ? split(/\n/, $cmdout) : (); |
66 | } |
67 | |
4111e151 |
68 | method get_gpp_object (NonEmptySimpleStr $sha1) { |
defb0050 |
69 | return $self->gpp->get_object($sha1) || undef; |
4111e151 |
70 | } |
71 | |
56b6dbe6 |
72 | } # end class |
775e96e0 |
73 | |
74 | __END__ |
75 | |
271f6b46 |
76 | =head1 NAME |
77 | |
78 | Gitalist::Git::Util - Class for utilities to run git or deal with Git::PurePerl |
79 | |
80 | =head1 SEE ALSO |
81 | |
82 | L<Git::PurePerl>. |
83 | |
775e96e0 |
84 | =head1 AUTHORS |
85 | |
86 | See L<Gitalist> for authors. |
87 | |
88 | =head1 LICENSE |
89 | |
90 | See L<Gitalist> for the license. |
91 | |
92 | =cut |
93 | |