@matheusbsbs / matheus-bagliano / commits / c24fe420d3
Fork 0

show-branch: omit uninteresting merges.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 1, 2006 at 17:12 UTC c24fe420d3e2af6e5faabc6ab7f68c18f939582d
1 file changed +30 -3
show-branch.c
+30 -3
@@ -5,7 +5,7 @@
5 #include "refs.h"
6
7 static const char show_branch_usage[] =
8 -"git-show-branch [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]";
8 +"git-show-branch [--dense] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...]";
9
10 static int default_num = 0;
11 static int default_alloc = 0;
@@ -527,6 +527,27 @@ static int git_show_branch_config(const char *var, const char *value)
527 return git_default_config(var, value);
528 }
529
530 +static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
531 +{
532 + /* If the commit is tip of the named branches, do not
533 + * omit it.
534 + * Otherwise, if it is a merge that is reachable from only one
535 + * tip, it is not that interesting.
536 + */
537 + int i, flag, count;
538 + for (i = 0; i < n; i++)
539 + if (rev[i] == commit)
540 + return 0;
541 + flag = commit->object.flags;
542 + for (i = count = 0; i < n; i++) {
543 + if (flag & (1u << (i + REV_SHIFT)))
544 + count++;
545 + }
546 + if (count == 1)
547 + return 1;
548 + return 0;
549 +}
550 +
551 int main(int ac, char **av)
552 {
553 struct commit *rev[MAX_REVS], *commit;
@@ -548,6 +569,7 @@ int main(int ac, char **av)
569 int with_current_branch = 0;
570 int head_at = -1;
571 int topics = 0;
572 + int dense = 1;
573
574 setup_git_directory();
575 git_config(git_show_branch_config);
@@ -590,6 +612,8 @@ int main(int ac, char **av)
612 lifo = 1;
613 else if (!strcmp(arg, "--topics"))
614 topics = 1;
615 + else if (!strcmp(arg, "--sparse"))
616 + dense = 0;
617 else if (!strcmp(arg, "--date-order"))
618 lifo = 0;
619 else
@@ -732,12 +756,15 @@ int main(int ac, char **av)
756 shown_merge_point |= is_merge_point;
757
758 if (1 < num_rev) {
735 - int is_merge = !!(commit->parents && commit->parents->next);
759 + int is_merge = !!(commit->parents &&
760 + commit->parents->next);
761 if (topics &&
762 !is_merge_point &&
763 (this_flag & (1u << REV_SHIFT)))
764 continue;
740 -
765 + if (dense && is_merge &&
766 + omit_in_dense(commit, rev, num_rev))
767 + continue;
768 for (i = 0; i < num_rev; i++) {
769 int mark;
770 if (!(this_flag & (1u << (i + REV_SHIFT))))