93
use Error qw(:try);
94
use Cwd qw(abs_path);
95
96
-require XSLoader;
97
-XSLoader::load('Git', $VERSION);
98
-
96
}
97
98
410
411
Return the Git version in use.
412
416
-Implementation of this function is very fast; no external command calls
417
-are involved.
418
-
413
=cut
414
421
-# Implemented in Git.xs.
415
+sub version {
416
+ my $verstr = command_oneline('--version');
417
+ $verstr =~ s/^git version //;
418
+ $verstr;
419
+}
420
421
422
=item exec_path ()
424
Return path to the Git sub-command executables (the same as
425
C<git --exec-path>). Useful mostly only internally.
426
429
-Implementation of this function is very fast; no external command calls
430
-are involved.
431
-
427
=cut
428
434
-# Implemented in Git.xs.
429
+sub exec_path { command_oneline('--exec-path') }
430
431
432
=item repo_path ()
567
568
=item hash_object ( TYPE, FILENAME )
569
575
-=item hash_object ( TYPE, FILEHANDLE )
576
-
570
Compute the SHA1 object id of the given C<FILENAME> (or data waiting in
571
C<FILEHANDLE>) considering it is of the C<TYPE> object type (C<blob>,
572
C<commit>, C<tree>).
573
581
-In case of C<FILEHANDLE> passed instead of file name, all the data
582
-available are read and hashed, and the filehandle is automatically
583
-closed. The file handle should be freshly opened - if you have already
584
-read anything from the file handle, the results are undefined (since
585
-this function works directly with the file descriptor and internal
586
-PerlIO buffering might have messed things up).
587
-
574
The method can be called without any instance or on a specified Git repository,
575
it makes zero difference.
576
577
The function returns the SHA1 hash.
578
593
-Implementation of this function is very fast; no external command calls
594
-are involved.
595
-
579
=cut
580
581
+# TODO: Support for passing FILEHANDLE instead of FILENAME
582
sub hash_object {
583
my ($self, $type, $file) = _maybe_self(@_);
600
-
601
- # hash_object_* implemented in Git.xs.
602
-
603
- if (ref($file) eq 'GLOB') {
604
- my $hash = hash_object_pipe($type, fileno($file));
605
- close $file;
606
- return $hash;
607
- } else {
608
- hash_object_file($type, $file);
609
- }
584
+ command_oneline('hash-object', '-t', $type, $file);
585
}
586
587
777
778
# Execute the given Git command ($_[0]) with arguments ($_[1..])
779
# by searching for it at proper places.
805
-# _execv_git_cmd(), implemented in Git.xs.
780
+sub _execv_git_cmd { exec('git', @_); }
781
782
# Close pipe to a subprocess.
783
sub _cmd_close {
796
}
797
798
824
-# Trickery for .xs routines: In order to avoid having some horrid
825
-# C code trying to do stuff with undefs and hashes, we gate all
826
-# xs calls through the following and in case we are being ran upon
827
-# an instance call a C part of the gate which will set up the
828
-# environment properly.
829
-sub _call_gate {
830
- my $xsfunc = shift;
831
- my ($self, @args) = _maybe_self(@_);
832
-
833
- if (defined $self) {
834
- # XXX: We ignore the WorkingCopy! To properly support
835
- # that will require heavy changes in libgit.
836
-
837
- # XXX: And we ignore everything else as well. libgit
838
- # at least needs to be extended to let us specify
839
- # the $GIT_DIR instead of looking it up in environment.
840
- #xs_call_gate($self->{opts}->{Repository});
841
- }
842
-
843
- # Having to call throw from the C code is a sure path to insanity.
844
- local $SIG{__DIE__} = sub { throw Error::Simple("@_"); };
845
- &$xsfunc(@args);
846
-}
847
-
848
-sub AUTOLOAD {
849
- my $xsname;
850
- our $AUTOLOAD;
851
- ($xsname = $AUTOLOAD) =~ s/.*:://;
852
- throw Error::Simple("&Git::$xsname not defined") if $xsname =~ /^xs_/;
853
- $xsname = 'xs_'.$xsname;
854
- _call_gate(\&$xsname, @_);
855
-}
856
-
799
sub DESTROY { }
800
801