@@ -1545,6 +1545,7 @@ static int patch_update_file(struct add_p_state *s,
1545
1545
strbuf_reset (& s -> buf );
1546
1546
reassemble_patch (s , file_diff , 0 , & s -> buf );
1547
1547
1548
+ discard_index (s -> s .r -> index );
1548
1549
if (s -> mode -> apply_for_checkout )
1549
1550
apply_for_checkout (s , & s -> buf ,
1550
1551
s -> mode -> is_reverse );
@@ -1555,11 +1556,9 @@ static int patch_update_file(struct add_p_state *s,
1555
1556
NULL , 0 , NULL , 0 ))
1556
1557
error (_ ("'git apply' failed" ));
1557
1558
}
1558
- if (discard_index (s -> s .r -> index ) < 0 ||
1559
- repo_read_index_preload (s -> s .r , NULL , 0 ) < 0 )
1560
- return error (_ ("could not read index" ));
1561
- repo_refresh_and_write_index (s -> s .r , REFRESH_QUIET , 0 , 1 ,
1562
- NULL , NULL , NULL );
1559
+ if (!repo_read_index (s -> s .r ))
1560
+ repo_refresh_and_write_index (s -> s .r , REFRESH_QUIET , 0 ,
1561
+ 1 , NULL , NULL , NULL );
1563
1562
}
1564
1563
1565
1564
putchar ('\n' );
@@ -1602,9 +1601,8 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
1602
1601
s .mode = & patch_mode_stage ;
1603
1602
s .revision = revision ;
1604
1603
1605
- if (repo_read_index_preload (r , NULL , 0 ) < 0 )
1606
- return error (_ ("could not read index" ));
1607
- if (repo_refresh_and_write_index (r , REFRESH_QUIET , 0 , 1 ,
1604
+ if (discard_index (r -> index ) < 0 || repo_read_index (r ) < 0 ||
1605
+ repo_refresh_and_write_index (r , REFRESH_QUIET , 0 , 1 ,
1608
1606
NULL , NULL , NULL ) < 0 ||
1609
1607
parse_diff (& s , ps ) < 0 ) {
1610
1608
strbuf_release (& s .plain );
0 commit comments