Code

revision walker: mini clean-up
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 5 Nov 2007 21:22:34 +0000 (13:22 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Nov 2007 02:19:28 +0000 (18:19 -0800)
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>
builtin-log.c
builtin-rev-list.c
commit.h
revision.c
revision.h

index 981f38872c15606ebee66509dd04b6c4de3de583..d6845bc7f8363ccba67aa436e872962195e3e9b5 100644 (file)
@@ -88,15 +88,9 @@ static int estimate_commit_count(struct rev_info *rev, struct commit_list *list)
        while (list) {
                struct commit *commit = list->item;
                unsigned int flags = commit->object.flags;
-
                list = list->next;
-               if (flags & UNINTERESTING)
-                       continue;
-               if (rev->prune_fn && rev->dense && !(flags & TREECHANGE)) {
-                       if (commit->parents && !commit->parents->next)
-                               continue;
-               }
-               n++;
+               if ((flags & TREECHANGE) && !(flags & UNINTERESTING))
+                       n++;
        }
        return n;
 }
index 697046723fc64f38ab4fb589c84f1c5d5934894a..2dec8873f8a480898c993722ef8d12aec7906d25 100644 (file)
@@ -142,7 +142,7 @@ static int count_distance(struct commit_list *entry)
 
                if (commit->object.flags & (UNINTERESTING | COUNTED))
                        break;
-               if (!revs.prune_fn || (commit->object.flags & TREECHANGE))
+               if (commit->object.flags & TREECHANGE)
                        nr++;
                commit->object.flags |= COUNTED;
                p = commit->parents;
@@ -198,7 +198,7 @@ static inline int halfway(struct commit_list *p, int nr)
        /*
         * Don't short-cut something we are not going to return!
         */
-       if (revs.prune_fn && !(p->item->object.flags & TREECHANGE))
+       if (!(p->item->object.flags & TREECHANGE))
                return 0;
        if (DEBUG_BISECT)
                return 0;
@@ -268,7 +268,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
                int distance;
                unsigned flags = p->item->object.flags;
 
-               if (revs.prune_fn && !(flags & TREECHANGE))
+               if (!(flags & TREECHANGE))
                        continue;
                distance = weight(p);
                if (nr - distance < distance)
@@ -308,7 +308,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
                int distance;
                unsigned flags = p->item->object.flags;
 
-               if (revs.prune_fn && !(flags & TREECHANGE))
+               if (!(flags & TREECHANGE))
                        continue;
                distance = weight(p);
                if (nr - distance < distance)
@@ -362,7 +362,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
                p->item->util = &weights[n++];
                switch (count_interesting_parents(commit)) {
                case 0:
-                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                       if (flags & TREECHANGE) {
                                weight_set(p, 1);
                                counted++;
                                show_list("bisection 2 count one",
@@ -435,7 +435,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
                         * add one for p itself if p is to be counted,
                         * otherwise inherit it from q directly.
                         */
-                       if (!revs.prune_fn || (flags & TREECHANGE)) {
+                       if (flags & TREECHANGE) {
                                weight_set(p, weight(q)+1);
                                counted++;
                                show_list("bisection 2 count one",
@@ -482,7 +482,7 @@ static struct commit_list *find_bisection(struct commit_list *list,
                        continue;
                p->next = last;
                last = p;
-               if (!revs.prune_fn || (flags & TREECHANGE))
+               if (flags & TREECHANGE)
                        nr++;
                on_list++;
        }
index 4ed0c1cf7f5fdf235a2668d60e8250745e723b7d..aa679867a9376496febd5105121b1f49f3ff96a4 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -117,4 +117,9 @@ extern int interactive_add(void);
 extern void add_files_to_cache(int verbose, const char *prefix, const char **files);
 extern int rerere(void);
 
+static inline int single_parent(struct commit *commit)
+{
+       return commit->parents && !commit->parents->next;
+}
+
 #endif /* COMMIT_H */
index 2e6121fa1b92b158d6fdc39e0414bd03acf4a58a..931f978af91786abcdb0ce6b2ae819c9e4e15902 100644 (file)
@@ -308,6 +308,14 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
        struct commit_list **pp, *parent;
        int tree_changed = 0, tree_same = 0;
 
+       /*
+        * If we don't do pruning, everything is interesting
+        */
+       if (!revs->prune) {
+               commit->object.flags |= TREECHANGE;
+               return;
+       }
+
        if (!commit->tree)
                return;
 
@@ -317,6 +325,15 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
                return;
        }
 
+       /*
+        * Normal non-merge commit? If we don't want to make the
+        * history dense, we consider it always to be a change..
+        */
+       if (!revs->dense && !commit->parents->next) {
+               commit->object.flags |= TREECHANGE;
+               return;
+       }
+
        pp = &commit->parents;
        while ((parent = *pp) != NULL) {
                struct commit *p = parent->item;
@@ -415,8 +432,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, str
         * simplify the commit history and find the parent
         * that has no differences in the path set if one exists.
         */
-       if (revs->prune_fn)
-               revs->prune_fn(revs, commit);
+       try_to_simplify_commit(revs, commit);
 
        if (revs->no_walk)
                return 0;
@@ -684,9 +700,6 @@ void init_revisions(struct rev_info *revs, const char *prefix)
        revs->skip_count = -1;
        revs->max_count = -1;
 
-       revs->prune_fn = NULL;
-       revs->prune_data = NULL;
-
        revs->commit_format = CMIT_FMT_DEFAULT;
 
        diff_setup(&revs->diffopt);
@@ -1271,7 +1284,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                diff_tree_setup_paths(revs->prune_data, &revs->pruning);
                /* Can't prune commits with rename following: the paths change.. */
                if (!revs->diffopt.follow_renames)
-                       revs->prune_fn = try_to_simplify_commit;
+                       revs->prune = 1;
                if (!revs->full_diff)
                        diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
        }
@@ -1412,7 +1425,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
                return commit_ignore;
        if (!commit_match(commit, revs))
                return commit_ignore;
-       if (revs->prune_fn && revs->dense) {
+       if (revs->prune && revs->dense) {
                /* Commit without changes? */
                if (!(commit->object.flags & TREECHANGE)) {
                        /* drop merges unless we want parenthood */
index 2232247be4949305ea7b742ca3bdd45cf008d335..a79851449c7b71770fc44481e9ba9b562c6a8b5e 100644 (file)
@@ -15,8 +15,6 @@
 struct rev_info;
 struct log_info;
 
-typedef void (prune_fn_t)(struct rev_info *revs, struct commit *commit);
-
 struct rev_info {
        /* Starting list */
        struct commit_list *commits;
@@ -28,12 +26,11 @@ struct rev_info {
        /* Basic information */
        const char *prefix;
        void *prune_data;
-       prune_fn_t *prune_fn;
-
        unsigned int early_output;
 
        /* Traversal flags */
        unsigned int    dense:1,
+                       prune:1,
                        no_merges:1,
                        no_walk:1,
                        remove_empty_trees:1,