diff mbox series

[17/27] diff-lib: ensure full index

Message ID 45bbed6150a2a9f9e9446edc9a613f027da73957.1615929436.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series Sparse Index: API protections | expand

Commit Message

Derrick Stolee March 16, 2021, 9:17 p.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

Before iterating over all cache entries, ensure that a sparse index is
expanded to a full index to avoid unexpected behavior.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 diff-lib.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Elijah Newren March 18, 2021, 5:24 a.m. UTC | #1
On Tue, Mar 16, 2021 at 2:17 PM Derrick Stolee via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Derrick Stolee <dstolee@microsoft.com>
>
> Before iterating over all cache entries, ensure that a sparse index is
> expanded to a full index to avoid unexpected behavior.
>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> ---
>  diff-lib.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/diff-lib.c b/diff-lib.c
> index b73cc1859a49..41d6fcec1a81 100644
> --- a/diff-lib.c
> +++ b/diff-lib.c
> @@ -102,6 +102,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
>
>         if (diff_unmerged_stage < 0)
>                 diff_unmerged_stage = 2;
> +
>         entries = istate->cache_nr;
>         for (i = 0; i < entries; i++) {
>                 unsigned int oldmode, newmode;

I don't think adding a blank newline will ensure the index is expanded.  ;-)
Derrick Stolee March 23, 2021, 1:15 p.m. UTC | #2
On 3/18/2021 1:24 AM, Elijah Newren wrote:
> On Tue, Mar 16, 2021 at 2:17 PM Derrick Stolee via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> Before iterating over all cache entries, ensure that a sparse index is
>> expanded to a full index to avoid unexpected behavior.
>>
>> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
>> ---
>>  diff-lib.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/diff-lib.c b/diff-lib.c
>> index b73cc1859a49..41d6fcec1a81 100644
>> --- a/diff-lib.c
>> +++ b/diff-lib.c
>> @@ -102,6 +102,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
>>
>>         if (diff_unmerged_stage < 0)
>>                 diff_unmerged_stage = 2;
>> +
>>         entries = istate->cache_nr;
>>         for (i = 0; i < entries; i++) {
>>                 unsigned int oldmode, newmode;
> 
> I don't think adding a blank newline will ensure the index is expanded.  ;-)

Oops! This is one where I think we determined the loop doesn't
need the guard, but I didn't remove the newline and hence the
patch wasn't dropped.

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/diff-lib.c b/diff-lib.c
index b73cc1859a49..41d6fcec1a81 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -102,6 +102,7 @@  int run_diff_files(struct rev_info *revs, unsigned int option)
 
 	if (diff_unmerged_stage < 0)
 		diff_unmerged_stage = 2;
+
 	entries = istate->cache_nr;
 	for (i = 0; i < entries; i++) {
 		unsigned int oldmode, newmode;