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

Re: [PATCH v3] diff: generate prettier filenames when using GIT_EXTERNAL_DIFF

From
David Aguilar <davvid@gmail.com>
Date
May 26, 2009, 17:37 UTC
Message-ID
<20090526173726.GA5528@gmail.com>
In-Reply-To
<4A1B85B8.1050907@gmail.com>
On Mon, May 25, 2009 at 11:01:28PM -0700, Stephen Boyd wrote:
Show 23 quoted lines
> David Aguilar wrote:
> > -	fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
> > +	if (pretty_filename) {
> > +		struct strbuf pretty_name = STRBUF_INIT;
> > +		char *pathdup = xstrdup(path);
> > +		char *base = basename(pathdup);
> > +		char *dot = strchr(base, '.');
> > +		int suffix_len = 0;
> > +
> > +		if (dot) {
> > +			/* path has an extension, e.g. "foo.txt";
> > +			 * generate "foo.XXXX.txt".
> > +			 */
> > +			*dot = '\0';
> > +			strbuf_addstr(&pretty_name, base);
> > +			*dot = '.';
> > +			strbuf_addstr(&pretty_name, ".XXXXXX");
> > +			suffix_len = strlen(dot);
> > +			strbuf_addstr(&pretty_name, dot);
> 
> This *dot business annoys me. Would it be better to use strbuf_add()
> with some pointer math thrown in? Also, what happens with files such as
> "foo.bar.txt"? Do we want "foo.XXXXX.bar.txt"?

That was intentional; "foo.tar.gz" becomes "foo.XXXXXX.tar.gz", which is what I considered better behavior when writing it.

Thanks for the note about using strbuf_add(). I'll see if we can simplify things by using it instead of strbuf_addstr().

I should probably split the "add compat/mkstemps" and "use it in git_mkstemps()" parts into separate commits since we're going to want to use the native mkstemps implementation if it's available.

-- 
		David
Previous: Stephen BoydNext: Junio C Hamano
Message 3 of 7 in “diff: generate prettier filenames when using GIT_EXTERNAL_DIFF”
  1. diff: generate prettier filenames when using GIT_EXTERNAL_DIFFDavid Aguilar, May 26, 2009
  2. Stephen BoydMay 26, 2009
  3. David AguilarMay 26, 2009
  4. Junio C HamanoMay 26, 2009
  5. Markus HeidelbergMay 26, 2009
  6. David AguilarMay 26, 2009
  7. Junio C HamanoMay 26, 2009

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.