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 */
22 report_xs(const char *prefix, const char *err, va_list params)
24 static char buf[4096];
26 vsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params);
31 die_xs(const char *err, va_list params)
34 str = report_xs("fatal: ", err, params);
39 error_xs(const char *err, va_list params)
42 str = report_xs("error: ", err, params);
47 MODULE = Git PACKAGE = Git
54 set_error_routine(error_xs);
55 set_die_routine(die_xs);
59 # /* TODO: xs_call_gate(). See Git.pm. */
76 RETVAL = (char *)git_exec_path();
83 xs__execv_git_cmd(...)
89 argv = malloc(sizeof(const char *) * (items + 1));
91 croak("malloc failed");
92 for (i = 0; i < items; i++)
93 argv[i] = strdup(SvPV_nolen(ST(i)));
98 for (i = 0; i < items; i++)
100 free((char *) argv[i]);
101 free((char **) argv);
105 xs_hash_object_pipe(type, fd)
110 unsigned char sha1[20];
112 if (index_pipe(sha1, fd, type, 0))
113 croak("Unable to hash given filehandle");
114 RETVAL = sha1_to_hex(sha1);
120 xs_hash_object_file(type, path)
125 unsigned char sha1[20];
126 int fd = open(path, O_RDONLY);
130 fstat(fd, &st) < 0 ||
131 index_fd(sha1, fd, &st, 0, type))
132 croak("Unable to hash %s", path);
135 RETVAL = sha1_to_hex(sha1);