Thread (114 messages) 114 messages, 7 authors, 2d ago

Re: [PATCH v6 2/3] revision: add peek functions for lookahead

From: Chandra Pratap <hidden>
Date: 2026-06-21 06:42:28

+int revision_has_commits_after (struct rev_info *revs, int n)
+{
+       struct topo_walk_info *info = revs->topo_walk_info;
+
+       if (info) {
+               int visible = 0;
+               for (size_t i = 0; i < info->topo_queue.nr && visible < n; i++) {
+                       struct commit *c = info->topo_queue.array[i].data;
+                       if (get_commit_action(revs, c) == commit_show)
+                               visible++;
+               }
+               return visible > n-1;
Nit: I think 'return visible >= n' will be more readable here. As in,
more in-line with this function's description (below).
+       if (revs->commits) {
+               struct commit_list *cl;
+               int visible = 0;
+               for (cl = revs->commits; cl && visible < n; cl = cl->next) {
+                       if (get_commit_action(revs, cl->item) == commit_show)
+                               visible++;
+               }
+               return visible > n-1;
Same here.
quoted hunk ↗ jump to hunk
+       }
+
+       return 0;
+}
+
 static void trace2_topo_walk_statistics_atexit(void)
 {
        struct json_writer jw = JSON_WRITER_INIT;
diff --git a/revision.h b/revision.h
index 00c392be37..a10c6b0940 100644
--- a/revision.h
+++ b/revision.h
@@ -572,4 +572,14 @@ int rewrite_parents(struct rev_info *revs,
  */
 struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);

+/*
+ * Peek into revision's next commit without consuming it.
+ */
+struct commit *revision_peek_next_commit(struct rev_info *revs);
+
+/*
+ * Check if there are n more commits to be shown yet.
Shouldn't this be "n or more"?

+int revision_has_commits_after(struct rev_info *revs, int n);
+
 #endif

--
2.54.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help