4 static const char *result_path, *lock_path;
6 static void remove_lock_file(void)
12 static int handle_one_ref(const char *path, const unsigned char *sha1,
13 int flags, void *cb_data)
15 FILE *refs_file = cb_data;
17 fprintf(refs_file, "%s %s\n", sha1_to_hex(sha1), path);
21 int cmd_pack_refs(int argc, const char **argv, const char *prefix)
26 result_path = xstrdup(git_path("packed-refs"));
27 lock_path = xstrdup(mkpath("%s.lock", result_path));
29 fd = open(lock_path, O_CREAT | O_EXCL | O_WRONLY, 0666);
31 die("unable to create new ref-pack file (%s)", strerror(errno));
32 atexit(remove_lock_file);
34 refs_file = fdopen(fd, "w");
36 die("unable to create ref-pack file structure (%s)", strerror(errno));
37 for_each_ref(handle_one_ref, refs_file);
40 if (rename(lock_path, result_path) < 0)
41 die("unable to overwrite old ref-pack file (%s)", strerror(errno));