App-gh
view release on metacpan or search on metacpan
lib/App/gh/Git.pm view on Meta::CPAN
my $E = shift;
if ($E->value() == 1) {
# Key not found.
return undef;
} else {
throw $E;
}
};
}
=item config_int ( VARIABLE )
Retrieve the integer configuration C<VARIABLE>. The return value
is simple decimal number. An optional value suffix of 'k', 'm',
or 'g' in the config file will cause the value to be multiplied
by 1024, 1048576 (1024^2), or 1073741824 (1024^3) prior to output.
It would return C<undef> if configuration variable is not defined,
This currently wraps command('config') so it is not so fast.
=cut
sub config_int {
my ($self, $var) = _maybe_self(@_);
try {
my @cmd = ('config', '--int', '--get', $var);
unshift @cmd, $self if $self;
return command_oneline(@cmd);
} catch App::gh::Git::Error::Command with {
my $E = shift;
if ($E->value() == 1) {
# Key not found.
return undef;
} else {
throw $E;
}
};
}
=item get_colorbool ( NAME )
Finds if color should be used for NAMEd operation from the configuration,
and returns boolean (true for "use color", false for "do not use color").
=cut
sub get_colorbool {
my ($self, $var) = @_;
my $stdout_to_tty = (-t STDOUT) ? "true" : "false";
my $use_color = $self->command_oneline('config', '--get-colorbool',
$var, $stdout_to_tty);
return ($use_color eq 'true');
}
=item get_color ( SLOT, COLOR )
Finds color for SLOT from the configuration, while defaulting to COLOR,
and returns the ANSI color escape sequence:
print $repo->get_color("color.interactive.prompt", "underline blue white");
print "some text";
print $repo->get_color("", "normal");
=cut
sub get_color {
my ($self, $slot, $default) = @_;
my $color = $self->command_oneline('config', '--get-color', $slot, $default);
if (!defined $color) {
$color = "";
}
return $color;
}
=item remote_refs ( REPOSITORY [, GROUPS [, REFGLOBS ] ] )
This function returns a hashref of refs stored in a given remote repository.
The hash is in the format C<refname =\> hash>. For tags, the C<refname> entry
contains the tag object while a C<refname^{}> entry gives the tagged objects.
C<REPOSITORY> has the same meaning as the appropriate C<git-ls-remote>
argument; either an URL or a remote name (if called on a repository instance).
C<GROUPS> is an optional arrayref that can contain 'tags' to return all the
tags and/or 'heads' to return all the heads. C<REFGLOB> is an optional array
of strings containing a shell-like glob to further limit the refs returned in
the hash; the meaning is again the same as the appropriate C<git-ls-remote>
argument.
This function may or may not be called on a repository instance. In the former
case, remote names as defined in the repository are recognized as repository
specifiers.
=cut
sub remote_refs {
my ($self, $repo, $groups, $refglobs) = _maybe_self(@_);
my @args;
if (ref $groups eq 'ARRAY') {
foreach (@$groups) {
if ($_ eq 'heads') {
push (@args, '--heads');
} elsif ($_ eq 'tags') {
push (@args, '--tags');
} else {
# Ignore unknown groups for future
# compatibility
}
}
}
push (@args, $repo);
if (ref $refglobs eq 'ARRAY') {
push (@args, @$refglobs);
}
my @self = $self ? ($self) : (); # Ultra trickery
my ($fh, $ctx) = App::gh::Git::command_output_pipe(@self, 'ls-remote', @args);
my %refs;
while (<$fh>) {
chomp;
my ($hash, $ref) = split(/\t/, $_, 2);
( run in 1.002 second using v1.01-cache-2.11-cpan-0b5f733616e )