mirror of
https://github.com/git/git.git
synced 2024-11-19 07:24:50 +01:00
b1edc53d06
This patch introduces a very basic and barebone Git.pm module with a sketch of how the generic interface would look like; most functions are missing, but this should give some good base. I will continue expanding it. Most desirable now is more careful error reporting, generic_in() for feeding input to Git commands and the repository() constructor doing some poking with git-rev-parse to get the git directory and subdirectory prefix. Those three are basically the prerequisities for converting git-mv. I will send them as follow-ups to this patch. Currently Git.pm just wraps up exec()s of Git commands, but even that is not trivial to get right and various Git perl scripts do it in various inconsistent ways. In addition to Git.pm, there is now also Git.xs which provides barebone Git.xs for directly interfacing with libgit.a, and as an example providing the hash_object() function using libgit. This adds the Git module, integrates it to the build system and as an example converts the git-fmt-merge-msg.perl script to it (the result is not very impressive since its advantage is not quite apparent in this one, but I just picked up the simplest Git user around). Compared to v3, only very minor things were fixed in this patch (some whitespaces, a missing export, tiny bug in git-fmt-merge-msg.perl); at first I wanted to post them as a separate patch but since this is still only in pu, I decided that it will be cleaner to just resend the patch. My current working state is available all the time at http://pasky.or.cz/~xpasky/git-perl/Git.pm and an irregularily updated API documentation is at http://pasky.or.cz/~xpasky/git-perl/Git.html Many thanks to Jakub Narebski, Junio and others for their feedback. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>
64 lines
1.3 KiB
Text
64 lines
1.3 KiB
Text
/* By carefully stacking #includes here (even if WE don't really need them)
|
|
* we strive to make the thing actually compile. Git header files aren't very
|
|
* nice. Perl headers are one of the signs of the coming apocalypse. */
|
|
#include <ctype.h>
|
|
/* Ok, it hasn't been so bad so far. */
|
|
|
|
/* libgit interface */
|
|
#include "../cache.h"
|
|
|
|
/* XS and Perl interface */
|
|
#include "EXTERN.h"
|
|
#include "perl.h"
|
|
#include "XSUB.h"
|
|
|
|
#include "ppport.h"
|
|
|
|
|
|
MODULE = Git PACKAGE = Git
|
|
|
|
PROTOTYPES: DISABLE
|
|
|
|
# /* TODO: xs_call_gate(). See Git.pm. */
|
|
|
|
char *
|
|
xs_hash_object(file, type = "blob")
|
|
SV *file;
|
|
char *type;
|
|
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);
|
|
}
|
|
RETVAL = sha1_to_hex(sha1);
|
|
}
|
|
OUTPUT:
|
|
RETVAL
|