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

Re: [PATCH v1 2/2] log: add option to choose which refs to decorate

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 10, 2017, 17:42 UTC
Message-ID
<xmqqo9oaf2ss.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<89e7f8e0-8b0d-fde0-5e28-31173213a26e@gmail.com>
Rafael Ascensão <rafa.almas@gmail.com> writes:
Show 8 quoted lines
> I agree that describe should receive the "normalize" treatment. However,
> and following the same reasoning, why should describe users adopt the
> rules imposed by --glob? I could argue they're also used to the way it
> works now.
>
> That being said, the suggestion I mentioned earlier would allow to keep
> both current behaviors consistent at the expense of the extra call to
> refs.c::ref_exists().

In any case, updating the "describe" for consistency is something we can and should leave for later, to be done as a separate topic.

While I agree with you that the consistent behaviour between commands is desirable, and also I agree with you that given a pattern $X that does not have any glob char, trying to match $X when a ref whose name exactly is $X exists and trying to match $X/* otherwise would give us a consistent semantics without hurting any existing uses, I do not think you need to pay any extra expense of calling ref_exists() at all to achieve that.

That is because when $X exists, you already know $X/otherthing does not exist. And when $X does not exist, $X/otherthing might. So a naive implementation would be just to add two patterns $X and $X/* to the filter list and be done with it. If you exactly have refs/heads/master, even with the naive logic may throw both refs/heads/master and refs/heads/master/* to the filter list, nothing will match the latter to contaminate your result (and vice versa).

A bit more clever implementation "just throw in two items" would go like this. It is not all that involved:

 - In load_ref_decorations(), before running add_ref_decoration for
   each ref and head ref, iterate over the elements in the refname
   filter list.  For each element:
   - if item->string has a trailing '/', trim that.
   - store NULL in the item->util field for item whose string field
     has a glob char.
   - store something non-NULL (e.g. item->string) for item whose
     string field does not have a glob char.
 - In add_ref_decoration(), where your previous round iterates over
   filter->{include,exclude}, get rid of normalize_glob_ref() and
   use of real_pattern.  Instead do something like:
	matched = 0;
	if (item->util == NULL) {
		if (!wildmatch(item->string, refname, 0))
                	matched = 1;
	} else {
		const char *rest;
		if (skip_prefix(refname, item->string, &rest) &&
                    (!*rest || *rest == '/'))
			matched = 1;
	}
	if (matched)
		...
   Of course, you would probably want to encapsulate the logic to
   set matched = 1/0 in a helper function, e.g.
	static int match_ref_pattern(const char *refname,
				     const struct string_list_item *item) {
		int matched = 0;
		... do either wildmatch or head match with tail validation
		... depending on the item->util's NULLness (see above)
		return matched;
	}
   and call that from the two loops for exclude and include list.
Hmm?
Previous: Rafael AscensãoNext: Rafael Ascensão
Message 22 of 24 in “Add option to git log to choose which refs receive decoration”
  1. 0/2 Add option to git log to choose which refs receive decorationRafael Ascensão, Nov 4, 2017
  2. 1/2 refs: extract function to normalize partial refsRafael Ascensão, Nov 4, 2017
  3. Junio C HamanoNov 4, 2017
  4. Rafael AscensãoNov 4, 2017
  5. Kevin DaudtNov 4, 2017
  6. Michael HaggertyNov 5, 2017
  7. Michael HaggertyNov 5, 2017
  8. Junio C HamanoNov 6, 2017
  9. Rafael AscensãoNov 6, 2017
  10. Michael HaggertyNov 6, 2017
  11. 2/2 log: add option to choose which refs to decorateRafael Ascensão, Nov 4, 2017
  12. Junio C HamanoNov 4, 2017
  13. Rafael AscensãoNov 4, 2017
  14. Junio C HamanoNov 5, 2017
  15. Junio C HamanoNov 5, 2017
  16. Rafael AscensãoNov 6, 2017
  17. Junio C HamanoNov 6, 2017
  18. Michael HaggertyNov 6, 2017
  19. Jacob KellerNov 6, 2017
  20. Junio C HamanoNov 7, 2017
  21. Rafael AscensãoNov 10, 2017
  22. Junio C HamanoNov 10, 2017
  23. log: add option to choose which refs to decorateRafael Ascensão, Nov 21, 2017
  24. Junio C HamanoNov 22, 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.