22#define DISABLE_SIGN_COMPARE_WARNINGS
33
44#include "git-compat-util.h"
5- #include "add-interactive.h"
65#include "add-patch.h"
76#include "advice.h"
87#include "config.h"
@@ -263,7 +262,8 @@ struct hunk {
263262};
264263
265264struct add_p_state {
266- struct add_i_state s ;
265+ struct repository * r ;
266+ struct interactive_config cfg ;
267267 struct strbuf answer , buf ;
268268
269269 /* parsed diff */
@@ -408,7 +408,7 @@ static void add_p_state_clear(struct add_p_state *s)
408408 for (i = 0 ; i < s -> file_diff_nr ; i ++ )
409409 free (s -> file_diff [i ].hunk );
410410 free (s -> file_diff );
411- clear_add_i_state (& s -> s );
411+ interactive_config_clear (& s -> cfg );
412412}
413413
414414__attribute__((format (printf , 2 , 3 )))
@@ -417,9 +417,9 @@ static void err(struct add_p_state *s, const char *fmt, ...)
417417 va_list args ;
418418
419419 va_start (args , fmt );
420- fputs (s -> s . cfg .error_color , stdout );
420+ fputs (s -> cfg .error_color , stdout );
421421 vprintf (fmt , args );
422- puts (s -> s . cfg .reset_color_interactive );
422+ puts (s -> cfg .reset_color_interactive );
423423 va_end (args );
424424}
425425
@@ -437,7 +437,7 @@ static void setup_child_process(struct add_p_state *s,
437437
438438 cp -> git_cmd = 1 ;
439439 strvec_pushf (& cp -> env ,
440- INDEX_ENVIRONMENT "=%s" , s -> s . r -> index_file );
440+ INDEX_ENVIRONMENT "=%s" , s -> r -> index_file );
441441}
442442
443443static int parse_range (const char * * p ,
@@ -542,12 +542,12 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
542542 int res ;
543543
544544 strvec_pushv (& args , s -> mode -> diff_cmd );
545- if (s -> s . cfg .context != -1 )
546- strvec_pushf (& args , "--unified=%i" , s -> s . cfg .context );
547- if (s -> s . cfg .interhunkcontext != -1 )
548- strvec_pushf (& args , "--inter-hunk-context=%i" , s -> s . cfg .interhunkcontext );
549- if (s -> s . cfg .interactive_diff_algorithm )
550- strvec_pushf (& args , "--diff-algorithm=%s" , s -> s . cfg .interactive_diff_algorithm );
545+ if (s -> cfg .context != -1 )
546+ strvec_pushf (& args , "--unified=%i" , s -> cfg .context );
547+ if (s -> cfg .interhunkcontext != -1 )
548+ strvec_pushf (& args , "--inter-hunk-context=%i" , s -> cfg .interhunkcontext );
549+ if (s -> cfg .interactive_diff_algorithm )
550+ strvec_pushf (& args , "--diff-algorithm=%s" , s -> cfg .interactive_diff_algorithm );
551551 if (s -> revision ) {
552552 struct object_id oid ;
553553 strvec_push (& args ,
@@ -576,9 +576,9 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
576576 }
577577 strbuf_complete_line (plain );
578578
579- if (want_color_fd (1 , s -> s . cfg .use_color_diff )) {
579+ if (want_color_fd (1 , s -> cfg .use_color_diff )) {
580580 struct child_process colored_cp = CHILD_PROCESS_INIT ;
581- const char * diff_filter = s -> s . cfg .interactive_diff_filter ;
581+ const char * diff_filter = s -> cfg .interactive_diff_filter ;
582582
583583 setup_child_process (s , & colored_cp , NULL );
584584 xsnprintf ((char * )args .v [color_arg_index ], 8 , "--color" );
@@ -811,7 +811,7 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
811811 hunk -> colored_end - hunk -> colored_start );
812812 return ;
813813 } else {
814- strbuf_addstr (out , s -> s . cfg .fraginfo_color );
814+ strbuf_addstr (out , s -> cfg .fraginfo_color );
815815 p = s -> colored .buf + header -> colored_extra_start ;
816816 len = header -> colored_extra_end
817817 - header -> colored_extra_start ;
@@ -833,7 +833,7 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk,
833833 if (len )
834834 strbuf_add (out , p , len );
835835 else if (colored )
836- strbuf_addf (out , "%s\n" , s -> s . cfg .reset_color_diff );
836+ strbuf_addf (out , "%s\n" , s -> cfg .reset_color_diff );
837837 else
838838 strbuf_addch (out , '\n' );
839839 }
@@ -1222,12 +1222,12 @@ static void recolor_hunk(struct add_p_state *s, struct hunk *hunk)
12221222
12231223 strbuf_addstr (& s -> colored ,
12241224 plain [current ] == '-' ?
1225- s -> s . cfg .file_old_color :
1225+ s -> cfg .file_old_color :
12261226 plain [current ] == '+' ?
1227- s -> s . cfg .file_new_color :
1228- s -> s . cfg .context_color );
1227+ s -> cfg .file_new_color :
1228+ s -> cfg .context_color );
12291229 strbuf_add (& s -> colored , plain + current , eol - current );
1230- strbuf_addstr (& s -> colored , s -> s . cfg .reset_color_diff );
1230+ strbuf_addstr (& s -> colored , s -> cfg .reset_color_diff );
12311231 if (next > eol )
12321232 strbuf_add (& s -> colored , plain + eol , next - eol );
12331233 current = next ;
@@ -1356,7 +1356,7 @@ static int run_apply_check(struct add_p_state *s,
13561356
13571357static int read_single_character (struct add_p_state * s )
13581358{
1359- if (s -> s . cfg .use_single_key ) {
1359+ if (s -> cfg .use_single_key ) {
13601360 int res = read_key_without_echo (& s -> answer );
13611361 printf ("%s\n" , res == EOF ? "" : s -> answer .buf );
13621362 return res ;
@@ -1370,7 +1370,7 @@ static int read_single_character(struct add_p_state *s)
13701370static int prompt_yesno (struct add_p_state * s , const char * prompt )
13711371{
13721372 for (;;) {
1373- color_fprintf (stdout , s -> s . cfg .prompt_color , "%s" , _ (prompt ));
1373+ color_fprintf (stdout , s -> cfg .prompt_color , "%s" , _ (prompt ));
13741374 fflush (stdout );
13751375 if (read_single_character (s ) == EOF )
13761376 return -1 ;
@@ -1677,15 +1677,15 @@ static int patch_update_file(struct add_p_state *s,
16771677 else
16781678 prompt_mode_type = PROMPT_HUNK ;
16791679
1680- printf ("%s(%" PRIuMAX "/%" PRIuMAX ") " , s -> s . cfg .prompt_color ,
1680+ printf ("%s(%" PRIuMAX "/%" PRIuMAX ") " , s -> cfg .prompt_color ,
16811681 (uintmax_t )hunk_index + 1 ,
16821682 (uintmax_t )(file_diff -> hunk_nr
16831683 ? file_diff -> hunk_nr
16841684 : 1 ));
16851685 printf (_ (s -> mode -> prompt_mode [prompt_mode_type ]),
16861686 s -> buf .buf );
1687- if (* s -> s . cfg .reset_color_interactive )
1688- fputs (s -> s . cfg .reset_color_interactive , stdout );
1687+ if (* s -> cfg .reset_color_interactive )
1688+ fputs (s -> cfg .reset_color_interactive , stdout );
16891689 fflush (stdout );
16901690 if (read_single_character (s ) == EOF )
16911691 break ;
@@ -1847,7 +1847,7 @@ static int patch_update_file(struct add_p_state *s,
18471847 err (s , _ ("Sorry, cannot split this hunk" ));
18481848 } else if (!split_hunk (s , file_diff ,
18491849 hunk - file_diff -> hunk )) {
1850- color_fprintf_ln (stdout , s -> s . cfg .header_color ,
1850+ color_fprintf_ln (stdout , s -> cfg .header_color ,
18511851 _ ("Split into %d hunks." ),
18521852 (int )splittable_into );
18531853 rendered_hunk_index = -1 ;
@@ -1865,7 +1865,7 @@ static int patch_update_file(struct add_p_state *s,
18651865 } else if (s -> answer .buf [0 ] == '?' ) {
18661866 const char * p = _ (help_patch_remainder ), * eol = p ;
18671867
1868- color_fprintf (stdout , s -> s . cfg .help_color , "%s" ,
1868+ color_fprintf (stdout , s -> cfg .help_color , "%s" ,
18691869 _ (s -> mode -> help_patch_text ));
18701870
18711871 /*
@@ -1883,7 +1883,7 @@ static int patch_update_file(struct add_p_state *s,
18831883 if (* p != '?' && !strchr (s -> buf .buf , * p ))
18841884 continue ;
18851885
1886- color_fprintf_ln (stdout , s -> s . cfg .help_color ,
1886+ color_fprintf_ln (stdout , s -> cfg .help_color ,
18871887 "%.*s" , (int )(eol - p ), p );
18881888 }
18891889 } else {
@@ -1903,7 +1903,7 @@ static int patch_update_file(struct add_p_state *s,
19031903 strbuf_reset (& s -> buf );
19041904 reassemble_patch (s , file_diff , 0 , & s -> buf );
19051905
1906- discard_index (s -> s . r -> index );
1906+ discard_index (s -> r -> index );
19071907 if (s -> mode -> apply_for_checkout )
19081908 apply_for_checkout (s , & s -> buf ,
19091909 s -> mode -> is_reverse );
@@ -1914,8 +1914,8 @@ static int patch_update_file(struct add_p_state *s,
19141914 NULL , 0 , NULL , 0 ))
19151915 error (_ ("'git apply' failed" ));
19161916 }
1917- if (repo_read_index (s -> s . r ) >= 0 )
1918- repo_refresh_and_write_index (s -> s . r , REFRESH_QUIET , 0 ,
1917+ if (repo_read_index (s -> r ) >= 0 )
1918+ repo_refresh_and_write_index (s -> r , REFRESH_QUIET , 0 ,
19191919 1 , NULL , NULL , NULL );
19201920 }
19211921
@@ -1928,11 +1928,15 @@ int run_add_p(struct repository *r, enum add_p_mode mode,
19281928 const struct pathspec * ps )
19291929{
19301930 struct add_p_state s = {
1931- { r }, STRBUF_INIT , STRBUF_INIT , STRBUF_INIT , STRBUF_INIT
1931+ .r = r ,
1932+ .answer = STRBUF_INIT ,
1933+ .buf = STRBUF_INIT ,
1934+ .plain = STRBUF_INIT ,
1935+ .colored = STRBUF_INIT ,
19321936 };
19331937 size_t i , binary_count = 0 ;
19341938
1935- init_add_i_state (& s .s , r , opts );
1939+ interactive_config_init (& s .cfg , r , opts );
19361940
19371941 if (mode == ADD_P_STASH )
19381942 s .mode = & patch_mode_stash ;
0 commit comments