diff options
Diffstat (limited to 'refs')
-rw-r--r-- | refs/files-backend.c | 37 | ||||
-rw-r--r-- | refs/packed-backend.c | 1 | ||||
-rw-r--r-- | refs/refs-internal.h | 9 |
3 files changed, 20 insertions, 27 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c index a9a066dcfb..1f1a98e4cb 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -363,7 +363,7 @@ stat_ref: /* Follow "normalized" - ie "refs/.." symlinks by hand */ if (S_ISLNK(st.st_mode)) { strbuf_reset(&sb_contents); - if (strbuf_readlink(&sb_contents, path, 0) < 0) { + if (strbuf_readlink(&sb_contents, path, st.st_size) < 0) { if (errno == ENOENT || errno == EINVAL) /* inconsistent with lstat; retry */ goto stat_ref; @@ -1582,26 +1582,17 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid, const struct object_id *new_oid, const char *committer, const char *msg) { - int msglen, written; - unsigned maxlen, len; - char *logrec; - - msglen = msg ? strlen(msg) : 0; - maxlen = strlen(committer) + msglen + 100; - logrec = xmalloc(maxlen); - len = xsnprintf(logrec, maxlen, "%s %s %s\n", - oid_to_hex(old_oid), - oid_to_hex(new_oid), - committer); - if (msglen) - len += copy_reflog_msg(logrec + len - 1, msg) - 1; - - written = len <= maxlen ? write_in_full(fd, logrec, len) : -1; - free(logrec); - if (written < 0) - return -1; + struct strbuf sb = STRBUF_INIT; + int ret = 0; - return 0; + strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer); + if (msg && *msg) + copy_reflog_msg(&sb, msg); + strbuf_addch(&sb, '\n'); + if (write_in_full(fd, sb.buf, sb.len) < 0) + ret = -1; + strbuf_release(&sb); + return ret; } static int files_log_ref_write(struct files_ref_store *refs, @@ -1660,7 +1651,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock, struct object *o; int fd; - o = parse_object(oid); + o = parse_object(the_repository, oid); if (!o) { strbuf_addf(err, "trying to write ref '%s' with nonexistent object %s", @@ -1676,7 +1667,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock, return -1; } fd = get_lock_file_fd(&lock->lk); - if (write_in_full(fd, oid_to_hex(oid), GIT_SHA1_HEXSZ) < 0 || + if (write_in_full(fd, oid_to_hex(oid), the_hash_algo->hexsz) < 0 || write_in_full(fd, &term, 1) < 0 || close_ref_gently(lock) < 0) { strbuf_addf(err, @@ -3070,7 +3061,7 @@ static int files_reflog_expire(struct ref_store *ref_store, rollback_lock_file(&reflog_lock); } else if (update && (write_in_full(get_lock_file_fd(&lock->lk), - oid_to_hex(&cb.last_kept_oid), GIT_SHA1_HEXSZ) < 0 || + oid_to_hex(&cb.last_kept_oid), the_hash_algo->hexsz) < 0 || write_str_in_full(get_lock_file_fd(&lock->lk), "\n") < 0 || close_ref_gently(lock) < 0)) { status |= error("couldn't write %s", diff --git a/refs/packed-backend.c b/refs/packed-backend.c index cec3fb9e00..d447a731da 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -499,6 +499,7 @@ static int load_contents(struct snapshot *snapshot) size = xsize_t(st.st_size); if (!size) { + close(fd); return 0; } else if (mmap_strategy == MMAP_NONE || size <= SMALL_FILE_SIZE) { snapshot->buf = xmalloc(size); diff --git a/refs/refs-internal.h b/refs/refs-internal.h index dd834314bd..04425d6d1e 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -1,6 +1,8 @@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H +#include "iterator.h" + /* * Data structures and functions for the internal use of the refs * module. Code outside of the refs module should use only the public @@ -91,11 +93,10 @@ enum peel_status { enum peel_status peel_object(const struct object_id *name, struct object_id *oid); /* - * Copy the reflog message msg to buf, which has been allocated sufficiently - * large, while cleaning up the whitespaces. Especially, convert LF to space, - * because reflog file is one line per entry. + * Copy the reflog message msg to sb while cleaning up the whitespaces. + * Especially, convert LF to space, because reflog file is one line per entry. */ -int copy_reflog_msg(char *buf, const char *msg); +void copy_reflog_msg(struct strbuf *sb, const char *msg); /** * Information needed for a single ref update. Set new_oid to the new |