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

Re: [PATCH 1/1] rebase -r: let `label` generate safer labels

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 3, 2019, 11:19 UTC
Message-ID
<nycvar.QRO.7.76.6.1909031256290.46@tvgsbejvaqbjf.bet>
In-Reply-To
<xmqq5zmav9ej.fsf@gitster-ct.c.googlers.com>
Hi Junio,
On Mon, 2 Sep 2019, Junio C Hamano wrote:
Show 17 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
> >>   		for (p1 = label.buf; *p1; p1++)
> >> -			if (isspace(*p1))
> >> +			if (!(*p1 & 0x80) && !isalnum(*p1))
> >>   				*(char *)p1 = '-';
> >
> > I'm sightly concerned that this opens the possibility for unexpected
> > effects if two different labels get sanitized to the same string. I
> > suspect it's unlikely to happen in practice but doing something like
> > percent encoding non-alphanumeric characters would avoid the problem
> > entirely.
>
> I'd rather see 'x' used instead of '-' (double-or-more dashes and
> leading dash in refnames may currently be allowed but double-or-more
> exes and leading ex would be much more likely to stay valid) if we
> just want to redact invalid characters.
Hmm. Let's take a concrete example from the VFS for Git fork:
	Merge pull request #160: trace2:gvfs:experiment Add experimental regions and data events to help diagnose checkout and reset perf problems

(Yes, we have some quite verbose merge commits, with very, very long onelines. Not a good practice, we stopped doing it, but it was well within what Git allows.)

And now use dashes to encode all white-space:
	Merge-pull-request-#160:-trace2:gvfs:experiment-Add-experimental-regions-and-data-events-to-help-diagnose-checkout-and-reset-perf-problems
Pretty long, but looks okay. Of course, it does not work, because colons. So here is the label with Matt's patch:
	Merge-pull-request--160--trace2-gvfs-experiment-Add-experimental-regions-and-data-events-to-help-diagnose-checkout-and-reset-perf-problems
And here is the label with your proposed xs.
	Mergexpullxrequestxx160xxtrace2xgvfsxexperimentxAddxexperimentalxregionsxandxdataxeventsxtoxhelpxdiagnosexcheckoutxandxresetxperfxproblems

I cannot speak for you, of course, but I can speak for myself: this is not only way too reminiscent of xoxoxothxbye, but it is also really, totally unreadable.

If you care deeply about double dashes and leading dashes, how about this instead?

		char *from, *to;
   		for (from = to = label.buf; *from; from++)
			if ((*from & 0x80) || isalnum(*from))
				*(to++) = *from;
			/* avoid leading dash and double-dashes */
			else if (to != label.buf && to[-1] != '-')
   				*(to++) = '-';
		strbuf_setlen(&label, to - label.buf);
That would result in
	Merge-pull-request-160-trace2-gvfs-experiment-Add-experimental-regions-and-data-events-to-help-diagnose-checkout-and-reset-perf-problems
> I see there are "lets make sure it is unique by suffixing "-%d" in
> other codepaths; would that help if this piece of code yields a
> label that is not unique?

I'm way ahead of you. The sequencer already goes out of its way to guarantee the uniqueness of the labels (it's part of the design, as applied in 1644c73c6d4 (rebase-helper --make-script: introduce a flag to rebase merges, 2018-04-25)).

The patch you are looking at in this thread is only concerned about the initial phase, `label_oid()` does a lot more. Not only does it make the label unique (case-insensitively!), it also prevents it from looking like a full 40-hex digit SHA-1, so that we can guarantee that unique abbreviations of commit hashes will work as labels, too.

Ciao, Dscho

Previous: Philip OakleyNext: Junio C Hamano
Message 7 of 22 in “Make git rebase -r's label generation more resilient”
  1. 0/1 Make git rebase -r's label generation more resilientJohannes Schindelin via GitGitGadget, Sep 2, 2019
  2. 1/1 rebase -r: let `label` generate safer labelsMatt R via GitGitGadget, Sep 2, 2019
  3. Phillip WoodSep 2, 2019
  4. Junio C HamanoSep 2, 2019
  5. brian m. carlsonSep 2, 2019
  6. Philip OakleySep 2, 2019
  7. Johannes SchindelinSep 3, 2019
  8. Junio C HamanoSep 3, 2019
  9. Matt RogersSep 3, 2019
  10. Johannes SchindelinSep 2, 2019
  11. Junio C HamanoSep 3, 2019
  12. Johannes SchindelinNov 18, 2019
  13. 0/2 Make git rebase -r's label generation more resilientJohannes Schindelin via GitGitGadget, Nov 17, 2019
  14. 2/2 rebase -r: let `label` generate safer labelsMatthew Rogers via GitGitGadget, Nov 17, 2019
  15. 1/2 rebase-merges: move labels' whitespace mangling into `label_oid()`Johannes Schindelin via GitGitGadget, Nov 17, 2019
  16. Junio C HamanoNov 18, 2019
  17. sequencer: handle rebase-merge for "onto" messageDanh Doan, Nov 18, 2019
  18. sequencer: handle rebase-merges for "onto" messageDoan Tran Cong Danh, Nov 18, 2019
  19. Johannes SchindelinNov 18, 2019
  20. Junio C HamanoNov 21, 2019
  21. Johannes SchindelinNov 18, 2019
  22. Philip OakleySep 2, 2019

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.