git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	Jonathan Niedier <jrnieder@gmail.com>
Subject: Re: [PATCH v3] branch: show rebase/bisect info when possible instead of "(no branch)"
Date: Mon, 11 Feb 2013 11:13:26 -0800	[thread overview]
Message-ID: <7vehgmmzop.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1360318171-17614-1-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Fri, 8 Feb 2013 17:09:31 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> +static char *get_head_description()
> +{
> +	struct stat st;
> +	struct strbuf sb = STRBUF_INIT;
> +	struct strbuf result = STRBUF_INIT;
> +	int bisect = 0;
> +	int ret;
> +	if (!stat(git_path("rebase-merge"), &st) && S_ISDIR(st.st_mode))
> +		ret = strbuf_read_file(&sb, git_path("rebase-merge/head-name"), 0);

Hrmph.  Why isn't this checking if the file exists and then read it,
i.e.

	if (access(git_path("rebase-merge/head-name"), F_OK))
		ret = strbuf_read_file(&sb, git_path("rebase-merge/head-name"), 0);

It is not like you are creating this file and making sure leading
directories exist, so the sequence looks a bit strange.

> +	else if (!access(git_path("rebase-apply/rebasing"), F_OK))
> +		ret = strbuf_read_file(&sb, git_path("rebase-apply/head-name"), 0);
> +	else if (!access(git_path("BISECT_LOG"), F_OK)) {
> +		ret = strbuf_read_file(&sb, git_path("BISECT_START"), 0);
> +		bisect = 1;

And if the answer to the above question is "because if rebase-merge/
exists, with or without head-name, we know we are not bisecting",
then that may suggest that the structure of if/elseif cascade is
misdesigned.  Shouldn't the "bisect" boolean be an enum "what are we
doing" that is initialized to "I do not know" and each of these
if/elseif cascade set the state to it when they know what we are
doing, in order for this function to be longer-term maintainable?

      parent reply	other threads:[~2013-02-11 19:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-29 12:12 [PATCH] branch: show (rebasing) or (bisecting) instead of (no branch) when possible Nguyễn Thái Ngọc Duy
2013-01-29 19:13 ` Jonathan Nieder
2013-02-03  5:48 ` [PATCH v2] branch: show rebase/bisect info when possible instead of "(no branch)" Nguyễn Thái Ngọc Duy
2013-02-03 21:23   ` Matthieu Moy
2013-02-03 21:58     ` Junio C Hamano
2013-02-03 22:00       ` Junio C Hamano
2013-02-04 13:13       ` Matthieu Moy
2013-02-04 16:18         ` Junio C Hamano
2013-02-04  7:14     ` Duy Nguyen
2013-02-04  7:17       ` Duy Nguyen
2013-02-08 10:09   ` [PATCH v3] " Nguyễn Thái Ngọc Duy
2013-02-08 18:35     ` Junio C Hamano
2013-02-14  9:46       ` Duy Nguyen
2013-02-11 19:13     ` Junio C Hamano [this message]

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=7vehgmmzop.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@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;
as well as URLs for NNTP newsgroup(s).