From: Luiz Fernando N Capitulino <hidden> Date: 2016-06-15 22:43:07
Hi,
[This' also a git-send-email test, so, if this fail by showing just
the first e-mail in the series, do not blame me :)]
This series introduces a helper macro to help programs to walk through
revisions (details on the first patch).
Shawn has already alerted me that some people don't like to
'hide C constructs', but I think that in this case it's useful, as explained
in the next e-mail.
The complete diff stat is:
builtin-fmt-merge-msg.c | 3 +--
builtin-log.c | 12 ++++--------
builtin-shortlog.c | 3 +--
reachable.c | 3 +--
revision.h | 11 +++++++++++
5 files changed, 18 insertions(+), 14 deletions(-)
But if we subtract the for_each_revision() macro's code we get:
4 files changed, 7 insertions(+), 14 deletions(-)
From: Luiz Fernando N Capitulino <hidden> Date: 2016-06-15 22:43:07
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 <redacted>
---
revision.h | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
@@ -79,7 +79,7 @@ static void walk_commit_list(struct rev_info *revs)structobject_arrayobjects={0,0,NULL};/* Walk all commits, process their trees */-while((commit=get_revision(revs))!=NULL)+for_each_revision(commit,revs)process_tree(commit->tree,&objects,NULL,"");/* Then walk all the pending objects, recursively processing them too */
@@ -195,6 +195,5 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog)*Setuptherevisionwalk-thiswillmoveallcommits*fromthependinglisttothecommitwalkinglist.*/-prepare_revision_walk(revs);walk_commit_list(revs);}
From: Andy Whitcroft <hidden> Date: 2016-06-15 22:43:07
Luiz Fernando N Capitulino wrote:
quoted hunk
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 <redacted>
---
revision.h | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
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
From: Luiz Fernando N. Capitulino <hidden> Date: 2016-06-15 22:43:07
Em Thu, 26 Apr 2007 20:59:01 +0100
Andy Whitcroft [off-list ref] escreveu:
| 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); ) {
I'm *so* clueless that this mistake does not surprise me.
Will fix, thanks for the review Andy.
--
Luiz Fernando N. Capitulino