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

Re: [PATCH] name-rev: Allow to omit refs/tags/ part in --refs option when --tags used

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 17, 2013, 15:53 UTC
Message-ID
<7vehc0hgy6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<7vip1chi50.fsf@alter.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 35 quoted lines
> Wouldn't it make more sense to see if the given pattern matches a
> tail substring of the ref, instead of using the hardcoded "strip
> refs/heads/, refs/tags or refs/, and then match once" logic?  That
> way, --refs=origin/* can find refs/remotes/origin/master by running
> fnmatch of origin/* against its substrings, i.e.
>
> 	refs/remotes/origin/master
>         remotes/origin/master
>         origin/master
>
> and find that the pattern matches it.
>
> Perhaps it is just the matter of adding something like:
> ...
> and then at the beginning of name_ref() do this:
>
> 	int can_abbreviate_output = data->name_only;
>
> 	if (data->tags_only && prefixcmp(path, "refs/tags/"))
> 		return 0;
> 	if (data->ref_filter) {
>         	switch (subpath_matches(path, data->ref_filter)) {
> 		case -1: /* did not match */
> 			return 0;
> 		default: /* matched subpath */
> 			can_abbreviate_output = 1;
> 			break;
> 		case 0: /* matched fully */
>                 	break;
> 		}
> 	}
>
> The logic before calling name_rev() will be kept as "only decide how
> the output looks like", without mixing the unrelated "decide if we
> want to use it" logic in.

... which may make the "call name_rev with this abbreviated path" logic look something like this:

	if (o && o->type == OBJ_COMMIT) {
        	if (can_abbreviate_output)
			path = shorten_unambiguous_ref(path, 0);
		else if (!prefixcmp(path, "refs/heads/"))
			path = path + 11;
		else if (data->tags_only
		    && data->name_only
		    && !prefixcmp(path, "refs/tags/"))
			path = path + 10;
		else if (!prefixcmp(path, "refs/"))
			path = path + 5;
		name_rev((struct commit *) o, xstrdup(path), 0, 0, deref);
	}
Previous: Junio C HamanoNext: Namhyung Kim
Message 3 of 5 in “name-rev: Allow to omit refs/tags/ part in --refs option when --tags used”
  1. name-rev: Allow to omit refs/tags/ part in --refs option when --tags usedNamhyung Kim, Jun 17, 2013
  2. Junio C HamanoJun 17, 2013
  3. Junio C HamanoJun 17, 2013
  4. Namhyung KimJun 18, 2013
  5. Namhyung KimJun 18, 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.