+ SHA1_Final(pack_data->sha1, &ctx);
+ return tmpfile;
+}
+
+static char* keep_pack(char *curr_index_name)
+{
+ static char name[PATH_MAX];
+ static char *keep_msg = "fast-import";
+ int keep_fd;
+
+ chmod(pack_data->pack_name, 0444);
+ chmod(curr_index_name, 0444);
+
+ snprintf(name, sizeof(name), "%s/pack/pack-%s.keep",
+ get_object_directory(), sha1_to_hex(pack_data->sha1));
+ keep_fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+ if (keep_fd < 0)
+ die("cannot create keep file");
+ write(keep_fd, keep_msg, strlen(keep_msg));
+ close(keep_fd);
+
+ snprintf(name, sizeof(name), "%s/pack/pack-%s.pack",
+ get_object_directory(), sha1_to_hex(pack_data->sha1));
+ if (move_temp_to_file(pack_data->pack_name, name))
+ die("cannot store pack file");
+ printf("%s\n", name);
+
+ snprintf(name, sizeof(name), "%s/pack/pack-%s.idx",
+ get_object_directory(), sha1_to_hex(pack_data->sha1));
+ if (move_temp_to_file(curr_index_name, name))
+ die("cannot store index file");
+ return name;
+}
+
+static void unkeep_all_packs()
+{
+ static char name[PATH_MAX];
+ int k;
+
+ for (k = 0; k < pack_id; k++) {
+ struct packed_git *p = all_packs[k];
+ snprintf(name, sizeof(name), "%s/pack/pack-%s.keep",
+ get_object_directory(), sha1_to_hex(p->sha1));
+ unlink(name);
+ }