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

Re: [PATCH] show-ref: Allow --head to work with --verify

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 20, 2017, 19:03 UTC
Message-ID
<xmqqa8aly2o4.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170120155015.4360-1-git@thecybershadow.net>
Vladimir Panteleev <git@thecybershadow.net> writes:
> This patch adds --head support to show-ref's --verify logic, by
> explicitly checking if the "HEAD" ref is specified when --head is
> present.
Show 9 quoted lines
> @@ -207,6 +207,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
>  				if (!quiet)
>  					show_one(*pattern, &oid);
>  			}
> +			else if (show_head && !strcmp(*pattern, "HEAD"))
> +				head_ref(show_ref, NULL);
>  			else if (!quiet)
>  				die("'%s' - not a valid ref", *pattern);
>  			else
The context around here look like this:
		while (*pattern) {
			struct object_id oid;
			if (starts_with(*pattern, "refs/") &&
			    !read_ref(*pattern, oid.hash)) {
				if (!quiet)
					show_one(*pattern, &oid);
			}
			else if (!quiet)
				die("'%s' - not a valid ref", *pattern);
			else
				return 1;
			pattern++;
		}

and viewed in the wider context, I notice that quiet is not honored in the added code. I think that is easily fixable by replacing this hunk with something like:

- if (starts_with(*pattern, "refs/") && + if (to_show_ref(*pattern) &&

and then another hunk that implements to_show_ref() helper function, perhaps like

	static int to_show_ref(const char *pattern)
	{
		if (starts_with(pattern, "refs/"))
			return 1;
		if (show_head && !strcmp(pattern, "HEAD"))
			return 1;
		return 0;
	}
or something.

Having said all that, using --verify on HEAD does not make much sense, because if HEAD is missing in .git/, I do not think Git considers that directory as a Git repository to begin with. So from that point of view, I am not sure what value this change adds to the system, even though the change is almost correct (modulo the "quiet" thing).

Previous: Vladimir PanteleevNext: Vladimir Panteleev
Message 2 of 11 in “show-ref: Allow --head to work with --verify”
  1. show-ref: Allow --head to work with --verifyVladimir Panteleev, Jan 20, 2017
  2. Junio C HamanoJan 20, 2017
  3. Vladimir PanteleevJan 20, 2017
  4. Vladimir PanteleevJan 20, 2017
  5. Junio C HamanoJan 20, 2017
  6. Junio C HamanoJan 20, 2017
  7. Junio C HamanoJan 20, 2017
  8. Vladimir PanteleevJan 20, 2017
  9. Junio C HamanoJan 20, 2017
  10. Junio C HamanoJan 20, 2017
  11. Vladimir PanteleevJan 21, 2017

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.