X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=diffcore-rename.c;h=794e5cc7d5d984f49d65f93348199724ec753af9;hb=b2bf34d6c5f0867ab189fc64b1c519bfa613275d;hp=9a13cafd6856607f429b517067c3f4c03975fb36;hpb=38c6f78059c3060db6f94b24f4a90063a91090d2;p=git.git diff --git a/diffcore-rename.c b/diffcore-rename.c index 9a13cafd..794e5cc7 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -77,12 +77,12 @@ static int estimate_similarity(struct diff_filespec *src, /* We would not consider edits that change the file size so * drastically. delta_size must be smaller than - * minimum_score/MAX_SCORE * min(src->size, dst->size). + * (MAX_SCORE-minimum_score)/MAX_SCORE * min(src->size, dst->size). * Note that base_size == 0 case is handled here already * and the final score computation below would not have a * divide-by-zero issue. */ - if (base_size * minimum_score < delta_size * MAX_SCORE) + if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE) return 0; delta = diff_delta(src->data, src->size, @@ -142,7 +142,7 @@ static void debug_filespec(struct diff_filespec *s, int x, const char *one) fprintf(stderr, "queue[%d] %s (%s) %s %06o %s\n", x, one, s->path, - s->file_valid ? "valid" : "invalid", + DIFF_FILE_VALID(s) ? "valid" : "invalid", s->mode, s->sha1_valid ? sha1_to_hex(s->sha1) : ""); fprintf(stderr, "queue[%d] %s size %lu flags %d\n", @@ -210,7 +210,7 @@ static int needs_to_stay(struct diff_queue_struct *q, int i, */ while (i < q->nr) { struct diff_filepair *p = q->queue[i++]; - if (!p->two->file_valid) + if (!DIFF_FILE_VALID(p->two)) continue; /* removed is fine */ if (strcmp(p->one->path, it->path)) continue; /* not relevant */ @@ -224,8 +224,25 @@ static int needs_to_stay(struct diff_queue_struct *q, int i, return 0; } -void diff_detect_rename(int detect_rename, - int minimum_score) +int diff_scoreopt_parse(const char *opt) +{ + int diglen, num, scale, i; + if (opt[0] != '-' || (opt[1] != 'M' && opt[1] != 'C')) + return -1; /* that is not a -M nor -C option */ + diglen = strspn(opt+2, "0123456789"); + if (diglen == 0 || strlen(opt+2) != diglen) + return 0; /* use default */ + sscanf(opt+2, "%d", &num); + for (i = 0, scale = 1; i < diglen; i++) + scale *= 10; + + /* user says num divided by scale and we say internally that + * is MAX_SCORE * num / scale. + */ + return MAX_SCORE * num / scale; +} + +void diffcore_rename(int detect_rename, int minimum_score) { struct diff_queue_struct *q = &diff_queued_diff; struct diff_queue_struct outq; @@ -235,6 +252,8 @@ void diff_detect_rename(int detect_rename, int h, i, j; int num_create, num_src, dst_cnt, src_cnt; + if (!minimum_score) + minimum_score = DEFAULT_MINIMUM_SCORE; outq.queue = NULL; outq.nr = outq.alloc = 0; @@ -247,12 +266,12 @@ void diff_detect_rename(int detect_rename, for (i = 0; i < q->nr; i++) { struct diff_filepair *p = q->queue[i]; - if (!p->one->file_valid) - if (!p->two->file_valid) + if (!DIFF_FILE_VALID(p->one)) + if (!DIFF_FILE_VALID(p->two)) continue; /* ignore nonsense */ else diff_rename_pool_add(&created, p->two); - else if (!p->two->file_valid) + else if (!DIFF_FILE_VALID(p->two)) diff_rename_pool_add(&deleted, p->one); else if (1 < detect_rename) /* find copy, too */ diff_rename_pool_add(&stay, p->one); @@ -340,15 +359,15 @@ void diff_detect_rename(int detect_rename, */ for (i = 0; i < q->nr; i++) { struct diff_filepair *dp, *p = q->queue[i]; - if (!p->one->file_valid) { - if (p->two->file_valid) { + if (!DIFF_FILE_VALID(p->one)) { + if (DIFF_FILE_VALID(p->two)) { /* creation */ dp = diff_queue(&outq, p->one, p->two); dp->xfrm_work = 4; } /* otherwise it is a nonsense; just ignore it */ } - else if (!p->two->file_valid) { + else if (!DIFF_FILE_VALID(p->two)) { /* deletion */ dp = diff_queue(&outq, p->one, p->two); dp->xfrm_work = 2; @@ -374,14 +393,14 @@ void diff_detect_rename(int detect_rename, /* Copy it out to q, removing duplicates. */ for (i = 0; i < outq.nr; i++) { struct diff_filepair *p = outq.queue[i]; - if (!p->one->file_valid) { + if (!DIFF_FILE_VALID(p->one)) { /* created */ if (p->two->xfrm_flags & RENAME_DST_MATCHED) ; /* rename/copy created it already */ else diff_queue(q, p->one, p->two); } - else if (!p->two->file_valid) { + else if (!DIFF_FILE_VALID(p->two)) { /* deleted */ if (p->one->xfrm_flags & RENAME_SRC_GONE) ; /* rename/copy deleted it already */