diffcore-rename.c: move code around to prepare for the next patch

No actual code changes, just move hash_filespec up and outdent part of find_identical_files. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karsten Blees committed Nov 14, 2013 at 20:19 UTC 48f6407ffec1db18f5ef3316f0d761965bb17f1e
1 file changed +49 -49
diffcore-rename.c
+49 -49
@@ -248,6 +248,18 @@ struct file_similarity {
248 struct file_similarity *next;
249 };
250
251 +static unsigned int hash_filespec(struct diff_filespec *filespec)
252 +{
253 + unsigned int hash;
254 + if (!filespec->sha1_valid) {
255 + if (diff_populate_filespec(filespec, 0))
256 + return 0;
257 + hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
258 + }
259 + memcpy(&hash, filespec->sha1, sizeof(hash));
260 + return hash;
261 +}
262 +
263 static int find_identical_files(struct file_similarity *src,
264 struct file_similarity *dst,
265 struct diff_options *options)
@@ -258,46 +270,46 @@ static int find_identical_files(struct file_similarity *src,
270 * Walk over all the destinations ...
271 */
272 do {
261 - struct diff_filespec *target = dst->filespec;
262 - struct file_similarity *p, *best;
263 - int i = 100, best_score = -1;
264 -
265 - /*
266 - * .. to find the best source match
267 - */
268 - best = NULL;
269 - for (p = src; p; p = p->next) {
270 - int score;
271 - struct diff_filespec *source = p->filespec;
272 -
273 - /* False hash collision? */
274 - if (hashcmp(source->sha1, target->sha1))
275 - continue;
276 - /* Non-regular files? If so, the modes must match! */
277 - if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
278 - if (source->mode != target->mode)
279 - continue;
280 - }
281 - /* Give higher scores to sources that haven't been used already */
282 - score = !source->rename_used;
283 - if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
284 - continue;
285 - score += basename_same(source, target);
286 - if (score > best_score) {
287 - best = p;
288 - best_score = score;
289 - if (score == 2)
290 - break;
291 - }
273 + struct diff_filespec *target = dst->filespec;
274 + struct file_similarity *p, *best;
275 + int i = 100, best_score = -1;
276
293 - /* Too many identical alternatives? Pick one */
294 - if (!--i)
295 - break;
277 + /*
278 + * .. to find the best source match
279 + */
280 + best = NULL;
281 + for (p = src; p; p = p->next) {
282 + int score;
283 + struct diff_filespec *source = p->filespec;
284 +
285 + /* False hash collision? */
286 + if (hashcmp(source->sha1, target->sha1))
287 + continue;
288 + /* Non-regular files? If so, the modes must match! */
289 + if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
290 + if (source->mode != target->mode)
291 + continue;
292 }
297 - if (best) {
298 - record_rename_pair(dst->index, best->index, MAX_SCORE);
299 - renames++;
293 + /* Give higher scores to sources that haven't been used already */
294 + score = !source->rename_used;
295 + if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
296 + continue;
297 + score += basename_same(source, target);
298 + if (score > best_score) {
299 + best = p;
300 + best_score = score;
301 + if (score == 2)
302 + break;
303 }
304 +
305 + /* Too many identical alternatives? Pick one */
306 + if (!--i)
307 + break;
308 + }
309 + if (best) {
310 + record_rename_pair(dst->index, best->index, MAX_SCORE);
311 + renames++;
312 + }
313 } while ((dst = dst->next) != NULL);
314 return renames;
315 }
@@ -343,18 +355,6 @@ static int find_same_files(void *ptr, void *data)
355 return ret;
356 }
357
346 -static unsigned int hash_filespec(struct diff_filespec *filespec)
347 -{
348 - unsigned int hash;
349 - if (!filespec->sha1_valid) {
350 - if (diff_populate_filespec(filespec, 0))
351 - return 0;
352 - hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
353 - }
354 - memcpy(&hash, filespec->sha1, sizeof(hash));
355 - return hash;
356 -}
357 -
358 static void insert_file_table(struct hash_table *table, int src_dst, int index, struct diff_filespec *filespec)
359 {
360 void **pos;