git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] branch: show rebase/bisect info when possible instead of "(no branch)"

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 11, 2013, 19:13 UTC
Message-ID
<7vehgmmzop.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1360318171-17614-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 9 quoted lines
> +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.

Show 5 quoted lines
> +	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?

Previous: Duy Nguyen
Message 14 of 14 in “branch: show (rebasing) or (bisecting) instead of (no branch) when possible”
  1. branch: show (rebasing) or (bisecting) instead of (no branch) when possibleNguyễn Thái Ngọc Duy, Jan 29, 2013
  2. Jonathan NiederJan 29, 2013
  3. branch: show rebase/bisect info when possible instead of "(no branch)"Nguyễn Thái Ngọc Duy, Feb 3, 2013
  4. Matthieu MoyFeb 3, 2013
  5. Junio C HamanoFeb 3, 2013
  6. Junio C HamanoFeb 3, 2013
  7. Matthieu MoyFeb 4, 2013
  8. Junio C HamanoFeb 4, 2013
  9. Duy NguyenFeb 4, 2013
  10. Duy NguyenFeb 4, 2013
  11. branch: show rebase/bisect info when possible instead of "(no branch)"Nguyễn Thái Ngọc Duy, Feb 8, 2013
  12. Junio C HamanoFeb 8, 2013
  13. Duy NguyenFeb 14, 2013
  14. Junio C HamanoFeb 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.