1 /* By carefully stacking #includes here (even if WE don't really need them)
2 * we strive to make the thing actually compile. Git header files aren't very
3 * nice. Perl headers are one of the signs of the coming apocalypse. */
5 /* Ok, it hasn't been so bad so far. */
9 #include "../exec_cmd.h"
11 #define die perlyshadow_die__
13 /* XS and Perl interface */
24 report_xs(const char *prefix, const char *err, va_list params)
26 static char buf[4096];
28 vsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params);
33 die_xs(const char *err, va_list params)
36 str = report_xs("fatal: ", err, params);
41 error_xs(const char *err, va_list params)
44 str = report_xs("error: ", err, params);
50 MODULE = Git PACKAGE = Git
57 set_error_routine(error_xs);
58 set_die_routine(die_xs);
62 # /* TODO: xs_call_gate(). See Git.pm. */
79 RETVAL = git_exec_path();
86 xs__execv_git_cmd(...)
92 argv = malloc(sizeof(const char *) * (items + 1));
94 croak("malloc failed");
95 for (i = 0; i < items; i++)
96 argv[i] = strdup(SvPV_nolen(ST(i)));
101 for (i = 0; i < items; i++)
103 free((char *) argv[i]);
104 free((char **) argv);
108 xs_hash_object(file, type = "blob")
113 unsigned char sha1[20];
115 if (SvTYPE(file) == SVt_RV)
118 if (SvTYPE(file) == SVt_PVGV) {
122 pio = IoIFP(sv_2io(file));
124 croak("You passed me something weird - a dir glob?");
125 /* XXX: I just hope PerlIO didn't read anything from it yet.
127 if (index_pipe(sha1, PerlIO_fileno(pio), type, 0))
128 croak("Unable to hash given filehandle");
129 /* Avoid any nasty surprises. */
134 char *path = SvPV_nolen(file);
135 int fd = open(path, O_RDONLY);
139 fstat(fd, &st) < 0 ||
140 index_fd(sha1, fd, &st, 0, type))
141 croak("Unable to hash %s", path);
144 RETVAL = sha1_to_hex(sha1);