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 /* XS and Perl interface */
18 report_xs(const char *prefix, const char *err, va_list params)
20 static char buf[4096];
22 vsnprintf(buf + strlen(prefix), 4096 - strlen(prefix), err, params);
27 die_xs(const char *err, va_list params)
30 str = report_xs("fatal: ", err, params);
35 error_xs(const char *err, va_list params)
38 str = report_xs("error: ", err, params);
43 MODULE = Git PACKAGE = Git
50 set_error_routine(error_xs);
51 set_die_routine(die_xs);
56 xs__call_gate(repoid, git_dir)
61 static long last_repoid;
62 if (repoid != last_repoid) {
64 getenv(DB_ENVIRONMENT),
65 getenv(INDEX_ENVIRONMENT),
66 getenv(GRAFT_ENVIRONMENT));
86 RETVAL = (char *)git_exec_path();
93 xs__execv_git_cmd(...)
99 argv = malloc(sizeof(const char *) * (items + 1));
101 croak("malloc failed");
102 for (i = 0; i < items; i++)
103 argv[i] = strdup(SvPV_nolen(ST(i)));
108 for (i = 0; i < items; i++)
110 free((char *) argv[i]);
111 free((char **) argv);
116 xs_get_object(type, id)
121 unsigned char sha1[20];
125 if (strlen(id) != 40 || get_sha1_hex(id, sha1) < 0)
128 buf = read_sha1_file(sha1, type, &size);
131 RETVAL = newSVpvn(buf, size);
139 xs_hash_object_pipe(type, fd)
144 unsigned char sha1[20];
146 if (index_pipe(sha1, fd, type, 0))
147 croak("Unable to hash given filehandle");
148 RETVAL = sha1_to_hex(sha1);
154 xs_hash_object_file(type, path)
159 unsigned char sha1[20];
160 int fd = open(path, O_RDONLY);
164 fstat(fd, &st) < 0 ||
165 index_fd(sha1, fd, &st, 0, type))
166 croak("Unable to hash %s", path);
169 RETVAL = sha1_to_hex(sha1);