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

Re: [JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Dec 10, 2008, 23:22 UTC
Message-ID
<200812110022.03719.robin.rosenberg@dewire.com>
In-Reply-To
<1228946751-12708-5-git-send-email-spearce@spearce.org>
onsdag 10 december 2008 23:05:49 skrev Shawn O. Pearce:
> Git patch files can contain file names which are quoted using the
> C language quoting rules.  In order to correctly create or parse

Should we maybe call this Git-style since we really do not care about C (which version btw?).

Show 11 quoted lines
> QuotedString itself is an abstract API so callers can be passed a
> quoting style based on the context of where their output will be
> used, and multiple styles could be supported.  This may be useful
> if jgit ever grows a "git for-each-ref" style of output where Perl,
> Python, Tcl and Bourne style quoting might be necessary.
> 
> References through the singleton QuotedString.C should be able to
> bypass the virtual function table, as the specific type is mentioned
> in the field declaration and that type is final.  A good JIT should
> be able to remove the abstraction costs when the caller has hardcoded
> the quoting style.

Making two interfaces is better. We may share the implementation initially, but parsing file names in Git patches and parsing C strings are different operations.

Show 5 quoted lines
> +	public void testQuote_OctalAll() {
> +		assertQuote("\1", "\\001");
> +		assertQuote("~", "\\176");
> +		assertQuote("\u00ff", "\\303\\277"); // \u00ff in UTF-8
> +	}

What do we do with non-UTF8 names? I think we should follow the logic we use when parsing commits and paths in other places.

> +
> +	public void testDequote_UnknownEscapeQ() {
> +		assertDequote("\\q", "\\q");
> +	}
Would Git generate this style in a name? 
Show 12 quoted lines
> +			quote[' '] = 0;
> +			quote['+'] = 0;
> +			quote[','] = 0;
> +			quote['-'] = 0;
> +			quote['.'] = 0;
> +			quote['/'] = 0;
> +			quote['='] = 0;
> +			quote['_'] = 0;
> +			quote['^'] = 0;
> +
> +			quote['\u0007'] = 'a';
> +			quote['\b'] = 'b';
\e = esc
Show 10 quoted lines
> +				default:
> +					// Any other code is taken literally.
> +					//
> +					r[rPtr++] = '\\';
> +					r[rPtr++] = in[inPtr - 1];
> +					continue;
> +				}
> +			}
> +
> +			return decode(Constants.CHARSET, r, 0, rPtr);

Importing methods really obscures things. Please qualify with class name of RawparseUtils here instead.

-- robin
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 8 of 11 in “RawParseUtil improvements”
  1. 0/6 RawParseUtil improvementsShawn O. Pearce, Dec 10, 2008
  2. 1/6 Simplify RawParseUtils.nextLF invocationsShawn O. Pearce, Dec 10, 2008
  3. 2/6 Simplify RawParseUtils next and nextLF loopsShawn O. Pearce, Dec 10, 2008
  4. 3/6 Correct Javadoc of RawParseUtils next and nextLF methodsShawn O. Pearce, Dec 10, 2008
  5. 4/6 Add QuotedString class to handle C-style quoting rulesShawn O. Pearce, Dec 10, 2008
  6. 5/6 Add Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  7. 6/6 Add ~user friendly Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  8. Robin RosenbergDec 10, 2008
  9. Shawn O. PearceDec 10, 2008
  10. Robin RosenbergDec 11, 2008
  11. 4/6 Add QuotedString class to handle Git path style quoting rulesShawn O. Pearce, Dec 11, 2008

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.