@@ -468,12 +468,14 @@ static void update_one(const char *path)
468
468
report ("add '%s'" , path );
469
469
}
470
470
471
- static void read_index_info (int line_termination )
471
+ static void read_index_info (int nul_term_line )
472
472
{
473
473
struct strbuf buf = STRBUF_INIT ;
474
474
struct strbuf uq = STRBUF_INIT ;
475
+ strbuf_getline_fn getline_fn ;
475
476
476
- while (strbuf_getline (& buf , stdin , line_termination ) != EOF ) {
477
+ getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf ;
478
+ while (getline_fn (& buf , stdin ) != EOF ) {
477
479
char * ptr , * tab ;
478
480
char * path_name ;
479
481
unsigned char sha1 [20 ];
@@ -522,7 +524,7 @@ static void read_index_info(int line_termination)
522
524
goto bad_line ;
523
525
524
526
path_name = ptr ;
525
- if (line_termination && path_name [0 ] == '"' ) {
527
+ if (! nul_term_line && path_name [0 ] == '"' ) {
526
528
strbuf_reset (& uq );
527
529
if (unquote_c_style (& uq , path_name , NULL )) {
528
530
die ("git update-index: bad quoting of path name" );
@@ -844,12 +846,12 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,
844
846
static int stdin_cacheinfo_callback (struct parse_opt_ctx_t * ctx ,
845
847
const struct option * opt , int unset )
846
848
{
847
- int * line_termination = opt -> value ;
849
+ int * nul_term_line = opt -> value ;
848
850
849
851
if (ctx -> argc != 1 )
850
852
return error ("option '%s' must be the last argument" , opt -> long_name );
851
853
allow_add = allow_replace = allow_remove = 1 ;
852
- read_index_info (* line_termination );
854
+ read_index_info (* nul_term_line );
853
855
return 0 ;
854
856
}
855
857
@@ -901,7 +903,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx,
901
903
902
904
int cmd_update_index (int argc , const char * * argv , const char * prefix )
903
905
{
904
- int newfd , entries , has_errors = 0 , line_termination = '\n' ;
906
+ int newfd , entries , has_errors = 0 , nul_term_line = 0 ;
905
907
int untracked_cache = -1 ;
906
908
int read_from_stdin = 0 ;
907
909
int prefix_length = prefix ? strlen (prefix ) : 0 ;
@@ -912,6 +914,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
912
914
int split_index = -1 ;
913
915
struct lock_file * lock_file ;
914
916
struct parse_opt_ctx_t ctx ;
917
+ strbuf_getline_fn getline_fn ;
915
918
int parseopt_state = PARSE_OPT_UNKNOWN ;
916
919
struct option options [] = {
917
920
OPT_BIT ('q' , NULL , & refresh_args .flags ,
@@ -963,13 +966,13 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
963
966
N_ ("add to index only; do not add content to object database" ), 1 ),
964
967
OPT_SET_INT (0 , "force-remove" , & force_remove ,
965
968
N_ ("remove named paths even if present in worktree" ), 1 ),
966
- OPT_SET_INT ('z' , NULL , & line_termination ,
967
- N_ ("with --stdin: input lines are terminated by null bytes" ), '\0' ),
969
+ OPT_BOOL ('z' , NULL , & nul_term_line ,
970
+ N_ ("with --stdin: input lines are terminated by null bytes" )),
968
971
{OPTION_LOWLEVEL_CALLBACK , 0 , "stdin" , & read_from_stdin , NULL ,
969
972
N_ ("read list of paths to be updated from standard input" ),
970
973
PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
971
974
(parse_opt_cb * ) stdin_callback },
972
- {OPTION_LOWLEVEL_CALLBACK , 0 , "index-info" , & line_termination , NULL ,
975
+ {OPTION_LOWLEVEL_CALLBACK , 0 , "index-info" , & nul_term_line , NULL ,
973
976
N_ ("add entries from standard input to the index" ),
974
977
PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
975
978
(parse_opt_cb * ) stdin_cacheinfo_callback },
@@ -1057,6 +1060,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1057
1060
}
1058
1061
}
1059
1062
argc = parse_options_end (& ctx );
1063
+
1064
+ getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf ;
1060
1065
if (preferred_index_format ) {
1061
1066
if (preferred_index_format < INDEX_FORMAT_LB ||
1062
1067
INDEX_FORMAT_UB < preferred_index_format )
@@ -1073,9 +1078,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1073
1078
struct strbuf buf = STRBUF_INIT , nbuf = STRBUF_INIT ;
1074
1079
1075
1080
setup_work_tree ();
1076
- while (strbuf_getline (& buf , stdin , line_termination ) != EOF ) {
1081
+ while (getline_fn (& buf , stdin ) != EOF ) {
1077
1082
char * p ;
1078
- if (line_termination && buf .buf [0 ] == '"' ) {
1083
+ if (! nul_term_line && buf .buf [0 ] == '"' ) {
1079
1084
strbuf_reset (& nbuf );
1080
1085
if (unquote_c_style (& nbuf , buf .buf , NULL ))
1081
1086
die ("line is badly quoted" );
0 commit comments