+ ref = buf + 11;
+ } else {
+ if (pipe(p) == -1) {
+ fprintf(stderr, "pipe failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ pid_t pid4 = fork();
+ if (pid4 == -1) {
+ fprintf(stderr, "fork failed: %s\n", strerror(errno));
+ return 1;
+ }
+ if (pid4 == 0) {
+ char* args[] = {"git", "rev-parse", "HEAD", NULL};
+ if (dup2(p[1], 1) == -1) {
+ fprintf(stderr, "dup2 failed: %s\n", strerror(errno));
+ }
+ execvp(args[0], args);
+ return 1;
+ }
+
+ close(p[1]);
+
+ while (waitpid(pid4, &status, 0) < 0) {
+ if (errno != EINTR) {
+ fprintf(stderr, "waitpid failed: %s\n", strerror(errno));
+ return 1;
+ }
+ }
+ if (WEXITSTATUS(status) == 0) {
+ ssize_t bytes = read(p[0], buf, sizeof(buf));
+ if (bytes < 0) {
+ fprintf(stderr, "read failed: %s\n", strerror(errno));
+ return 1;
+ }
+ buf[short_hash_length] = '\0';
+ ref = buf;
+ }