Git.pm: Remove PerlIO usage from Git.xs
PerlIO_*() is not portable before 5.7.3, according to ppport.h, and it's more clear what is going on when we do it in the Perl part of the Git module anyway. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:

committed by
Junio C Hamano

parent
b9795608c4
commit
e6634ac984
14
perl/Git.pm
14
perl/Git.pm
@ -511,7 +511,19 @@ are involved.
|
|||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
# Implemented in Git.xs.
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
56
perl/Git.xs
56
perl/Git.xs
@ -104,42 +104,36 @@ CODE:
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xs_hash_object(type, file)
|
xs_hash_object_pipe(type, fd)
|
||||||
char *type;
|
char *type;
|
||||||
SV *file;
|
int fd;
|
||||||
CODE:
|
CODE:
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
|
|
||||||
if (SvTYPE(file) == SVt_RV)
|
if (index_pipe(sha1, fd, type, 0))
|
||||||
file = SvRV(file);
|
croak("Unable to hash given filehandle");
|
||||||
|
RETVAL = sha1_to_hex(sha1);
|
||||||
if (SvTYPE(file) == SVt_PVGV) {
|
}
|
||||||
/* Filehandle */
|
OUTPUT:
|
||||||
PerlIO *pio;
|
RETVAL
|
||||||
|
|
||||||
pio = IoIFP(sv_2io(file));
|
char *
|
||||||
if (!pio)
|
xs_hash_object_file(type, path)
|
||||||
croak("You passed me something weird - a dir glob?");
|
char *type;
|
||||||
/* XXX: I just hope PerlIO didn't read anything from it yet.
|
char *path;
|
||||||
* --pasky */
|
CODE:
|
||||||
if (index_pipe(sha1, PerlIO_fileno(pio), type, 0))
|
{
|
||||||
croak("Unable to hash given filehandle");
|
unsigned char sha1[20];
|
||||||
/* Avoid any nasty surprises. */
|
int fd = open(path, O_RDONLY);
|
||||||
PerlIO_close(pio);
|
struct stat st;
|
||||||
|
|
||||||
} else {
|
if (fd < 0 ||
|
||||||
/* String */
|
fstat(fd, &st) < 0 ||
|
||||||
char *path = SvPV_nolen(file);
|
index_fd(sha1, fd, &st, 0, type))
|
||||||
int fd = open(path, O_RDONLY);
|
croak("Unable to hash %s", path);
|
||||||
struct stat st;
|
close(fd);
|
||||||
|
|
||||||
if (fd < 0 ||
|
|
||||||
fstat(fd, &st) < 0 ||
|
|
||||||
index_fd(sha1, fd, &st, 0, type))
|
|
||||||
croak("Unable to hash %s", path);
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
RETVAL = sha1_to_hex(sha1);
|
RETVAL = sha1_to_hex(sha1);
|
||||||
}
|
}
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
Reference in New Issue
Block a user