From: shejialuo <shejialuo@gmail.com>
To: Caleb White <cdwhite3@pm.me>
Cc: Eric Sunshine <sunshine@sunshineco.com>, git@vger.kernel.org
Subject: Re: [PATCH v2 1/4] worktree: refactor infer_backlink() to use *strbuf
Date: Mon, 7 Oct 2024 12:12:40 +0800 [thread overview]
Message-ID: <ZwNfuLoVn4aU4mgQ@ArchLinux> (raw)
In-Reply-To: <o7jQV4JUYr2iQtErKFhCrjCySiGn7_I18gmdInKbOC9TAsvqazG0O_fPUtiWZ5UfiGLr25OZ5xvqIhfOIwCG-s1RGgri-BJIdHqiokIw4z0=@pm.me>
On Mon, Oct 07, 2024 at 02:26:51AM +0000, Caleb White wrote:
> On Sunday, October 6th, 2024 at 13:41, Eric Sunshine <sunshine@sunshineco.com> wrote:
> > I found the name "git_contents" clear enough and understood its
> > purpose at-a-glance, so I think it's a reasonably good choice. A
> > slightly better name might be "gitfile_contents" or perhaps
> > "dotgit_contents" for consistency with other similarly-named variables
> > in this function.
>
> I will rename to `dotgit_contents`.
>
> > It certainly makes sense to check whether "git_contents" is NULL
> > before trying to copy it into the "backlink" strbuf, however, if
> > "git_contents" is NULL here, then what does that mean? What does it
> > mean to leave "backlink" empty? The only way (presumably) we get this
> > far is if read_gitfile_gently() succeeded, so (presumably)
> > "git_contents" should not be NULL. Thus, rather than conditionally
> > copying into "backlink", we should instead indicate clearly via BUG()
> > that it should be impossible for "git_contents" to be NULL. So, rather
> > than making this part of the existing if-else-cascade, we should do
> > this as a standalone `if`:
> >
>
> > if (!git_contents)
> > BUG(...);
> > strbuf_addstr(&backlink, git_contents);
I agree with the idea that Eric proposed. It's truly we should raise a
bug here. That's would be much more clear.
> We can't use BUG because this is handled as part of the err
> conditions. The contents can be NULL and `backlink` could be
> filled with the inferred backlink. I moved this to the top
> and I think it reads better.
That's not correct. It is true that the contents can be NULL and
`backlink` could be filled with the infer_backlink. But do you notice
that if `backlink` was filled with the infer_backlink, it will jump
to the "done" label.
What Erie means is the following:
git_contents = read_gitfile_gently(...);
if (err) {
if (...) {
} else if (err == RAED_GITFILE_ERR_NOT_A_REPO) {
// handle backlink
goto done;
}
}
if (!git_contents)
BUG(...);
strbuf_addstr(&backlink, git_contents);
done:
// cleanup operations
Thanks,
Jialuo
next prev parent reply other threads:[~2024-10-07 4:12 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-06 6:00 [PATCH v2 0/4] Link worktrees with relative paths Caleb White
2024-10-06 6:00 ` [PATCH v2 1/4] worktree: refactor infer_backlink() to use *strbuf Caleb White
2024-10-06 15:09 ` shejialuo
2024-10-06 15:13 ` Kristoffer Haugsbakk
2024-10-06 18:41 ` Eric Sunshine
2024-10-07 2:26 ` Caleb White
2024-10-07 4:12 ` shejialuo [this message]
2024-10-07 4:19 ` Caleb White
2024-10-07 4:28 ` shejialuo
2024-10-07 4:31 ` Caleb White
2024-10-07 3:56 ` shejialuo
2024-10-07 4:01 ` Caleb White
2024-10-07 4:19 ` shejialuo
2024-10-06 23:47 ` Caleb White
2024-10-06 18:16 ` Eric Sunshine
2024-10-07 2:42 ` Caleb White
2024-10-07 3:26 ` Eric Sunshine
2024-10-07 3:28 ` Caleb White
2024-10-06 6:01 ` [PATCH v2 2/4] worktree: link worktrees with relative paths Caleb White
2024-10-06 11:05 ` Eric Sunshine
2024-10-06 22:37 ` Caleb White
2024-10-06 15:37 ` shejialuo
2024-10-06 23:57 ` Caleb White
2024-10-07 3:45 ` shejialuo
2024-10-07 4:02 ` Eric Sunshine
2024-10-07 16:59 ` Caleb White
2024-10-06 6:01 ` [PATCH v2 3/4] worktree: sync worktree paths after gitdir move Caleb White
2024-10-06 11:12 ` Eric Sunshine
2024-10-06 22:41 ` Caleb White
2024-10-06 22:48 ` Eric Sunshine
2024-10-06 23:13 ` Caleb White
2024-10-06 23:27 ` Eric Sunshine
2024-10-06 6:01 ` [PATCH v2 4/4] worktree: prevent null pointer dereference Caleb White
2024-10-06 11:24 ` Eric Sunshine
2024-10-06 23:03 ` Caleb White
2024-10-06 23:24 ` Eric Sunshine
2024-10-07 3:09 ` Caleb White
2024-10-06 6:18 ` [PATCH v2 0/4] Link worktrees with relative paths Eric Sunshine
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=ZwNfuLoVn4aU4mgQ@ArchLinux \
--to=shejialuo@gmail.com \
--cc=cdwhite3@pm.me \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.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;
as well as URLs for NNTP newsgroup(s).