rename/copy score parsing updates.
Better variant, which handles stuff like "4.5%" and rejects "192.168.0.1". Additionally, make sure numbers are unsigned (I'm making them unsigned long just for the hell of it), to make sure that artificial wraparound scenarios don't cause harm. -hpa [jc: with this, -M100 changes its meaning back to 10%. People wanting to say "pure renames only" should now say -M100% or -M1.0; sounds a bit like an earthquake, but arguably things are more consistent this way ;-)] Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
f35230fb11
commit
1b1480ff6a
31
diff.c
31
diff.c
@ -838,29 +838,38 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
|
|||||||
|
|
||||||
static int parse_num(const char **cp_p)
|
static int parse_num(const char **cp_p)
|
||||||
{
|
{
|
||||||
int num, scale, ch, cnt;
|
unsigned long num, scale;
|
||||||
|
int ch, dot;
|
||||||
const char *cp = *cp_p;
|
const char *cp = *cp_p;
|
||||||
|
|
||||||
cnt = num = 0;
|
num = 0;
|
||||||
scale = 1;
|
scale = 1;
|
||||||
while ('0' <= (ch = *cp) && ch <= '9') {
|
dot = 0;
|
||||||
if (cnt++ < 5) {
|
for(;;) {
|
||||||
/* We simply ignore more than 5 digits precision. */
|
ch = *cp;
|
||||||
|
if ( !dot && ch == '.' ) {
|
||||||
|
scale = 1;
|
||||||
|
dot = 1;
|
||||||
|
} else if ( ch == '%' ) {
|
||||||
|
scale = dot ? scale*100 : 100;
|
||||||
|
cp++; /* % is always at the end */
|
||||||
|
break;
|
||||||
|
} else if ( ch >= '0' && ch <= '9' ) {
|
||||||
|
if ( scale < 100000 ) {
|
||||||
scale *= 10;
|
scale *= 10;
|
||||||
num = num * 10 + ch - '0';
|
num = (num*10) + (ch-'0');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
cp++;
|
cp++;
|
||||||
}
|
}
|
||||||
*cp_p = cp;
|
*cp_p = cp;
|
||||||
|
|
||||||
/* special case: -M100 would mean 1.0 not 0.1 */
|
|
||||||
if (num == 100 && scale == 1000)
|
|
||||||
return MAX_SCORE;
|
|
||||||
|
|
||||||
/* user says num divided by scale and we say internally that
|
/* user says num divided by scale and we say internally that
|
||||||
* is MAX_SCORE * num / scale.
|
* is MAX_SCORE * num / scale.
|
||||||
*/
|
*/
|
||||||
return (MAX_SCORE * num / scale);
|
return (num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff_scoreopt_parse(const char *opt)
|
int diff_scoreopt_parse(const char *opt)
|
||||||
|
Loading…
Reference in New Issue
Block a user