git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 03/11] diffcore-rename.c: move code around to prepare for the next patch

From
Karsten Blees <karsten.blees@gmail.com>
Date
Oct 1, 2013, 09:36 UTC
Message-ID
<524A9783.8020107@gmail.com>
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
Previous: Karsten BleesNext: Karsten Blees
Message 4 of 14 in “New hash table implementation”
  1. 00/11 New hash table implementationKarsten Blees, Oct 1, 2013
  2. 01/11 add a hashtable implementation that supports O(1) removalKarsten Blees, Oct 1, 2013
  3. 02/11 buitin/describe.c: use new hash map implementationKarsten Blees, Oct 1, 2013
  4. 03/11 diffcore-rename.c: move code around to prepare for the next patchKarsten Blees, Oct 1, 2013
  5. 04/11 diffcore-rename.c: simplify finding exact renamesKarsten Blees, Oct 1, 2013
  6. 05/11 diffcore-rename.c: use new hash map implementationKarsten Blees, Oct 1, 2013
  7. 06/11 name-hash.c: use new hash map implementation for directoriesKarsten Blees, Oct 1, 2013
  8. 07/11 name-hash.c: remove unreferenced directory entriesKarsten Blees, Oct 1, 2013
  9. 08/11 name-hash.c: use new hash map implementation for cache entriesKarsten Blees, Oct 1, 2013
  10. 09/11 name-hash.c: remove cache entries instead of marking them CE_UNHASHEDKarsten Blees, Oct 1, 2013
  11. 10/11 read-cache.c: fix memory leaks caused by removed cache entriesKarsten Blees, Oct 1, 2013
  12. Thomas RastOct 19, 2013
  13. fixup! read-cache.c: fix memory leaks caused by removed cache, entriesKarsten Blees, Oct 22, 2013
  14. 11/11 remove old hash.[ch] implementationKarsten Blees, Oct 1, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.