summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2013-04-22 19:52:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-05-01 22:33:10 (GMT)
commitfec3137ffcc49d58e6388b1c61da902b031e01ca (patch)
tree06733ad63065038b746a6f296cbf9506bbe90235 /refs.c
parent694b7a1999fa331e00ed9297f3b6b01f7da7a104 (diff)
downloadgit-fec3137ffcc49d58e6388b1c61da902b031e01ca.zip
git-fec3137ffcc49d58e6388b1c61da902b031e01ca.tar.gz
git-fec3137ffcc49d58e6388b1c61da902b031e01ca.tar.bz2
refs: extract a function write_packed_entry()
Extract the I/O code from the "business logic" in repack_ref_fn(). Later there will be another caller for this function. 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.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/refs.c b/refs.c
index 6032ba6..e09c045 100644
--- a/refs.c
+++ b/refs.c
@@ -1959,12 +1959,36 @@ struct ref_lock *lock_any_ref_for_update(const char *refname,
return lock_ref_sha1_basic(refname, old_sha1, flags, NULL);
}
-static int repack_ref_fn(struct ref_entry *entry, void *cb_data)
+/*
+ * Write an entry to the packed-refs file for the specified refname.
+ * If peeled is non-NULL, write it as the entry's peeled value.
+ */
+static void write_packed_entry(int fd, char *refname, unsigned char *sha1,
+ unsigned char *peeled)
{
- int *fd = cb_data;
char line[PATH_MAX + 100];
int len;
+ len = snprintf(line, sizeof(line), "%s %s\n",
+ sha1_to_hex(sha1), refname);
+ /* this should not happen but just being defensive */
+ if (len > sizeof(line))
+ die("too long a refname '%s'", refname);
+ write_or_die(fd, line, len);
+
+ if (peeled) {
+ if (snprintf(line, sizeof(line), "^%s\n",
+ sha1_to_hex(peeled)) != PEELED_LINE_LENGTH)
+ die("internal error");
+ write_or_die(fd, line, PEELED_LINE_LENGTH);
+ }
+}
+
+static int repack_ref_fn(struct ref_entry *entry, void *cb_data)
+{
+ int *fd = cb_data;
+ enum peel_status peel_status;
+
if (entry->flag & REF_ISBROKEN) {
/* This shouldn't happen to packed refs. */
error("%s is broken!", entry->name);
@@ -2000,20 +2024,10 @@ static int repack_ref_fn(struct ref_entry *entry, void *cb_data)
return 0;
}
- len = snprintf(line, sizeof(line), "%s %s\n",
- sha1_to_hex(entry->u.value.sha1), entry->name);
- /* this should not happen but just being defensive */
- if (len > sizeof(line))
- die("too long a refname '%s'", entry->name);
- write_or_die(*fd, line, len);
- if (!peel_entry(entry)) {
- /* This reference could be peeled; write the peeled value: */
- if (snprintf(line, sizeof(line), "^%s\n",
- sha1_to_hex(entry->u.value.peeled)) !=
- PEELED_LINE_LENGTH)
- die("internal error");
- write_or_die(*fd, line, PEELED_LINE_LENGTH);
- }
+ peel_status = peel_entry(entry);
+ write_packed_entry(*fd, entry->name, entry->u.value.sha1,
+ peel_status == PEEL_PEELED ?
+ entry->u.value.peeled : NULL);
return 0;
}