"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
use got_object_id_queue_free() instead of hand-rolled code
To:
gameoftrees@openbsd.org
Date:
Mon, 06 Jan 2025 00:33:36 +1100

Download raw body.

Thread
While looking into implementing worktree diffs against repository
trees, I spotted a small opportunity to trim some code in got.c:
use the object_qid API to deallocate the queue.
Grepping the codebase uncovered a few other instances.

ok?


commit 2519ef4a5d9d866b93e5ca4d5bdbdde7c2e44032
from: Mark Jamsek <mark@jamsek.dev>
date: Sun Jan  5 12:49:24 2025 UTC

use got_object_id_queue_free() instead of hand-rolled code

M  cvg/cvg.c          |  1+  5-
M  got/got.c          |  1+  5-
M  gotd/repo_write.c  |  1+  5-
M  tog/tog.c          |  1+  6-

4 files changed, 4 insertions(+), 21 deletions(-)

commit - 1f1a52c62e4226a2d03e9e031fce6ba59bdfdd21
commit + 2519ef4a5d9d866b93e5ca4d5bdbdde7c2e44032
blob - b8e1d37587798c64a9b4aa32a9e41a81d15c4cf3
blob + 7ff4453eb37231d259aac420e9ab90fcd3615847
--- cvg/cvg.c
+++ cvg/cvg.c
@@ -3913,11 +3913,7 @@ print_commits(struct got_object_id *root_id, struct go
 		}
 	}
 done:
-	while (!STAILQ_EMPTY(&reversed_commits)) {
-		qid = STAILQ_FIRST(&reversed_commits);
-		STAILQ_REMOVE_HEAD(&reversed_commits, entry);
-		got_object_qid_free(qid);
-	}
+	got_object_id_queue_free(&reversed_commits);
 	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	if (search_pattern)
 		regfree(&regex);
blob - 4f9a936005900e7b54a3fd696424a48a92a1d262
blob + db6129ef317c31225f7da933b72b257309f299aa
--- got/got.c
+++ got/got.c
@@ -4691,11 +4691,7 @@ print_commits(struct got_object_id *root_id, struct go
 		}
 	}
 done:
-	while (!STAILQ_EMPTY(&reversed_commits)) {
-		qid = STAILQ_FIRST(&reversed_commits);
-		STAILQ_REMOVE_HEAD(&reversed_commits, entry);
-		got_object_qid_free(qid);
-	}
+	got_object_id_queue_free(&reversed_commits);
 	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	if (search_pattern)
 		regfree(&regex);
blob - 8f92913331bd60b19ef2fd111b33c55e075f4a01
blob + 12d6d0ad06ab75d791a22ba785294f8321da89df
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -1955,11 +1955,7 @@ print_commits(struct got_object_id *root_id, struct go
 done:
 	if (commit)
 		got_object_commit_close(commit);
-	while (!STAILQ_EMPTY(&reversed_commits)) {
-		qid = STAILQ_FIRST(&reversed_commits);
-		STAILQ_REMOVE_HEAD(&reversed_commits, entry);
-		got_object_qid_free(qid);
-	}
+	got_object_id_queue_free(&reversed_commits);
 	got_pathlist_free(&changed_paths, GOT_PATHLIST_FREE_ALL);
 	got_commit_graph_close(graph);
 	return err;
blob - 4eb0e6acc9ff0cfb7f844d192808a181c12ecfec
blob + 24da169be687cc8f1d49741d9aab788cd5867273
--- tog/tog.c
+++ tog/tog.c
@@ -8376,12 +8376,7 @@ close_blame_view(struct tog_view *view)
 	if (s->blame.thread)
 		err = stop_blame(&s->blame);
 
-	while (!STAILQ_EMPTY(&s->blamed_commits)) {
-		struct got_object_qid *blamed_commit;
-		blamed_commit = STAILQ_FIRST(&s->blamed_commits);
-		STAILQ_REMOVE_HEAD(&s->blamed_commits, entry);
-		got_object_qid_free(blamed_commit);
-	}
+	got_object_id_queue_free(&s->blamed_commits);
 
 	if (using_mock_io) {
 		struct tog_blame_thread_args *bta = &s->blame.thread_args;


-- 
Mark Jamsek <https://bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68