From: Patrick Steinhardt <ps@pks.im>
To: Justin Tobler <jltobler@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3 3/4] object-file: explicitly write ".keep" lockfile
Date: Tue, 20 Oct 2026 16:26:42 +0200 [thread overview]
Message-ID: <atd6IjqH8F_O44gP@pks.im> (raw)
In-Reply-To: <20261020132900.1208343-4-jltobler@gmail.com>
On Tue, Oct 20, 2026 at 08:28:59AM -0500, Justin Tobler wrote:
> diff --git a/object-file.c b/object-file.c
> index 210984f825..ad55c01198 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -1256,6 +1256,45 @@ int read_loose_object(struct repository *repo,
> return ret;
> }
>
> +static int write_pack_lockfile(struct odb_source *source, const char *pack_name,
> + const char *keep_msg)
> +{
> + struct strbuf lock_path = STRBUF_INIT;
> + struct strbuf contents = STRBUF_INIT;
> + int ret = 0;
> + int fd;
Hum, not quite what I meant :P I'd leave the variable explicitly
uninitialized and then set it on all exit paths. Like that, the compiler
(or at least most common compilers) would warn for all code paths where
we don't set the error code. So:
int ret;
> + strbuf_addf(&lock_path, "%s/pack/pack-%s.keep",
> + source->path, pack_name);
> + strbuf_addf(&contents, "%s\n", keep_msg);
> +
> + fd = safe_create_file_with_leading_directories(source->odb->repo,
> + lock_path.buf);
> + if (fd < 0) {
> + ret = error_errno(_("unable to create '%s'"), lock_path.buf);
> + goto out;
> + }
> +
> + if (write_in_full(fd, contents.buf, contents.len) < 0) {
> + ret = error_errno(_("unable to write '%s'"), lock_path.buf);
> + close(fd);
> + unlink(lock_path.buf);
> + goto out;
> + }
> +
> + if (close(fd) < 0) {
> + ret = error_errno(_("unable to close '%s'"), lock_path.buf);
> + unlink(lock_path.buf);
> + goto out;
> + }
> +
and then:
ret = 0;
> +out:
> + strbuf_release(&lock_path);
> + strbuf_release(&contents);
> +
> + return ret;
> +}
> +
> static int odb_transaction_files_commit(struct odb_transaction *base)
> {
> struct odb_transaction_files *transaction =
Thanks!
Patrick
next prev parent reply other threads:[~2026-10-20 14:26 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 2:28 [PATCH 0/3] object-file: fix ".keep" lockfile ownership in ODB transactions Justin Tobler
2026-10-16 2:28 ` [PATCH 1/3] pack-write: lift and expose index-pack report parsing Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 17:30 ` Justin Tobler
2026-10-16 2:29 ` [PATCH 2/3] object-file: explicitly write ".keep" lockfile Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 18:37 ` Justin Tobler
2026-10-16 2:29 ` [PATCH 3/3] object-file: write ".keep" lockfiles during transaction commit Justin Tobler
2026-10-16 6:58 ` Patrick Steinhardt
2026-10-16 19:22 ` Justin Tobler
2026-10-16 21:37 ` [PATCH v2 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions Justin Tobler
2026-10-16 21:37 ` [PATCH v2 1/4] pack-write: make index-pack output comment hash agnostic Justin Tobler
2026-10-16 21:37 ` [PATCH v2 2/4] pack-write: lift and expose index-pack report parsing Justin Tobler
2026-10-16 21:37 ` [PATCH v2 3/4] object-file: explicitly write ".keep" lockfile Justin Tobler
2026-10-19 6:14 ` Patrick Steinhardt
2026-10-19 21:44 ` Justin Tobler
2026-10-16 21:37 ` [PATCH v2 4/4] object-file: write ".keep" lockfiles during transaction commit Justin Tobler
2026-10-19 6:14 ` Patrick Steinhardt
2026-10-20 13:28 ` [PATCH v3 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions Justin Tobler
2026-10-20 13:28 ` [PATCH v3 1/4] pack-write: make index-pack output comment hash agnostic Justin Tobler
2026-10-20 13:28 ` [PATCH v3 2/4] pack-write: lift and expose index-pack report parsing Justin Tobler
2026-10-20 13:28 ` [PATCH v3 3/4] object-file: explicitly write ".keep" lockfile Justin Tobler
2026-10-20 14:26 ` Patrick Steinhardt [this message]
2026-10-20 13:29 ` [PATCH v3 4/4] object-file: write ".keep" lockfiles during transaction commit Justin Tobler
2026-10-20 14:15 ` [PATCH v3 0/4] object-file: fix ".keep" lockfile ownership in ODB transactions Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atd6IjqH8F_O44gP@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox