From: H. Peter Anvin Date: Mon, 21 Nov 2005 22:10:23 GMT Subject: Re: Pure renames/copies Message-ID: <438245CF.9030501@zytor.com> In-Reply-To: <7vd5ktoe52.fsf@assigned-by-dhcp.cox.net> Junio C Hamano wrote: > "H. Peter Anvin" writes: > > >>Okay, in that post Linus suggests that -M without an argument should be >>== 100% (1.0), thus avoiding having to mess up the meaning of -M100 as >>0.100. It seems like a really odd thing to have -M100 mean something >>that's completely out of line with the rest of the meaning. > > True, but it might be too late to change that; I suspect people > expect -M to do a bit more than pure renames by now. > Okay, how about the following? It lets both -M1.0 and -M100% work, while keeping everything else compatible, and avoiding artificial special cases. -hpa diff --git a/diff.c b/diff.c index 0391e8c..df62d2b 100644 --- a/diff.c +++ b/diff.c @@ -843,11 +843,19 @@ static int parse_num(const char **cp_p) cnt = num = 0; scale = 1; - while ('0' <= (ch = *cp) && ch <= '9') { - if (cnt++ < 5) { - /* We simply ignore more than 5 digits precision. */ - scale *= 10; - num = num * 10 + ch - '0'; + for(;;) { + ch = *cp; + if ( ch == '.' ) { + scale = 1; + } else if ( ch == '%' ) { + scale = 100; + } else if ( ch >= '0' && ch <= '9' ) { + if ( scale < 100000 ) { + scale *= 10; + num = (num*10) + (ch-'0'); + } + } else { + break; } cp++; } @@ -856,7 +864,7 @@ static int parse_num(const char **cp_p) /* user says num divided by scale and we say internally that * 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)