All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: Luiz Fernando N Capitulino <lcapitulino@mandriva.com.br>
Cc: junkio@cox.net, git@vger.kernel.org
Subject: Re: [PATCH 1/5] Introduces for_each_revision() helper
Date: Thu, 26 Apr 2007 20:59:01 +0100	[thread overview]
Message-ID: <46310485.8070605@shadowen.org> (raw)
In-Reply-To: <11776168001048-git-send-email-lcapitulino@mandriva.com.br>

Luiz Fernando N Capitulino wrote:
> 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.
> 
> 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..bb6f475 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) \
> +	prepare_revision_walk(rev);    \
> +	while ((commit = get_revision(rev)) != NULL)
> +
>  #endif

If this is constructed like that then I would expect the code below to
be miss-compiled:

	if (condition)
		for_each_revision(commit, rev) {
		}

As it would be effectivly be:

	if (condition)
		prepare_revision_walk(rev);
	while ((commit = get_revision(rev)) != NULL) {
	}

I think you'd want this to be something more like:

#define for_each_revision(commit, rev) \
	for (prepare_revision_walk(rev); \
		(commit = get_revision(rev))) != NULL); ) {

-apw

  reply	other threads:[~2007-04-26 19:59 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-26 19:46 [PATCH 0/5] RFC: for_each_revision() helper Luiz Fernando N Capitulino
2007-04-26 19:46 ` [PATCH 1/5] Introduces " Luiz Fernando N Capitulino
2007-04-26 19:59   ` Andy Whitcroft [this message]
2007-04-26 21:12     ` Luiz Fernando N. Capitulino
2007-04-26 19:46 ` [PATCH 2/5] builtin-fmt-merge-msg.c: Use " Luiz Fernando N Capitulino
2007-04-26 19:46 ` [PATCH 3/5] reachable.c: " Luiz Fernando N Capitulino
2007-04-26 19:46 ` [PATCH 4/5] builtin-shortlog.c: " Luiz Fernando N Capitulino
2007-04-26 19:46 ` [PATCH 5/5] builtin-log.c: " Luiz Fernando N Capitulino
2007-04-26 20:57 ` [PATCH 0/5] RFC: " Hermes Trismegisto
2007-04-26 21:05   ` Sam Ravnborg
2007-04-26 21:17     ` Luiz Fernando N. Capitulino
2007-04-26 21:14   ` Luiz Fernando N. Capitulino
2007-04-26 21:21     ` Junio C Hamano
2007-04-27 13:21       ` Luiz Fernando N. Capitulino
2007-04-27 17:13         ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2007-04-27 17:00 [PATCH 0/5] New " Luiz Fernando N. Capitulino
2007-04-27 17:00 ` [PATCH 1/5] Introduces " Luiz Fernando N. Capitulino
2007-04-27 19:32   ` Junio C Hamano
2007-04-27 21:13     ` Luiz Fernando N. Capitulino
2007-04-29  6:59       ` Junio C Hamano
2007-04-29  7:06         ` Shawn O. Pearce
2007-04-30 23:19           ` Junio C Hamano
2007-04-28  2:46   ` Johannes Schindelin
2007-04-28 11:50     ` Alex Riesen
2007-04-28 12:52       ` Johannes Schindelin
2007-04-28 16:02       ` Luiz Fernando N. Capitulino
2007-04-28 16:48         ` Alex Riesen
2007-04-29 13:04           ` Luiz Fernando N. Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=46310485.8070605@shadowen.org \
    --to=apw@shadowen.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=lcapitulino@mandriva.com.br \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.