summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2013-04-22 21:52:38 +0200
committerJunio C Hamano <gitster@pobox.com>2013-05-01 15:33:11 -0700
commit0f29920f1e0ce00aaf867fdd9ad2174011179f47 (patch)
treee6bd573489e7304a1946dff9ca93f260495e5bc3 /refs.c
parentf85354b5c7b800912743927f4abba022444163fd (diff)
downloadgit-0f29920f1e0ce00aaf867fdd9ad2174011179f47.tar.gz
pack_one_ref(): use write_packed_entry() to do the writing
Change pack_refs() to work with a file descriptor instead of a FILE* (making the file-locking code less awkward) and use write_packed_entry() to do the writing. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/refs.c b/refs.c
index 7e4aca95bb..00174e9498 100644
--- a/refs.c
+++ b/refs.c
@@ -2001,7 +2001,7 @@ struct ref_to_prune {
struct pack_refs_cb_data {
unsigned int flags;
struct ref_to_prune *ref_to_prune;
- FILE *refs_file;
+ int fd;
};
static int pack_one_ref(struct ref_entry *entry, void *cb_data)
@@ -2020,15 +2020,13 @@ static int pack_one_ref(struct ref_entry *entry, void *cb_data)
!(entry->flag & REF_ISPACKED))
return 0;
- fprintf(cb->refs_file, "%s %s\n", sha1_to_hex(entry->u.value.sha1),
- entry->name);
-
peel_status = peel_entry(entry, 1);
- if (peel_status == PEEL_PEELED)
- fprintf(cb->refs_file, "^%s\n", sha1_to_hex(entry->u.value.peeled));
- else if (peel_status != PEEL_NON_TAG)
+ if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)
die("internal error peeling reference %s (%s)",
entry->name, sha1_to_hex(entry->u.value.sha1));
+ write_packed_entry(cb->fd, entry->name, entry->u.value.sha1,
+ peel_status == PEEL_PEELED ?
+ entry->u.value.peeled : NULL);
/* If the ref was already packed, there is no need to prune it. */
if ((cb->flags & PACK_REFS_PRUNE) && !(entry->flag & REF_ISPACKED)) {
@@ -2097,32 +2095,17 @@ static struct lock_file packlock;
int pack_refs(unsigned int flags)
{
- int fd;
struct pack_refs_cb_data cbdata;
memset(&cbdata, 0, sizeof(cbdata));
cbdata.flags = flags;
- fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"),
- LOCK_DIE_ON_ERROR);
- cbdata.refs_file = fdopen(fd, "w");
- if (!cbdata.refs_file)
- die_errno("unable to create ref-pack file structure");
+ cbdata.fd = hold_lock_file_for_update(&packlock, git_path("packed-refs"),
+ LOCK_DIE_ON_ERROR);
- /* perhaps other traits later as well */
- fprintf(cbdata.refs_file, "# pack-refs with: peeled fully-peeled \n");
+ write_or_die(cbdata.fd, PACKED_REFS_HEADER, strlen(PACKED_REFS_HEADER));
do_for_each_entry(NULL, "", pack_one_ref, &cbdata);
- if (ferror(cbdata.refs_file))
- die("failed to write ref-pack file");
- if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file))
- die_errno("failed to write ref-pack file");
- /*
- * Since the lock file was fdopen()'ed and then fclose()'ed above,
- * assign -1 to the lock file descriptor so that commit_lock_file()
- * won't try to close() it.
- */
- packlock.fd = -1;
if (commit_lock_file(&packlock) < 0)
die_errno("unable to overwrite old ref-pack file");
prune_refs(cbdata.ref_to_prune);