@matheusbsbs / matheus-bagliano / commits / 81ac051d6a
Fork 0

Fix ugly magic special case in exact rename detection

For historical reasons, the exact rename detection had populated the filespecs for the entries it compared, and the rest of the similarity analysis depended on that. I hadn't even bothered to debug why that was the case when I re-did the rename detection, I just made the new one have the same broken behaviour, with a note about this special case. This fixes that fixme. The reason the exact rename detector needed to fill in the file sizes of the files it checked was that the _inexact_ rename detector was broken, and started comparing file sizes before it filled them in. Fixing that allows the exact phase to do the sane thing of never even caring (since all *it* cares about is really just the SHA1 itself, not the size nor the contents). It turns out that this also indirectly fixes a bug: trying to populate all the filespecs will run out of virtual memory if there is tons and tons of possible rename options. The fuzzy similarity analysis does the right thing in this regard, and free's the blob info after it has generated the hash tables, so the special case code caused more trouble than just some extra illogical code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Oct 26, 2007 at 16:51 UTC 81ac051d6ac9deef9a34de496fb981469aae77f0
1 file changed +14 -13
diffcore-rename.c
+14 -13
@@ -144,6 +144,20 @@ static int estimate_similarity(struct diff_filespec *src,
144 if (!S_ISREG(src->mode) || !S_ISREG(dst->mode))
145 return 0;
146
147 + /*
148 + * Need to check that source and destination sizes are
149 + * filled in before comparing them.
150 + *
151 + * If we already have "cnt_data" filled in, we know it's
152 + * all good (avoid checking the size for zero, as that
153 + * is a possible size - we really should have a flag to
154 + * say whether the size is valid or not!)
155 + */
156 + if (!src->cnt_data && diff_populate_filespec(src, 0))
157 + return 0;
158 + if (!dst->cnt_data && diff_populate_filespec(dst, 0))
159 + return 0;
160 +
161 max_size = ((src->size > dst->size) ? src->size : dst->size);
162 base_size = ((src->size < dst->size) ? src->size : dst->size);
163 delta_size = max_size - base_size;
@@ -159,11 +173,6 @@ static int estimate_similarity(struct diff_filespec *src,
173 if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE)
174 return 0;
175
162 - if ((!src->cnt_data && diff_populate_filespec(src, 0))
163 - || (!dst->cnt_data && diff_populate_filespec(dst, 0)))
164 - return 0; /* error but caught downstream */
165 -
166 -
176 delta_limit = (unsigned long)
177 (base_size * (MAX_SCORE-minimum_score) / MAX_SCORE);
178 if (diffcore_count_changes(src, dst,
@@ -270,19 +279,11 @@ static int find_identical_files(struct file_similarity *src,
279 return renames;
280 }
281
273 -/*
274 - * Note: the rest of the rename logic depends on this
275 - * phase also populating all the filespecs for any
276 - * entry that isn't matched up with an exact rename.
277 - */
282 static void free_similarity_list(struct file_similarity *p)
283 {
284 while (p) {
285 struct file_similarity *entry = p;
286 p = p->next;
283 -
284 - /* Stupid special case, see note above! */
285 - diff_populate_filespec(entry->filespec, 0);
287 free(entry);
288 }
289 }