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

Re: [PATCH v3 1/2] diff --no-index: optionally follow symlinks

From
Dennis Kaarsemaker <dennis@kaarsemaker.net>
Date
Mar 20, 2017, 10:50 UTC
Message-ID
<1490007035.15470.14.camel@kaarsemaker.net>
In-Reply-To
<xmqqk27kzzfm.fsf@gitster.mtv.corp.google.com>
On Sun, 2017-03-19 at 15:14 -0700, Junio C Hamano wrote:
Show 26 quoted lines
> Dennis Kaarsemaker <dennis@kaarsemaker.net> writes:
> 
> > diff --git a/diff.c b/diff.c
> > index be11e4ef2b..2afecfb939 100644
> > --- a/diff.c
> > +++ b/diff.c
> > @@ -2815,7 +2815,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
> >  		s->size = xsize_t(st.st_size);
> >  		if (!s->size)
> >  			goto empty;
> > -		if (S_ISLNK(st.st_mode)) {
> > +		if (S_ISLNK(s->mode)) {
> >  			struct strbuf sb = STRBUF_INIT;
> >  
> >  			if (strbuf_readlink(&sb, s->path, s->size))
> > @@ -2825,6 +2825,10 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
> >  			s->should_free = 1;
> >  			return 0;
> >  		}
> > +		if (S_ISLNK(st.st_mode)) {
> > +			stat(s->path, &st);
> > +			s->size = xsize_t(st.st_size);
> 
> Doesn't this affect --no-index mode?  We never need to do a wasteful
> stat() after lstat() and we are penalizing the normal codepath with
> this change, no?

the S_ISLNK(s->mode) conditional above is for the normal codepath, which returns early. So the stat I added is only done for symlinks in no_index mode.

Show 16 quoted lines
> > @@ -3884,7 +3888,11 @@ int diff_opt_parse(struct diff_options *options,
> >  	else if (!strcmp(arg, "--no-follow")) {
> >  		DIFF_OPT_CLR(options, FOLLOW_RENAMES);
> >  		DIFF_OPT_CLR(options, DEFAULT_FOLLOW_RENAMES);
> > -	} else if (!strcmp(arg, "--color"))
> > +	} else if (!strcmp(arg, "--dereference"))
> > +		DIFF_OPT_SET(options, DEREFERENCE);
> > +	else if (!strcmp(arg, "--no-dereference"))
> > +		DIFF_OPT_CLR(options, DEREFERENCE);
> > +	else if (!strcmp(arg, "--color"))
> >  		options->use_color = 1;
> 
> Also shouldn't be some code to detect --[no-]dereference options
> given when --no-index is not in effect and error out?  As the patch
> title says, this change should be a no-op for normal codepath and
> only affect the no-index hack.

But erroring out isn't a no-op. With the current patch you can do  --dereference without --no-index and it simply wouldn't affect anything.

I don't mind either way, so I'll make it error out.
-- 
Dennis Kaarsemaker
http://www.kaarsemaker.net
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 8 in “diff --no-index: support symlinks and pipes”
  1. 0/2 diff --no-index: support symlinks and pipesDennis Kaarsemaker, Mar 18, 2017
  2. 2/2 diff --no-index: support reading from pipesDennis Kaarsemaker, Mar 18, 2017
  3. 1/2 diff --no-index: optionally follow symlinksDennis Kaarsemaker, Mar 18, 2017
  4. Junio C HamanoMar 19, 2017
  5. Dennis KaarsemakerMar 20, 2017
  6. Junio C HamanoMar 19, 2017
  7. Dennis KaarsemakerMar 20, 2017
  8. Junio C HamanoMar 20, 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.