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

[PATCH 1/2] fast-export: deletion action first

From
Miguel Torroja <miguel.torroja@gmail.com>
Date
Apr 25, 2017, 00:12 UTC
Message-ID
<1493079137-1838-1-git-send-email-miguel.torroja@gmail.com>

The delete operations of the fast-export output should precede any addition belonging to the same commit, Addition and deletion with the same name entry could happen in case of file to directory and viceversa.

The fast-export sorting was added in 060df62 (fast-export: Fix output order of D/F changes). That change was made in order to fix the case of directory to file in the same commit, but it broke the reverse case (File to directory).

Signed-off-by: Miguel Torroja <miguel.torroja@gmail.com>
---
 builtin/fast-export.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index e022063..a3ab7da 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -260,26 +260,19 @@ static void export_blob(const struct object_id *oid)
 		free(buf);
 }
 
-static int depth_first(const void *a_, const void *b_)
+/*
+ * Compares two diff types to order based on output priorities.
+ */
+static int diff_type_cmp(const void *a_, const void *b_)
 {
 	const struct diff_filepair *a = *((const struct diff_filepair **)a_);
 	const struct diff_filepair *b = *((const struct diff_filepair **)b_);
-	const char *name_a, *name_b;
-	int len_a, len_b, len;
 	int cmp;
 
-	name_a = a->one ? a->one->path : a->two->path;
-	name_b = b->one ? b->one->path : b->two->path;
-
-	len_a = strlen(name_a);
-	len_b = strlen(name_b);
-	len = (len_a < len_b) ? len_a : len_b;
-
-	/* strcmp will sort 'd' before 'd/e', we want 'd/e' before 'd' */
-	cmp = memcmp(name_a, name_b, len);
-	if (cmp)
-		return cmp;
-	cmp = len_b - len_a;
+	/*
+	 * Move Delete entries first so that an addition is always reported after
+	 */
+	cmp = (b->status == DIFF_STATUS_DELETED) - (a->status == DIFF_STATUS_DELETED);
 	if (cmp)
 		return cmp;
 	/*
@@ -347,7 +340,7 @@ static void show_filemodify(struct diff_queue_struct *q,
 	 * Handle files below a directory first, in case they are all deleted
 	 * and the directory changes to a file or symlink.
 	 */
-	QSORT(q->queue, q->nr, depth_first);
+	QSORT(q->queue, q->nr, diff_type_cmp);
 
 	for (i = 0; i < q->nr; i++) {
 		struct diff_filespec *ospec = q->queue[i]->one;
-- 
2.1.4
Next: Miguel Torroja
Message 1 of 9 in “fast-export: deletion action first”
  1. 1/2 fast-export: deletion action firstMiguel Torroja, Apr 25, 2017
  2. 2/2 fast-export: DIFF_STATUS_RENAMED instead of 'R'Miguel Torroja, Apr 25, 2017
  3. Jeff KingApr 25, 2017
  4. Junio C HamanoApr 25, 2017
  5. Jeff KingApr 25, 2017
  6. Junio C HamanoApr 25, 2017
  7. Jeff KingApr 25, 2017
  8. fast-export: deletion action firstMiguel Torroja, May 4, 2017
  9. miguel torrojaMay 4, 2017

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.