X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=perl%2FGit.pm;h=2b26b65bfb00c60535919d7b9359a5549f9e9709;hb=c326246accf36bc070b326773df2b9ec1c336037;hp=f2467bddbe91954aa5a014bcee79333fe1586cde;hpb=d7b6c3c0f54b951c85cd41c6e6571c65cf090111;p=git.git diff --git a/perl/Git.pm b/perl/Git.pm index f2467bddb..2b26b65bf 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -93,13 +93,8 @@ use Carp qw(carp croak); # but croak is bad - throw instead use Error qw(:try); use Cwd qw(abs_path); -require XSLoader; -XSLoader::load('Git', $VERSION); - } -my $instance_id = 0; - =head1 CONSTRUCTORS @@ -217,7 +212,7 @@ sub repository { delete $opts{Directory}; } - $self = { opts => \%opts, id => $instance_id++ }; + $self = { opts => \%opts }; bless $self, $class; } @@ -415,12 +410,13 @@ sub command_noisy { Return the Git version in use. -Implementation of this function is very fast; no external command calls -are involved. - =cut -# Implemented in Git.xs. +sub version { + my $verstr = command_oneline('--version'); + $verstr =~ s/^git version //; + $verstr; +} =item exec_path () @@ -428,12 +424,9 @@ are involved. Return path to the Git sub-command executables (the same as C). Useful mostly only internally. -Implementation of this function is very fast; no external command calls -are involved. - =cut -# Implemented in Git.xs. +sub exec_path { command_oneline('--exec-path') } =item repo_path () @@ -572,61 +565,23 @@ sub ident_person { } -=item get_object ( TYPE, SHA1 ) - -Return contents of the given object in a scalar string. If the object has -not been found, undef is returned; however, do not rely on this! Currently, -if you use multiple repositories at once, get_object() on one repository -_might_ return the object even though it exists only in another repository. -(But do not rely on this behaviour either.) - -The method must be called on a repository instance. - -Implementation of this method is very fast; no external command calls -are involved. That's why it is broken, too. ;-) - -=cut - -# Implemented in Git.xs. - - =item hash_object ( TYPE, FILENAME ) -=item hash_object ( TYPE, FILEHANDLE ) - Compute the SHA1 object id of the given C (or data waiting in C) considering it is of the C object type (C, C, C). -In case of C passed instead of file name, all the data -available are read and hashed, and the filehandle is automatically -closed. The file handle should be freshly opened - if you have already -read anything from the file handle, the results are undefined (since -this function works directly with the file descriptor and internal -PerlIO buffering might have messed things up). - The method can be called without any instance or on a specified Git repository, it makes zero difference. The function returns the SHA1 hash. -Implementation of this function is very fast; no external command calls -are involved. - =cut +# TODO: Support for passing FILEHANDLE instead of FILENAME sub hash_object { my ($self, $type, $file) = _maybe_self(@_); - - # hash_object_* implemented in Git.xs. - - if (ref($file) eq 'GLOB') { - my $hash = hash_object_pipe($type, fileno($file)); - close $file; - return $hash; - } else { - hash_object_file($type, $file); - } + command_oneline('hash-object', '-t', $type, $file); } @@ -822,7 +777,7 @@ sub _cmd_exec { # Execute the given Git command ($_[0]) with arguments ($_[1..]) # by searching for it at proper places. -# _execv_git_cmd(), implemented in Git.xs. +sub _execv_git_cmd { exec('git', @_); } # Close pipe to a subprocess. sub _cmd_close { @@ -841,38 +796,6 @@ sub _cmd_close { } -# Trickery for .xs routines: In order to avoid having some horrid -# C code trying to do stuff with undefs and hashes, we gate all -# xs calls through the following and in case we are being ran upon -# an instance call a C part of the gate which will set up the -# environment properly. -sub _call_gate { - my $xsfunc = shift; - my ($self, @args) = _maybe_self(@_); - - if (defined $self) { - # XXX: We ignore the WorkingCopy! To properly support - # that will require heavy changes in libgit. - # For now, when we will need to do it we could temporarily - # chdir() there and then chdir() back after the call is done. - - xs__call_gate($self->{id}, $self->repo_path()); - } - - # Having to call throw from the C code is a sure path to insanity. - local $SIG{__DIE__} = sub { throw Error::Simple("@_"); }; - &$xsfunc(@args); -} - -sub AUTOLOAD { - my $xsname; - our $AUTOLOAD; - ($xsname = $AUTOLOAD) =~ s/.*:://; - throw Error::Simple("&Git::$xsname not defined") if $xsname =~ /^xs_/; - $xsname = 'xs_'.$xsname; - _call_gate(\&$xsname, @_); -} - sub DESTROY { }