From: Karsten Blees <karsten.blees@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Karsten Blees <karsten.blees@gmail.com>
Subject: [PATCH v3 03/11] diffcore-rename.c: move code around to prepare for the next patch
Date: Tue, 01 Oct 2013 11:36:03 +0200 [thread overview]
Message-ID: <524A9783.8020107@gmail.com> (raw)
In-Reply-To: <524A96FF.5090604@gmail.com>
No actual code changes, just move hash_filespec up and outdent part of
find_identical_files.
Signed-off-by: Karsten Blees <blees@dcon.de>
---
diffcore-rename.c | 98 +++++++++++++++++++++++++++----------------------------
1 file changed, 49 insertions(+), 49 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 6c7a72f..008a60c 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -248,6 +248,18 @@ struct file_similarity {
struct file_similarity *next;
};
+static unsigned int hash_filespec(struct diff_filespec *filespec)
+{
+ unsigned int hash;
+ if (!filespec->sha1_valid) {
+ if (diff_populate_filespec(filespec, 0))
+ return 0;
+ hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
+ }
+ memcpy(&hash, filespec->sha1, sizeof(hash));
+ return hash;
+}
+
static int find_identical_files(struct file_similarity *src,
struct file_similarity *dst,
struct diff_options *options)
@@ -258,46 +270,46 @@ static int find_identical_files(struct file_similarity *src,
* Walk over all the destinations ...
*/
do {
- struct diff_filespec *target = dst->filespec;
- struct file_similarity *p, *best;
- int i = 100, best_score = -1;
-
- /*
- * .. to find the best source match
- */
- best = NULL;
- for (p = src; p; p = p->next) {
- int score;
- struct diff_filespec *source = p->filespec;
-
- /* False hash collision? */
- if (hashcmp(source->sha1, target->sha1))
- continue;
- /* Non-regular files? If so, the modes must match! */
- if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
- if (source->mode != target->mode)
- continue;
- }
- /* Give higher scores to sources that haven't been used already */
- score = !source->rename_used;
- if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
- continue;
- score += basename_same(source, target);
- if (score > best_score) {
- best = p;
- best_score = score;
- if (score == 2)
- break;
- }
+ struct diff_filespec *target = dst->filespec;
+ struct file_similarity *p, *best;
+ int i = 100, best_score = -1;
- /* Too many identical alternatives? Pick one */
- if (!--i)
- break;
+ /*
+ * .. to find the best source match
+ */
+ best = NULL;
+ for (p = src; p; p = p->next) {
+ int score;
+ struct diff_filespec *source = p->filespec;
+
+ /* False hash collision? */
+ if (hashcmp(source->sha1, target->sha1))
+ continue;
+ /* Non-regular files? If so, the modes must match! */
+ if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
+ if (source->mode != target->mode)
+ continue;
}
- if (best) {
- record_rename_pair(dst->index, best->index, MAX_SCORE);
- renames++;
+ /* Give higher scores to sources that haven't been used already */
+ score = !source->rename_used;
+ if (source->rename_used && options->detect_rename != DIFF_DETECT_COPY)
+ continue;
+ score += basename_same(source, target);
+ if (score > best_score) {
+ best = p;
+ best_score = score;
+ if (score == 2)
+ break;
}
+
+ /* Too many identical alternatives? Pick one */
+ if (!--i)
+ break;
+ }
+ if (best) {
+ record_rename_pair(dst->index, best->index, MAX_SCORE);
+ renames++;
+ }
} while ((dst = dst->next) != NULL);
return renames;
}
@@ -343,18 +355,6 @@ static int find_same_files(void *ptr, void *data)
return ret;
}
-static unsigned int hash_filespec(struct diff_filespec *filespec)
-{
- unsigned int hash;
- if (!filespec->sha1_valid) {
- if (diff_populate_filespec(filespec, 0))
- return 0;
- hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
- }
- memcpy(&hash, filespec->sha1, sizeof(hash));
- return hash;
-}
-
static void insert_file_table(struct hash_table *table, int src_dst, int index, struct diff_filespec *filespec)
{
void **pos;
--
1.8.4.11.g4f52745.dirty
next prev parent reply other threads:[~2013-10-01 9:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-01 9:33 [PATCH v3 00/11] New hash table implementation Karsten Blees
2013-10-01 9:34 ` [PATCH v3 01/11] add a hashtable implementation that supports O(1) removal Karsten Blees
2013-10-01 9:35 ` [PATCH v3 02/11] buitin/describe.c: use new hash map implementation Karsten Blees
2013-10-01 9:36 ` Karsten Blees [this message]
2013-10-01 9:36 ` [PATCH v3 04/11] diffcore-rename.c: simplify finding exact renames Karsten Blees
2013-10-01 9:37 ` [PATCH v3 05/11] diffcore-rename.c: use new hash map implementation Karsten Blees
2013-10-01 9:37 ` [PATCH v3 06/11] name-hash.c: use new hash map implementation for directories Karsten Blees
2013-10-01 9:38 ` [PATCH v3 07/11] name-hash.c: remove unreferenced directory entries Karsten Blees
2013-10-01 9:39 ` [PATCH v3 08/11] name-hash.c: use new hash map implementation for cache entries Karsten Blees
2013-10-01 9:39 ` [PATCH v3 09/11] name-hash.c: remove cache entries instead of marking them CE_UNHASHED Karsten Blees
2013-10-01 9:40 ` [PATCH v3 10/11] read-cache.c: fix memory leaks caused by removed cache entries Karsten Blees
2013-10-19 19:28 ` Thomas Rast
2013-10-22 13:13 ` [PATCH] fixup! read-cache.c: fix memory leaks caused by removed cache, entries Karsten Blees
2013-10-01 9:40 ` [PATCH v3 11/11] remove old hash.[ch] implementation Karsten Blees
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=524A9783.8020107@gmail.com \
--to=karsten.blees@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.