From 9f70b806920e3ea158d7e189a1ec668445c13359 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 21 Nov 2005 12:18:23 -0800 Subject: rename detection with -M100 means "exact renames only". When the user is interested in pure renames, there is no point doing the similarity scores. This changes the score argument parsing to special case -M100 (otherwise, it is a precision scaled value 0 <= v < 1 and would mean 0.1, not 1.0 --- if you do mean 0.1, you can say -M1), and optimizes the diffcore_rename transformation to only look at pure renames in that case. Signed-off-by: Junio C Hamano --- diff.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 0391e8c423..0f839c11b7 100644 --- a/diff.c +++ b/diff.c @@ -853,6 +853,10 @@ static int parse_num(const char **cp_p) } *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 * is MAX_SCORE * num / scale. */ -- cgit v1.3 From 1b1480ff6acda6e53325961e20fb13ae6895ee69 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 21 Nov 2005 14:17:12 -0800 Subject: 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 --- diff.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 0f839c11b7..ffe8a55234 100644 --- a/diff.c +++ b/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) { - int num, scale, ch, cnt; + unsigned long num, scale; + int ch, dot; const char *cp = *cp_p; - cnt = num = 0; + 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'; + dot = 0; + for(;;) { + 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; + num = (num*10) + (ch-'0'); + } + } else { + break; } 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 * 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) -- cgit v1.3 From 9ce392f4826558357af2b2c7eb6ad876fdb53a91 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 21 Nov 2005 22:52:37 -0800 Subject: Move diff.renamelimit out of default configuration. Otherwise we would end up linking all the unneeded stuff into git-daemon only to link with git_default_config. Signed-off-by: Junio C Hamano --- Makefile | 3 ++- config.c | 5 ----- diff-files.c | 2 +- diff-index.c | 2 +- diff-stages.c | 3 +++ diff-tree.c | 2 +- diff.c | 10 ++++++++++ diff.h | 1 + 8 files changed, 19 insertions(+), 9 deletions(-) (limited to 'diff.c') diff --git a/Makefile b/Makefile index ecbb88889d..a97a5d9595 100644 --- a/Makefile +++ b/Makefile @@ -482,7 +482,8 @@ deb: dist ### Cleaning rules clean: - rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o git $(PROGRAMS) $(LIB_FILE) + rm -f *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o $(LIB_FILE) + rm -f $(PROGRAMS) $(SIMPLE_PROGRAMS) git$X rm -f $(filter-out gitk,$(SCRIPTS)) rm -f *.spec *.pyc *.pyo rm -rf $(GIT_TARNAME) diff --git a/config.c b/config.c index 357c1caf97..18d59ee6e3 100644 --- a/config.c +++ b/config.c @@ -236,11 +236,6 @@ int git_default_config(const char *var, const char *value) return 0; } - if (!strcmp(var, "diff.renamelimit")) { - diff_rename_limit_default = git_config_int(var, value); - return 0; - } - /* Add other config variables here.. */ return 0; } diff --git a/diff-files.c b/diff-files.c index 17899390b8..38599b5b75 100644 --- a/diff-files.c +++ b/diff-files.c @@ -38,7 +38,7 @@ int main(int argc, const char **argv) const char *prefix = setup_git_directory(); int entries, i; - git_config(git_default_config); + git_config(git_diff_config); diff_setup(&diff_options); while (1 < argc && argv[1][0] == '-') { if (!strcmp(argv[1], "--")) { diff --git a/diff-index.c b/diff-index.c index c9a9f4c74d..0054883a5e 100644 --- a/diff-index.c +++ b/diff-index.c @@ -180,7 +180,7 @@ int main(int argc, const char **argv) int allow_options = 1; int i; - git_config(git_default_config); + git_config(git_diff_config); diff_setup(&diff_options); for (i = 1; i < argc; i++) { const char *arg = argv[i]; diff --git a/diff-stages.c b/diff-stages.c index 85170b21d6..9968d6ce1c 100644 --- a/diff-stages.c +++ b/diff-stages.c @@ -55,6 +55,9 @@ int main(int ac, const char **av) { int stage1, stage2; + setup_git_directory(); + + git_config(git_diff_config); read_cache(); diff_setup(&diff_options); while (1 < ac && av[1][0] == '-') { diff --git a/diff-tree.c b/diff-tree.c index 09d16ad661..da9c68c16f 100644 --- a/diff-tree.c +++ b/diff-tree.c @@ -164,7 +164,7 @@ int main(int argc, const char **argv) unsigned char sha1[2][20]; const char *prefix = setup_git_directory(); - git_config(git_default_config); + git_config(git_diff_config); nr_sha1 = 0; diff_setup(&diff_options); diff --git a/diff.c b/diff.c index ffe8a55234..2e0797bf3e 100644 --- a/diff.c +++ b/diff.c @@ -15,6 +15,16 @@ static int use_size_cache; int diff_rename_limit_default = -1; +int git_diff_config(const char *var, const char *value) +{ + if (!strcmp(var, "diff.renamelimit")) { + diff_rename_limit_default = git_config_int(var, value); + return 0; + } + + return git_default_config(var, value); +} + static char *quote_one(const char *str) { int needlen; diff --git a/diff.h b/diff.h index 9b2e1e62bb..32b4780173 100644 --- a/diff.h +++ b/diff.h @@ -77,6 +77,7 @@ extern int diff_scoreopt_parse(const char *opt); #define DIFF_SETUP_USE_CACHE 2 #define DIFF_SETUP_USE_SIZE_CACHE 4 +extern int git_diff_config(const char *var, const char *value); extern void diff_setup(struct diff_options *); extern int diff_opt_parse(struct diff_options *, const char **, int); extern int diff_setup_done(struct diff_options *); -- cgit v1.3