15
15
#include "sigchain.h"
16
16
#include "submodule.h"
17
17
#include "ll-merge.h"
18
+ #include "string-list.h"
18
19
19
20
#ifdef NO_FAST_WORKING_DIRECTORY
20
21
#define FAST_WORKING_DIRECTORY 0
@@ -69,26 +70,30 @@ static int parse_diff_color_slot(const char *var, int ofs)
69
70
return -1 ;
70
71
}
71
72
72
- static int parse_dirstat_params (struct diff_options * options , const char * params ,
73
+ static int parse_dirstat_params (struct diff_options * options , const char * params_string ,
73
74
struct strbuf * errmsg )
74
75
{
75
- const char * p = params ;
76
- int p_len , ret = 0 ;
76
+ char * params_copy = xstrdup (params_string );
77
+ struct string_list params = STRING_LIST_INIT_NODUP ;
78
+ int ret = 0 ;
79
+ int i ;
77
80
78
- while (* p ) {
79
- p_len = strchrnul (p , ',' ) - p ;
80
- if (!memcmp (p , "changes" , p_len )) {
81
+ if (* params_copy )
82
+ string_list_split_in_place (& params , params_copy , ',' , -1 );
83
+ for (i = 0 ; i < params .nr ; i ++ ) {
84
+ const char * p = params .items [i ].string ;
85
+ if (!strcmp (p , "changes" )) {
81
86
DIFF_OPT_CLR (options , DIRSTAT_BY_LINE );
82
87
DIFF_OPT_CLR (options , DIRSTAT_BY_FILE );
83
- } else if (!memcmp (p , "lines" , p_len )) {
88
+ } else if (!strcmp (p , "lines" )) {
84
89
DIFF_OPT_SET (options , DIRSTAT_BY_LINE );
85
90
DIFF_OPT_CLR (options , DIRSTAT_BY_FILE );
86
- } else if (!memcmp (p , "files" , p_len )) {
91
+ } else if (!strcmp (p , "files" )) {
87
92
DIFF_OPT_CLR (options , DIRSTAT_BY_LINE );
88
93
DIFF_OPT_SET (options , DIRSTAT_BY_FILE );
89
- } else if (!memcmp (p , "noncumulative" , p_len )) {
94
+ } else if (!strcmp (p , "noncumulative" )) {
90
95
DIFF_OPT_CLR (options , DIRSTAT_CUMULATIVE );
91
- } else if (!memcmp (p , "cumulative" , p_len )) {
96
+ } else if (!strcmp (p , "cumulative" )) {
92
97
DIFF_OPT_SET (options , DIRSTAT_CUMULATIVE );
93
98
} else if (isdigit (* p )) {
94
99
char * end ;
@@ -100,24 +105,21 @@ static int parse_dirstat_params(struct diff_options *options, const char *params
100
105
while (isdigit (* ++ end ))
101
106
; /* nothing */
102
107
}
103
- if (end - p == p_len )
108
+ if (! * end )
104
109
options -> dirstat_permille = permille ;
105
110
else {
106
- strbuf_addf (errmsg , _ (" Failed to parse dirstat cut-off percentage '%.* s'\n" ),
107
- p_len , p );
111
+ strbuf_addf (errmsg , _ (" Failed to parse dirstat cut-off percentage '%s'\n" ),
112
+ p );
108
113
ret ++ ;
109
114
}
110
115
} else {
111
- strbuf_addf (errmsg , _ (" Unknown dirstat parameter '%.*s'\n" ),
112
- p_len , p );
116
+ strbuf_addf (errmsg , _ (" Unknown dirstat parameter '%s'\n" ), p );
113
117
ret ++ ;
114
118
}
115
119
116
- p += p_len ;
117
-
118
- if (* p )
119
- p ++ ; /* more parameters, swallow separator */
120
120
}
121
+ string_list_clear (& params , 0 );
122
+ free (params_copy );
121
123
return ret ;
122
124
}
123
125
0 commit comments