Re: Expose subprojects as special files to "git diff" machinery
- From
Linus Torvalds <torvalds@linux-foundation.org>
- Date
- Apr 15, 2007, 19:05 UTC
- Message-ID
- <Pine.LNX.4.64.0704151204320.5473@woody.linux-foundation.org>
- In-Reply-To
- <20070415190119.GA21786@uranus.ravnborg.org>
On Sun, 15 Apr 2007, Sam Ravnborg wrote:
Show 10 quoted lines
> >
> > +static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
> > +{
> > + int len;
> > + char *data = xmalloc(100);
> > + len = snprintf(data, 100,
> > + "Subproject commit %s\n", sha1_to_hex(s->sha1));
>
> In userland I would use a local variable for an array of the size of 100.
> I would normally only allocate when we are say 5x bigger.We're _returning_ the pointer to the caller, so no, we cannot use an automatic array.
But I do think I had a bug - I think I should have set
s->should_free = 1;
to let the caller know it should be free'd with free(), and not leak the thing.
Linus