+ if (use_filecopy) {
+ int ifd, ofd, status;
+ struct stat st;
+ void *map;
+ ifd = open(filename, O_RDONLY);
+ if (ifd < 0 || fstat(ifd, &st) < 0) {
+ close(ifd);
+ fprintf(stderr, "cannot open %s\n", filename);
+ return -1;
+ }
+ map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
+ close(ifd);
+ if (map == MAP_FAILED) {
+ fprintf(stderr, "cannot mmap %s\n", filename);
+ return -1;
+ }
+ ofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ status = ((ofd < 0) ||
+ (write(ofd, map, st.st_size) != st.st_size));
+ munmap(map, st.st_size);
+ close(ofd);
+ if (status)
+ fprintf(stderr, "cannot write %s\n", dest_filename);
+ else
+ pull_say("copy %s\n", hex);
+ return status;
+ }
+ fprintf(stderr, "failed to copy %s with given copy methods.\n", hex);
+ return -1;
+}
+
+int fetch_ref(char *ref, unsigned char *sha1)
+{
+ static int ref_name_start = -1;
+ static char filename[PATH_MAX];
+ static char hex[41];
+ int ifd;
+
+ if (ref_name_start < 0) {
+ sprintf(filename, "%s/refs/", path);
+ ref_name_start = strlen(filename);
+ }
+ strcpy(filename + ref_name_start, ref);