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

[PATCH 1/5] Introduces for_each_revision() helper

From
LCLuiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
Date
Apr 27, 2007, 17:00 UTC
Message-ID
<1177693212202-git-send-email-lcapitulino@mandriva.com.br>
In-Reply-To
<11776932123749-git-send-email-lcapitulino@mandriva.com.br>
From: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>

This macro may be used to iterate over revisions, so, instead of doing:

	struct commit *commit;
	...
	prepare_revision_walk(rev);
	while ((commit = get_revision(rev)) != NULL) {
	...
 	}
New code should use:
	struct commit *commit;
	...
	for_each_revision(commit, rev) {
	...
	}

The only disadvantage is that it's something magical, and the fact that it returns a struct commit is not obvious.

On the other hand it's documented, has the advantage of making the walking through revisions easier and can save some lines of code.

This version was suggested by Andy Whitcroft.
Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
---
 revision.h |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/revision.h b/revision.h
index cdf94ad..7be3fc7 100644
--- a/revision.h
+++ b/revision.h
@@ -133,4 +133,15 @@ extern void add_object(struct object *obj,
 extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
 extern void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode);
 
+/* helpers */
+
+/**
+ * for_each_revision	- iterate over revisions
+ * @commit:	pointer to a commit object returned for each iteration
+ * @rev:	revision pointer
+ */
+#define for_each_revision(commit, rev) \
+	for (prepare_revision_walk(rev); \
+		  (commit = get_revision(rev)) != NULL; )
+
 #endif
-- 
1.5.1.1.372.g4342
Previous: Luiz Fernando N. CapitulinoNext: Junio C Hamano
Message 2 of 17 in “New for_each_revision() helper”
  1. 0/5 New for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007
  2. 1/5 Introduces for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007
  3. Junio C HamanoApr 27, 2007
  4. Luiz Fernando N. CapitulinoApr 27, 2007
  5. Junio C HamanoApr 29, 2007
  6. Shawn O. PearceApr 29, 2007
  7. Junio C HamanoApr 30, 2007
  8. Johannes SchindelinApr 28, 2007
  9. Alex RiesenApr 28, 2007
  10. Johannes SchindelinApr 28, 2007
  11. Luiz Fernando N. CapitulinoApr 28, 2007
  12. Alex RiesenApr 28, 2007
  13. Luiz Fernando N. CapitulinoApr 29, 2007
  14. 2/5 builtin-fmt-merge-msg.c: Use for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007
  15. 3/5 reachable.c: Use for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007
  16. 4/5 builtin-shortlog.c: Use for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007
  17. 5/5 builtin-log.c: Use for_each_revision() helperLuiz Fernando N. Capitulino, Apr 27, 2007

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.