@matheusbsbs / matheus-bagliano / commits / 53b2c823f6
Fork 0

revision walker: mini clean-up

This removes the unnecessary indirection of "revs->prune_fn", since that function is always the same one (or NULL), and there is in fact not even an abstraction reason to make it a function (i.e. its not called from some other file and doesn't allow us to keep the function itself static or anything like that). It then just replaces it with a bit that says "prune or not", and if not pruning, every commit gets TREECHANGE. That in turn means that - if (!revs->prune_fn || (flags & TREECHANGE)) - if (revs->prune_fn && !(flags & TREECHANGE)) just become - if (flags & TREECHANGE) - if (!(flags & TREECHANGE)) respectively. Together with adding the "single_parent()" helper function, the "complex" conditional now becomes if (!(flags & TREECHANGE) && rev->dense && single_parent(commit)) continue; Also indirection of "revs->dense" checking is thrown away the same way, because TREECHANGE bit is set appropriately now. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Nov 5, 2007 at 13:22 UTC 53b2c823f6e862e0c83a4a25bab43e8c32e9c289
5 files changed +35 -26
builtin-log.c
+2 -8
@@ -88,15 +88,9 @@ static int estimate_commit_count(struct rev_info *rev, struct commit_list *list)
88 while (list) {
89 struct commit *commit = list->item;
90 unsigned int flags = commit->object.flags;
91 -
91 list = list->next;
93 - if (flags & UNINTERESTING)
94 - continue;
95 - if (rev->prune_fn && rev->dense && !(flags & TREECHANGE)) {
96 - if (commit->parents && !commit->parents->next)
97 - continue;
98 - }
99 - n++;
92 + if ((flags & TREECHANGE) && !(flags & UNINTERESTING))
93 + n++;
94 }
95 return n;
96 }
builtin-rev-list.c
+7 -7
@@ -142,7 +142,7 @@ static int count_distance(struct commit_list *entry)
142
143 if (commit->object.flags & (UNINTERESTING | COUNTED))
144 break;
145 - if (!revs.prune_fn || (commit->object.flags & TREECHANGE))
145 + if (commit->object.flags & TREECHANGE)
146 nr++;
147 commit->object.flags |= COUNTED;
148 p = commit->parents;
@@ -198,7 +198,7 @@ static inline int halfway(struct commit_list *p, int nr)
198 /*
199 * Don't short-cut something we are not going to return!
200 */
201 - if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
201 + if (!(p->item->object.flags & TREECHANGE))
202 return 0;
203 if (DEBUG_BISECT)
204 return 0;
@@ -268,7 +268,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
268 int distance;
269 unsigned flags = p->item->object.flags;
270
271 - if (revs.prune_fn && !(flags & TREECHANGE))
271 + if (!(flags & TREECHANGE))
272 continue;
273 distance = weight(p);
274 if (nr - distance < distance)
@@ -308,7 +308,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
308 int distance;
309 unsigned flags = p->item->object.flags;
310
311 - if (revs.prune_fn && !(flags & TREECHANGE))
311 + if (!(flags & TREECHANGE))
312 continue;
313 distance = weight(p);
314 if (nr - distance < distance)
@@ -362,7 +362,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
362 p->item->util = &weights[n++];
363 switch (count_interesting_parents(commit)) {
364 case 0:
365 - if (!revs.prune_fn || (flags & TREECHANGE)) {
365 + if (flags & TREECHANGE) {
366 weight_set(p, 1);
367 counted++;
368 show_list("bisection 2 count one",
@@ -435,7 +435,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
435 * add one for p itself if p is to be counted,
436 * otherwise inherit it from q directly.
437 */
438 - if (!revs.prune_fn || (flags & TREECHANGE)) {
438 + if (flags & TREECHANGE) {
439 weight_set(p, weight(q)+1);
440 counted++;
441 show_list("bisection 2 count one",
@@ -482,7 +482,7 @@ static struct commit_list *find_bisection(struct commit_list *list,
482 continue;
483 p->next = last;
484 last = p;
485 - if (!revs.prune_fn || (flags & TREECHANGE))
485 + if (flags & TREECHANGE)
486 nr++;
487 on_list++;
488 }
commit.h
+5
@@ -117,4 +117,9 @@ extern int interactive_add(void);
117 extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
118 extern int rerere(void);
119
120 +static inline int single_parent(struct commit *commit)
121 +{
122 + return commit->parents && !commit->parents->next;
123 +}
124 +
125 #endif /* COMMIT_H */
revision.c
+20 -7
@@ -308,6 +308,14 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
308 struct commit_list **pp, *parent;
309 int tree_changed = 0, tree_same = 0;
310
311 + /*
312 + * If we don't do pruning, everything is interesting
313 + */
314 + if (!revs->prune) {
315 + commit->object.flags |= TREECHANGE;
316 + return;
317 + }
318 +
319 if (!commit->tree)
320 return;
321
@@ -317,6 +325,15 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
325 return;
326 }
327
328 + /*
329 + * Normal non-merge commit? If we don't want to make the
330 + * history dense, we consider it always to be a change..
331 + */
332 + if (!revs->dense && !commit->parents->next) {
333 + commit->object.flags |= TREECHANGE;
334 + return;
335 + }
336 +
337 pp = &commit->parents;
338 while ((parent = *pp) != NULL) {
339 struct commit *p = parent->item;
@@ -415,8 +432,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
432 * simplify the commit history and find the parent
433 * that has no differences in the path set if one exists.
434 */
418 - if (revs->prune_fn)
419 - revs->prune_fn(revs, commit);
435 + try_to_simplify_commit(revs, commit);
436
437 if (revs->no_walk)
438 return 0;
@@ -684,9 +700,6 @@ void init_revisions(struct rev_info *revs, const char *prefix)
700 revs->skip_count = -1;
701 revs->max_count = -1;
702
687 - revs->prune_fn = NULL;
688 - revs->prune_data = NULL;
689 -
703 revs->commit_format = CMIT_FMT_DEFAULT;
704
705 diff_setup(&revs->diffopt);
@@ -1271,7 +1284,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1284 diff_tree_setup_paths(revs->prune_data, &revs->pruning);
1285 /* Can't prune commits with rename following: the paths change.. */
1286 if (!revs->diffopt.follow_renames)
1274 - revs->prune_fn = try_to_simplify_commit;
1287 + revs->prune = 1;
1288 if (!revs->full_diff)
1289 diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
1290 }
@@ -1412,7 +1425,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1425 return commit_ignore;
1426 if (!commit_match(commit, revs))
1427 return commit_ignore;
1415 - if (revs->prune_fn && revs->dense) {
1428 + if (revs->prune && revs->dense) {
1429 /* Commit without changes? */
1430 if (!(commit->object.flags & TREECHANGE)) {
1431 /* drop merges unless we want parenthood */
revision.h
+1 -4
@@ -15,8 +15,6 @@
15 struct rev_info;
16 struct log_info;
17
18 -typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
19 -
18 struct rev_info {
19 /* Starting list */
20 struct commit_list *commits;
@@ -28,12 +26,11 @@ struct rev_info {
26 /* Basic information */
27 const char *prefix;
28 void *prune_data;
31 - prune_fn_t *prune_fn;
32 -
29 unsigned int early_output;
30
31 /* Traversal flags */
32 unsigned int dense:1,
33 + prune:1,
34 no_merges:1,
35 no_walk:1,
36 remove_empty_trees:1,