Subject: Re: [PATCH v2] diff -c -p: do not die on submodules

From: Junio C Hamano <[email-masked]>
Date: Wed, 29 Apr 2009 16:09:28 -0700

Alex Riesen <[email-masked]> writes:

> 2009/4/29 Junio C Hamano <[email-masked]>:
>> +
>> +       if (S_ISGITLINK(mode)) {
>> +               blob = xmalloc(100);
>> +               *size = snprintf(blob, 100,
>> +                                "Subproject commit %s\n", sha1_to_hex(sha1));
>
> snprintf returns a signed value. It also has a bad record of returning
> negative values for obscure reasons (on obscure platforms, admittedly).

The arena is sufficiently large that there is no way any broken snprintf
can return negative here.

This is a copy from Linus's diff_populate_gitlink(), that dates back to
0478675 (Expose subprojects as special files to "git diff" machinery,
2007-04-15), and you have never seen any breakage, which should tell you
something.

As I mentioned in the original patch, the codepath that reads one side of
diff (either from a blob or from a work tree entity) in show_patch_diff()
and grab_blob() in combine-diff.c should do the same thing as what
diff_populate_filespec() in diff.c does, and these three functions need
some refactoring to share more code.  The patch however is about fixing
the existing breakage without invasive refactoring.