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

[PATCH] Fix llist_sorted_difference_inplace in git-pack-redundant

From
Lukas Sandström <lukass@etek.chalmers.se>
Date
Nov 15, 2005, 21:24 UTC
Message-ID
<437A51F2.4000106@etek.chalmers.se>
In-Reply-To
<81b0412b0511150749g5672158v7b39c02ffdf13e08@mail.gmail.com>

Simplify and actually make llist_sorted_difference_inplace work by using llist_sorted_remove instead of duplicating parts of the code.

Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se>

--- Looking at the code; I must have been tired when I wrote llist_sorted_difference_inplace. This should hopefully fix things up nicely. Note that I think the old version got the case "remove last element from list" wrong too.

I think the Signed-off line is in utf8 this time. Tell me if it works better, of if I just should change my name ;)

 pack-redundant.c |   47 +++++++++++++++--------------------------------
 1 files changed, 15 insertions(+), 32 deletions(-)

applies-to: 4b6dbe856a3e63699b299c76f4f1fc5cb34cbe26 560aa97889ef028fed0678389d4bb05ebf3ead62

diff --git a/pack-redundant.c b/pack-redundant.c
index 28b82ee..fcb36ff 100644
--- a/pack-redundant.c
+++ b/pack-redundant.c
@@ -127,38 +127,6 @@ inline struct llist_item * llist_insert_
 	return llist_insert_back(list, sha1);
 }
 
-/* computes A\B */
-void llist_sorted_difference_inplace(struct llist *A,
-				     struct llist *B)
-{
-	struct llist_item *prev, *a, *b, *x;
-
-	prev = a = A->front;
-	b = B->front;
-
-	while (a != NULL && b != NULL) {
-		int cmp = memcmp(a->sha1, b->sha1, 20);
-		if (!cmp) {
-			x = a;
-			if (a == A->front)
-				A->front = a->next;
-			a = prev->next = a->next;
-
-			if (a == NULL) /* end of list */
-				A->back = prev;
-			A->size--;
-			free(x);
-			b = b->next;
-		} else
-			if (cmp > 0)
-				b = b->next;
-			else {
-				prev = a;
-				a = a->next;
-			}
-	}
-}
-
 /* returns a pointer to an item in front of sha1 */
 inline struct llist_item * llist_sorted_remove(struct llist *list, char *sha1,
 					       struct llist_item *hint)
@@ -194,6 +162,21 @@ redo_from_start:
 	return prev;
 }
 
+/* computes A\B */
+void llist_sorted_difference_inplace(struct llist *A,
+				     struct llist *B)
+{
+	struct llist_item *hint, *b;
+
+	hint = NULL;
+	b = B->front;
+
+	while (b) {
+		hint = llist_sorted_remove(A, b->sha1, hint);
+		b = b->next;
+	}
+}
+
 inline struct pack_list * pack_list_insert(struct pack_list **pl,
 					   struct pack_list *entry)
 {
---
0.99.9.GIT
Previous: Lukas SandströmNext: Alex Riesen
Message 6 of 21 in “fix git-pack-redundant crashing sometimes”
  1. Alex RiesenNov 15, 2005
  2. Timo HirvonenNov 15, 2005
  3. Alex RiesenNov 15, 2005
  4. Linus TorvaldsNov 15, 2005
  5. Lukas SandströmNov 15, 2005
  6. Fix llist_sorted_difference_inplace in git-pack-redundantLukas Sandström, Nov 15, 2005
  7. Alex RiesenNov 15, 2005
  8. Lukas SandströmNov 15, 2005
  9. Alex RiesenNov 15, 2005
  10. Lukas SandströmNov 15, 2005
  11. Alex RiesenNov 16, 2005
  12. Alex RiesenNov 16, 2005
  13. Linus TorvaldsNov 15, 2005
  14. Junio C HamanoNov 16, 2005
  15. Lukas SandströmNov 16, 2005
  16. Lukas SandströmNov 16, 2005
  17. Matthias UrlichsNov 17, 2005
  18. Fredrik KuivinenNov 17, 2005
  19. Make git-pack-redundant non-horribly slow on large sets of packsLukas Sandström, Nov 17, 2005
  20. Fix bug introduced by the latest changes to git-pack-redundantLukas Sandström, Nov 18, 2005
  21. Fix a bug in get_all_permutations.Lukas Sandström, Nov 18, 2005

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.