@@ -36,11 +36,16 @@ static void init_color(struct repository *r, struct add_i_state *s,
3636 free (key );
3737}
3838
39- void init_add_i_state (struct add_i_state * s , struct repository * r )
39+ void init_add_i_state (struct add_i_state * s , struct repository * r ,
40+ struct add_p_opt * add_p_opt )
4041{
4142 const char * value ;
43+ int context ;
44+ int interhunkcontext ;
4245
4346 s -> r = r ;
47+ s -> context = -1 ;
48+ s -> interhunkcontext = -1 ;
4449
4550 if (repo_config_get_value (r , "color.interactive" , & value ))
4651 s -> use_color = -1 ;
@@ -78,9 +83,33 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
7883 repo_config_get_string (r , "diff.algorithm" ,
7984 & s -> interactive_diff_algorithm );
8085
86+ if (!repo_config_get_int (r , "diff.context" , & context )) {
87+ if (context < 0 )
88+ die (_ ("%s cannot be negative" ), "diff.context" );
89+ else
90+ s -> context = context ;
91+ };
92+ if (!repo_config_get_int (r , "diff.interHunkContext" , & interhunkcontext )) {
93+ if (interhunkcontext < 0 )
94+ die (_ ("%s cannot be negative" ), "diff.interHunkContext" );
95+ else
96+ s -> interhunkcontext = interhunkcontext ;
97+ };
98+
8199 repo_config_get_bool (r , "interactive.singlekey" , & s -> use_single_key );
82100 if (s -> use_single_key )
83101 setbuf (stdin , NULL );
102+
103+ if (add_p_opt -> context != -1 ) {
104+ if (add_p_opt -> context < 0 )
105+ die (_ ("%s cannot be negative" ), "--unified" );
106+ s -> context = add_p_opt -> context ;
107+ }
108+ if (add_p_opt -> interhunkcontext != -1 ) {
109+ if (add_p_opt -> interhunkcontext < 0 )
110+ die (_ ("%s cannot be negative" ), "--inter-hunk-context" );
111+ s -> interhunkcontext = add_p_opt -> interhunkcontext ;
112+ }
84113}
85114
86115void clear_add_i_state (struct add_i_state * s )
@@ -969,6 +998,10 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
969998 opts -> prompt = N_ ("Patch update" );
970999 count = list_and_choose (s , files , opts );
9711000 if (count > 0 ) {
1001+ struct add_p_opt add_p_opt = {
1002+ .context = s -> context ,
1003+ .interhunkcontext = s -> interhunkcontext ,
1004+ };
9721005 struct strvec args = STRVEC_INIT ;
9731006 struct pathspec ps_selected = { 0 };
9741007
@@ -979,7 +1012,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
9791012 parse_pathspec (& ps_selected ,
9801013 PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL ,
9811014 PATHSPEC_LITERAL_PATH , "" , args .v );
982- res = run_add_p (s -> r , ADD_P_ADD , NULL , & ps_selected );
1015+ res = run_add_p (s -> r , ADD_P_ADD , & add_p_opt , NULL , & ps_selected );
9831016 strvec_clear (& args );
9841017 clear_pathspec (& ps_selected );
9851018 }
@@ -1014,10 +1047,13 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
10141047 if (count > 0 ) {
10151048 struct child_process cmd = CHILD_PROCESS_INIT ;
10161049
1017- strvec_pushl (& cmd .args , "git" , "diff" , "-p" , "--cached" ,
1018- oid_to_hex (!is_initial ? & oid :
1019- s -> r -> hash_algo -> empty_tree ),
1020- "--" , NULL );
1050+ strvec_pushl (& cmd .args , "git" , "diff" , "-p" , "--cached" , NULL );
1051+ if (s -> context != -1 )
1052+ strvec_pushf (& cmd .args , "--unified=%i" , s -> context );
1053+ if (s -> interhunkcontext != -1 )
1054+ strvec_pushf (& cmd .args , "--inter-hunk-context=%i" , s -> interhunkcontext );
1055+ strvec_pushl (& cmd .args , oid_to_hex (!is_initial ? & oid :
1056+ s -> r -> hash_algo -> empty_tree ), "--" , NULL );
10211057 for (i = 0 ; i < files -> items .nr ; i ++ )
10221058 if (files -> selected [i ])
10231059 strvec_push (& cmd .args ,
@@ -1110,7 +1146,8 @@ static void command_prompt_help(struct add_i_state *s)
11101146 _ ("(empty) select nothing" ));
11111147}
11121148
1113- int run_add_i (struct repository * r , const struct pathspec * ps )
1149+ int run_add_i (struct repository * r , const struct pathspec * ps ,
1150+ struct add_p_opt * add_p_opt )
11141151{
11151152 struct add_i_state s = { NULL };
11161153 struct print_command_item_data data = { "[" , "]" };
@@ -1153,7 +1190,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11531190 -> util = util ;
11541191 }
11551192
1156- init_add_i_state (& s , r );
1193+ init_add_i_state (& s , r , add_p_opt );
11571194
11581195 /*
11591196 * When color was asked for, use the prompt color for
0 commit comments