{"thread":{"id":"4731","subject":"[PATCH] Git.pm: Remove PerlIO usage from Git.xs","startedAt":"2006-07-01T23:38:56Z","lastAt":"2006-07-01T23:38:56Z","messageCount":1,"participants":["Petr Baudis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23009","messageId":"20060701233856.2104.3557.stgit@machine.or.cz","threadId":"4731","inReplyTo":null,"subject":"[PATCH] Git.pm: Remove PerlIO usage from Git.xs","fromName":"Petr Baudis","fromEmail":"pasky@suse.cz","sentAt":"2006-07-01T23:38:56Z","receivedAt":"2006-07-01T23:38:56Z","isPatch":true,"sender":{"key":"pasky@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/18439?v=4"},"body":"PerlIO_*() is not portable before 5.7.3, according to ppport.h, and it's\nmore clear what is going on when we do it in the Perl part of the Git module\nanyway.\n\nSigned-off-by: Petr Baudis <pasky@suse.cz>\n---\n\n perl/Git.pm |   14 +++++++++++++-\n perl/Git.xs |   56 +++++++++++++++++++++++++-------------------------------\n 2 files changed, 38 insertions(+), 32 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 0581447..b4ee88b 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -511,7 +511,19 @@ are involved.\n \n =cut\n \n-# Implemented in Git.xs.\n+sub hash_object {\n+\tmy ($self, $type, $file) = _maybe_self(@_);\n+\n+\t# hash_object_* implemented in Git.xs.\n+\n+\tif (ref($file) eq 'GLOB') {\n+\t\tmy $hash = hash_object_pipe($type, fileno($file));\n+\t\tclose $file;\n+\t\treturn $hash;\n+\t} else {\n+\t\thash_object_file($type, $file);\n+\t}\n+}\n \n \n \ndiff --git a/perl/Git.xs b/perl/Git.xs\nindex 3030ba9..cb23261 100644\n--- a/perl/Git.xs\n+++ b/perl/Git.xs\n@@ -104,42 +104,36 @@ CODE:\n }\n \n char *\n-xs_hash_object(type, file)\n+xs_hash_object_pipe(type, fd)\n \tchar *type;\n-\tSV *file;\n+\tint fd;\n CODE:\n {\n \tunsigned char sha1[20];\n \n-\tif (SvTYPE(file) == SVt_RV)\n-\t\tfile = SvRV(file);\n-\n-\tif (SvTYPE(file) == SVt_PVGV) {\n-\t\t/* Filehandle */\n-\t\tPerlIO *pio;\n-\n-\t\tpio = IoIFP(sv_2io(file));\n-\t\tif (!pio)\n-\t\t\tcroak(\"You passed me something weird - a dir glob?\");\n-\t\t/* XXX: I just hope PerlIO didn't read anything from it yet.\n-\t\t * --pasky */\n-\t\tif (index_pipe(sha1, PerlIO_fileno(pio), type, 0))\n-\t\t\tcroak(\"Unable to hash given filehandle\");\n-\t\t/* Avoid any nasty surprises. */\n-\t\tPerlIO_close(pio);\n-\n-\t} else {\n-\t\t/* String */\n-\t\tchar *path = SvPV_nolen(file);\n-\t\tint fd = open(path, O_RDONLY);\n-\t\tstruct stat st;\n-\n-\t\tif (fd < 0 ||\n-\t\t    fstat(fd, &st) < 0 ||\n-\t\t    index_fd(sha1, fd, &st, 0, type))\n-\t\t\tcroak(\"Unable to hash %s\", path);\n-\t\tclose(fd);\n-\t}\n+\tif (index_pipe(sha1, fd, type, 0))\n+\t\tcroak(\"Unable to hash given filehandle\");\n+\tRETVAL = sha1_to_hex(sha1);\n+}\n+OUTPUT:\n+\tRETVAL\n+\n+char *\n+xs_hash_object_file(type, path)\n+\tchar *type;\n+\tchar *path;\n+CODE:\n+{\n+\tunsigned char sha1[20];\n+\tint fd = open(path, O_RDONLY);\n+\tstruct stat st;\n+\n+\tif (fd < 0 ||\n+\t    fstat(fd, &st) < 0 ||\n+\t    index_fd(sha1, fd, &st, 0, type))\n+\t\tcroak(\"Unable to hash %s\", path);\n+\tclose(fd);\n+\n \tRETVAL = sha1_to_hex(sha1);\n }\n OUTPUT:\n"}]}