Message ID | d46a4e701620704ae3fd203c9d9dffb172cb3804.1615228580.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Fix all leaks in t0001 | expand |
On Mon, Mar 08, 2021 at 06:36:17PM +0000, Andrzej Hunt via GitGitGadget wrote: > Make sure that we release the temporary strbuf during dwim_branch() for > all codepaths (and not just for the early return). Makes sense. Two style nits: > static const char *dwim_branch(const char *path, const char **new_branch) > { > - int n; > + int n, branch_exists; If two variables aren't strictly related, but just happen to share the same type, IMHO it's better to declare them separately. (There are numerous spots in Git's code that don't follow this rule, but I think we should be moving in that direction). > - if (!strbuf_check_branch_ref(&ref, branchname) && > - ref_exists(ref.buf)) { > - strbuf_release(&ref); > + > + branch_exists = (!strbuf_check_branch_ref(&ref, branchname) && > + ref_exists(ref.buf)); We'd usually omit the extra parentheses here. I.e.,: branch_exists = !strbuf_check_branch_ref(&ref, branchname) && ref_exists(ref.buf); -Peff
On 08/03/2021 20:16, Jeff King wrote: > On Mon, Mar 08, 2021 at 06:36:17PM +0000, Andrzej Hunt via GitGitGadget wrote: > >> Make sure that we release the temporary strbuf during dwim_branch() for >> all codepaths (and not just for the early return). > > Makes sense. Two style nits: Thank, I'll fix both. > >> - if (!strbuf_check_branch_ref(&ref, branchname) && >> - ref_exists(ref.buf)) { >> - strbuf_release(&ref); >> + >> + branch_exists = (!strbuf_check_branch_ref(&ref, branchname) && >> + ref_exists(ref.buf)); > > We'd usually omit the extra parentheses here. I.e.,: > > branch_exists = !strbuf_check_branch_ref(&ref, branchname) && > ref_exists(ref.buf); I've made this change - but I have a question about the formatting: - In the few examples that I could find, the second line is aligned using spaces (i.e. same number of tabs as the previous line, followed by spaces to align correctly). However that appears to violate the indent-with-non-tab style check - should I switch to 100% tabs instead? That check has been around since: e2f6331a14 (.gitattributes: CR at the end of the line is an error, 2009-06-19) So maybe it's being intentionally ignored in the cases that I've seen (I only noticed it for my series because of the automated checks on Github) - but I thought I should ask to sure.
diff --git a/builtin/worktree.c b/builtin/worktree.c index 1cd5c2016e3f..44d3f058d065 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -445,17 +445,17 @@ static void print_preparing_worktree_line(int detach, static const char *dwim_branch(const char *path, const char **new_branch) { - int n; + int n, branch_exists; const char *s = worktree_basename(path, &n); const char *branchname = xstrndup(s, n); struct strbuf ref = STRBUF_INIT; - UNLEAK(branchname); - if (!strbuf_check_branch_ref(&ref, branchname) && - ref_exists(ref.buf)) { - strbuf_release(&ref); + + branch_exists = (!strbuf_check_branch_ref(&ref, branchname) && + ref_exists(ref.buf)); + strbuf_release(&ref); + if (branch_exists) return branchname; - } *new_branch = branchname; if (guess_remote) {