refs: use same lock_file object for both ref-packing functions

Use a single struct lock_file for both pack_refs() and
repack_without_ref().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2013-04-22 21:52:34 +02:00 коммит произвёл Junio C Hamano
Родитель 3b4ae6d502
Коммит d947033037
1 изменённых файлов: 4 добавлений и 6 удалений

10
refs.c
Просмотреть файл

@ -2092,7 +2092,7 @@ static void prune_refs(struct ref_to_prune *r)
} }
} }
static struct lock_file packed; static struct lock_file packlock;
int pack_refs(unsigned int flags) int pack_refs(unsigned int flags)
{ {
@ -2102,7 +2102,7 @@ int pack_refs(unsigned int flags)
memset(&cbdata, 0, sizeof(cbdata)); memset(&cbdata, 0, sizeof(cbdata));
cbdata.flags = flags; cbdata.flags = flags;
fd = hold_lock_file_for_update(&packed, git_path("packed-refs"), fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"),
LOCK_DIE_ON_ERROR); LOCK_DIE_ON_ERROR);
cbdata.refs_file = fdopen(fd, "w"); cbdata.refs_file = fdopen(fd, "w");
if (!cbdata.refs_file) if (!cbdata.refs_file)
@ -2121,8 +2121,8 @@ int pack_refs(unsigned int flags)
* assign -1 to the lock file descriptor so that commit_lock_file() * assign -1 to the lock file descriptor so that commit_lock_file()
* won't try to close() it. * won't try to close() it.
*/ */
packed.fd = -1; packlock.fd = -1;
if (commit_lock_file(&packed) < 0) if (commit_lock_file(&packlock) < 0)
die_errno("unable to overwrite old ref-pack file"); die_errno("unable to overwrite old ref-pack file");
prune_refs(cbdata.ref_to_prune); prune_refs(cbdata.ref_to_prune);
return 0; return 0;
@ -2176,8 +2176,6 @@ static int repack_ref_fn(struct ref_entry *entry, void *cb_data)
return 0; return 0;
} }
static struct lock_file packlock;
static int repack_without_ref(const char *refname) static int repack_without_ref(const char *refname)
{ {
int fd; int fd;