git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Hariom verma <hariom18599@gmail.com>
Subject: Re: [PATCH] worktree: avoid dead-code in conditional
Date: Wed, 24 Jun 2020 19:00:37 -0400	[thread overview]
Message-ID: <CAPig+cRdRyWAjU7QADPt39rDgJ4njDtN_pwo8JMVD=YX09a-Vg@mail.gmail.com> (raw)
In-Reply-To: <xmqqsgek5fg3.fsf@gitster.c.googlers.com>

On Wed, Jun 24, 2020 at 5:20 PM Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > get_worktrees() retrieves a list of all worktrees associated with a
> > repository, including the main worktree. The location of the main
> > worktree is determined by get_main_worktree() which needs to handle
> > three distinct cases for the main worktree after absolute-path
> > conversion:
> >
> >   * <bare-repository>/.
> >   * <main-worktree>/.git/. (when $CWD is .git)
> >   * <main-worktree>/.git (when $CWD is any worktree)
>
> It is unclear from the above but I would assume that you are talking
> about the returned path from get_git_common_dir().

No, I am talking about the result of strbuf_add_absolute_path()
applied to get_git_common_dir(). I intentionally explicitly stated
"after absolute-path conversion" in the commit message to be clear
about this, but perhaps I should have mentioned
strbuf_add_absolute_path() by name to avoid confusion.

> I can certainly understand why there needs two distinct cases
> (i.e.. bare vs non-bare), but why is this codepath (or any caller of
> get_git_common_dir()) forced to care about the two cases?

Callers of get_git_common_dir() aren't forced to care. But after
applying strbuf_add_absolute_path() we are forced to care. This is the
result of get_git_common_dir() for the three cases:

    .     (within bare repo)
    .git  (within any worktree)
    .     (within .git)

After applying strbuf_add_absolute_path(), we get:

    /whatever/proj.git/.   (within bare proj)
    /whatever/proj/.git    (within any worktree)
    /whatever/proj/.git/.  (within .git)

These need to be normalized, respectively, to:

    /whatever/proj.git  (within bare proj)
    /whatever/proj      (within any worktree)
    /whatever/proj      (within .git)

> I wonder if the right "fix" to this instance, at the same time
> preventing similar breakages in the future, is rather make sure
> get_git_common_dir() not to return the redundant path with ".git/."
> suffixed? For that matter, I do not know why the bare case must
> need "/." suffix. There seem to be about a dozen callers of the
> function, but don't some of them share a similar issue?
>
> Puzzled.

Your puzzlement may arise from the misunderstanding regarding
get_git_common_dir() vs. strbuf_add_absolute_path()?

It might be nice to refine strbuf_add_absolute_path() to return more
aesthetically pleasing results (i.e. not add trailing "." when
unneeded), but such a change is outside the scope of this small patch
and may have repercussions which could be a time sink (and I haven't
the time to devote to it).

> Let's look at the other two grep hits from worktree.c
>
>     strbuf_reset(&path);
>     strbuf_addf(&path, "%s/worktrees/%s/HEAD", get_git_common_dir(), id);
>
>     worktree = xcalloc(1, sizeof(*worktree));
>     worktree->path = strbuf_detach(&worktree_path, NULL);
>     worktree->id = xstrdup(id);
>     add_head_info(worktree);
>
> done:
>     strbuf_release(&path);
>     strbuf_release(&worktree_path);
>     return worktree;
> }
>
> This looks somewhat bogus. "sturct strbuf path" is populated, but
> is released without ever getting used, isn't it? Am I grossly
> misreading the code?

I think you're reading it just fine; that code is indeed dead. This
appears to be fallout from 5193490442 (worktree: add a function to get
worktree details, 2015-10-08), which unfortunately (I think) got
little or no review[1].

This could indeed use a "dead-code removal" patch of its own, though
it's unrelated to the current patch.

FOOTNOTES

[1] I had reviewed the very first version of the patch series which
    introduced these changes, but then effectively went offline for
    many, many months, thus was unable to review any of the re-rolls.

  reply	other threads:[~2020-06-24 23:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24 19:05 [PATCH] worktree: avoid dead-code in conditional Eric Sunshine
2020-06-24 21:20 ` Junio C Hamano
2020-06-24 23:00   ` Eric Sunshine [this message]
2020-06-25  0:38     ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPig+cRdRyWAjU7QADPt39rDgJ4njDtN_pwo8JMVD=YX09a-Vg@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hariom18599@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).