Git development
 help / color / mirror / Atom feed
From: Petr Baudis <pasky@suse.cz>
To: Junio C Hamano <junkio@cox.net>
Cc: <git@vger.kernel.org>
Subject: [PATCH] Git.pm: Remove PerlIO usage from Git.xs
Date: Sun, 02 Jul 2006 01:38:56 +0200	[thread overview]
Message-ID: <20060701233856.2104.3557.stgit@machine.or.cz> (raw)

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>
---

 perl/Git.pm |   14 +++++++++++++-
 perl/Git.xs |   56 +++++++++++++++++++++++++-------------------------------
 2 files changed, 38 insertions(+), 32 deletions(-)

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

                 reply	other threads:[~2006-07-01 23:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060701233856.2104.3557.stgit@machine.or.cz \
    --to=pasky@suse.cz \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox