mirror of
https://github.com/git/git.git
synced 2024-11-20 12:13:59 +01:00
13e4aa90ac
Now we can tell which one is symbolic and which one is not, it is easy to do so. Signed-off-by: Junio C Hamano <junkio@cox.net>
47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
#include "cache.h"
|
|
#include "refs.h"
|
|
|
|
static const char *result_path, *lock_path;
|
|
|
|
static void remove_lock_file(void)
|
|
{
|
|
if (lock_path)
|
|
unlink(lock_path);
|
|
}
|
|
|
|
static int handle_one_ref(const char *path, const unsigned char *sha1,
|
|
int flags, void *cb_data)
|
|
{
|
|
FILE *refs_file = cb_data;
|
|
|
|
/* Do not pack the symbolic refs */
|
|
if (!(flags & REF_ISSYMREF))
|
|
fprintf(refs_file, "%s %s\n", sha1_to_hex(sha1), path);
|
|
return 0;
|
|
}
|
|
|
|
int cmd_pack_refs(int argc, const char **argv, const char *prefix)
|
|
{
|
|
int fd;
|
|
FILE *refs_file;
|
|
|
|
result_path = xstrdup(git_path("packed-refs"));
|
|
lock_path = xstrdup(mkpath("%s.lock", result_path));
|
|
|
|
fd = open(lock_path, O_CREAT | O_EXCL | O_WRONLY, 0666);
|
|
if (fd < 0)
|
|
die("unable to create new ref-pack file (%s)", strerror(errno));
|
|
atexit(remove_lock_file);
|
|
|
|
refs_file = fdopen(fd, "w");
|
|
if (!refs_file)
|
|
die("unable to create ref-pack file structure (%s)", strerror(errno));
|
|
for_each_ref(handle_one_ref, refs_file);
|
|
fsync(fd);
|
|
fclose(refs_file);
|
|
if (rename(lock_path, result_path) < 0)
|
|
die("unable to overwrite old ref-pack file (%s)", strerror(errno));
|
|
lock_path = NULL;
|
|
return 0;
|
|
}
|