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>
Petr Baudis committed
Jul 2, 2006 at 01:38 UTC
e6634ac9841f8df3ce1c0c461c677faf2d59af3e
2 files changed
+38
-32
perl/Git.pm
+13
-1
@@ -511,7 +511,19 @@ are involved.
511
512
=cut
513
514
-# Implemented in Git.xs.
514
+sub hash_object {
515
+ my ($self, $type, $file) = _maybe_self(@_);
516
+
517
+ # hash_object_* implemented in Git.xs.
518
+
519
+ if (ref($file) eq 'GLOB') {
520
+ my $hash = hash_object_pipe($type, fileno($file));
521
+ close $file;
522
+ return $hash;
523
+ } else {
524
+ hash_object_file($type, $file);
525
+ }
526
+}
527
528
529
perl/Git.xs
+25
-31
@@ -104,42 +104,36 @@ CODE:
104
}
105
106
char *
107
-xs_hash_object(type, file)
107
+xs_hash_object_pipe(type, fd)
108
char *type;
109
- SV *file;
109
+ int fd;
110
CODE:
111
{
112
unsigned char sha1[20];
113
114
- if (SvTYPE(file) == SVt_RV)
115
- file = SvRV(file);
116
-
117
- if (SvTYPE(file) == SVt_PVGV) {
118
- /* Filehandle */
119
- PerlIO *pio;
120
-
121
- pio = IoIFP(sv_2io(file));
122
- if (!pio)
123
- croak("You passed me something weird - a dir glob?");
124
- /* XXX: I just hope PerlIO didn't read anything from it yet.
125
- * --pasky */
126
- if (index_pipe(sha1, PerlIO_fileno(pio), type, 0))
127
- croak("Unable to hash given filehandle");
128
- /* Avoid any nasty surprises. */
129
- PerlIO_close(pio);
130
-
131
- } else {
132
- /* String */
133
- char *path = SvPV_nolen(file);
134
- int fd = open(path, O_RDONLY);
135
- struct stat st;
136
-
137
- if (fd < 0 ||
138
- fstat(fd, &st) < 0 ||
139
- index_fd(sha1, fd, &st, 0, type))
140
- croak("Unable to hash %s", path);
141
- close(fd);
142
- }
114
+ if (index_pipe(sha1, fd, type, 0))
115
+ croak("Unable to hash given filehandle");
116
+ RETVAL = sha1_to_hex(sha1);
117
+}
118
+OUTPUT:
119
+ RETVAL
120
+
121
+char *
122
+xs_hash_object_file(type, path)
123
+ char *type;
124
+ char *path;
125
+CODE:
126
+{
127
+ unsigned char sha1[20];
128
+ int fd = open(path, O_RDONLY);
129
+ struct stat st;
130
+
131
+ if (fd < 0 ||
132
+ fstat(fd, &st) < 0 ||
133
+ index_fd(sha1, fd, &st, 0, type))
134
+ croak("Unable to hash %s", path);
135
+ close(fd);
136
+
137
RETVAL = sha1_to_hex(sha1);
138
}
139
OUTPUT: