@@ -1604,7 +1604,9 @@ static bool get_first_undecided(const struct file_diff *file_diff, size_t *idx)
16041604 return false;
16051605}
16061606
1607- static size_t patch_update_file (struct add_p_state * s , size_t idx )
1607+ static size_t patch_update_file (struct add_p_state * s ,
1608+ size_t idx ,
1609+ unsigned flags )
16081610{
16091611 size_t hunk_index = 0 ;
16101612 ssize_t i , undecided_previous , undecided_next , rendered_hunk_index = -1 ;
@@ -1715,7 +1717,8 @@ static size_t patch_update_file(struct add_p_state *s, size_t idx)
17151717 permitted |= ALLOW_SPLIT ;
17161718 strbuf_addstr (& s -> buf , ",s" );
17171719 }
1718- if (hunk_index + 1 > file_diff -> mode_change &&
1720+ if (!(flags & ADD_P_DISALLOW_EDIT ) &&
1721+ hunk_index + 1 > file_diff -> mode_change &&
17191722 !file_diff -> deleted ) {
17201723 permitted |= ALLOW_EDIT ;
17211724 strbuf_addstr (& s -> buf , ",e" );
@@ -2003,7 +2006,8 @@ static size_t patch_update_file(struct add_p_state *s, size_t idx)
20032006}
20042007
20052008static int run_add_p_common (struct add_p_state * state ,
2006- const struct pathspec * ps )
2009+ const struct pathspec * ps ,
2010+ unsigned flags )
20072011{
20082012 size_t binary_count = 0 ;
20092013 size_t i ;
@@ -2017,7 +2021,7 @@ static int run_add_p_common(struct add_p_state *state,
20172021 i ++ ;
20182022 continue ;
20192023 }
2020- if ((i = patch_update_file (state , i )) == state -> file_diff_nr )
2024+ if ((i = patch_update_file (state , i , flags )) == state -> file_diff_nr )
20212025 break ;
20222026 }
20232027
@@ -2035,7 +2039,8 @@ static int run_add_p_common(struct add_p_state *state,
20352039
20362040int run_add_p (struct repository * r , enum add_p_mode mode ,
20372041 struct interactive_options * opts , const char * revision ,
2038- const struct pathspec * ps )
2042+ const struct pathspec * ps ,
2043+ unsigned flags )
20392044{
20402045 struct add_p_state s = {
20412046 .r = r ,
@@ -2084,7 +2089,7 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
20842089 goto out ;
20852090 }
20862091
2087- ret = run_add_p_common (& s , ps );
2092+ ret = run_add_p_common (& s , ps , flags );
20882093 if (ret < 0 )
20892094 goto out ;
20902095
@@ -2100,7 +2105,8 @@ int run_add_p_index(struct repository *r,
21002105 const char * index_file ,
21012106 struct interactive_options * opts ,
21022107 const char * revision ,
2103- const struct pathspec * ps )
2108+ const struct pathspec * ps ,
2109+ unsigned flags )
21042110{
21052111 struct patch_mode mode = {
21062112 .apply_args = { "--cached" , NULL },
@@ -2156,7 +2162,7 @@ int run_add_p_index(struct repository *r,
21562162 mode .diff_cmd [1 ] = "-r" ;
21572163 mode .diff_cmd [2 ] = parent_tree_oid ;
21582164
2159- ret = run_add_p_common (& s , ps );
2165+ ret = run_add_p_common (& s , ps , flags );
21602166 if (ret < 0 )
21612167 goto out ;
21622168
0 commit comments