@matheusbsbs / matheus-bagliano / commits / 252a7c0235
Fork 0

Enhance --early-output format

This makes --early-output a bit more advanced, and actually makes it generate multiple "Final output:" headers as it updates things asynchronously. I realize that the "Final output:" line is now illogical, since it's not really final until it also says "done", but It now _always_ generates a "Final output:" header in front of any commit list, and that output header gives you a *guess* at the maximum number of commits available. However, it should be noted that the guess can be completely off: I do a reasonable job estimating it, but it is not meant to be exact. So what happens is that you may get output like this: - at 0.1 seconds: Final output: 2 incomplete .. 2 commits listed .. - half a second later: Final output: 33 incomplete .. 33 commits listed .. - another half a second after that: Final output: 71 incomplete .. 71 commits listed .. - another half second later: Final output: 136 incomplete .. 100 commits listed: we hit the --early-output limit, and .. will only output 100 commits, and after this you'll not .. see an "incomplete" report any more since you got as much .. early output as you asked for! - .. and then finally: Final output: 73106 done .. all the commits .. The above is a real-life scenario on my current kernel tree after having flushed all the caches. Tested with the experimental gitk patch that Paul sent out, and by looking at the actual log output (and verifying that my commit count guesses actually match real life fairly well). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Nov 4, 2007 at 12:12 UTC 252a7c02354a3e2825cfde3c5053a04acc07be9c
3 files changed +119 -40
builtin-log.c
+75 -13
@@ -77,17 +77,85 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
77 }
78 }
79
80 +/*
81 + * This gives a rough estimate for how many commits we
82 + * will print out in the list.
83 + */
84 +static int estimate_commit_count(struct rev_info *rev, struct commit_list *list)
85 +{
86 + int n = 0;
87 +
88 + while (list) {
89 + struct commit *commit = list->item;
90 + unsigned int flags = commit->object.flags;
91 +
92 + 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++;
100 + }
101 + return n;
102 +}
103 +
104 +static void show_early_header(struct rev_info *rev, const char *stage, int nr)
105 +{
106 + if (rev->shown_one) {
107 + rev->shown_one = 0;
108 + if (rev->commit_format != CMIT_FMT_ONELINE)
109 + putchar(rev->diffopt.line_termination);
110 + }
111 + printf("Final output: %d %s\n", nr, stage);
112 +}
113 +
114 +struct itimerval early_output_timer;
115 +
116 static void log_show_early(struct rev_info *revs, struct commit_list *list)
117 {
118 int i = revs->early_output;
119 + int show_header = 1;
120
121 sort_in_topological_order(&list, revs->lifo);
122 while (list && i) {
123 struct commit *commit = list->item;
87 - log_tree_commit(revs, commit);
124 + switch (simplify_commit(revs, commit)) {
125 + case commit_show:
126 + if (show_header) {
127 + int n = estimate_commit_count(revs, list);
128 + show_early_header(revs, "incomplete", n);
129 + show_header = 0;
130 + }
131 + log_tree_commit(revs, commit);
132 + i--;
133 + break;
134 + case commit_ignore:
135 + break;
136 + case commit_error:
137 + return;
138 + }
139 list = list->next;
89 - i--;
140 }
141 +
142 + /* Did we already get enough commits for the early output? */
143 + if (!i)
144 + return;
145 +
146 + /*
147 + * ..if no, then repeat it twice a second until we
148 + * do.
149 + *
150 + * NOTE! We don't use "it_interval", because if the
151 + * reader isn't listening, we want our output to be
152 + * throttled by the writing, and not have the timer
153 + * trigger every second even if we're blocked on a
154 + * reader!
155 + */
156 + early_output_timer.it_value.tv_sec = 0;
157 + early_output_timer.it_value.tv_usec = 500000;
158 + setitimer(ITIMER_REAL, &early_output_timer, NULL);
159 }
160
161 static void early_output(int signal)
@@ -98,7 +166,6 @@ static void early_output(int signal)
166 static void setup_early_output(struct rev_info *rev)
167 {
168 struct sigaction sa;
101 - struct itimerval v;
169
170 /*
171 * Set up the signal handler, minimally intrusively:
@@ -120,21 +187,16 @@ static void setup_early_output(struct rev_info *rev)
187 *
188 * This is a one-time-only trigger.
189 */
123 - memset(&v, 0, sizeof(v));
124 - v.it_value.tv_sec = 0;
125 - v.it_value.tv_usec = 100000;
126 - setitimer(ITIMER_REAL, &v, NULL);
190 + early_output_timer.it_value.tv_sec = 0;
191 + early_output_timer.it_value.tv_usec = 100000;
192 + setitimer(ITIMER_REAL, &early_output_timer, NULL);
193 }
194
195 static void finish_early_output(struct rev_info *rev)
196 {
197 + int n = estimate_commit_count(rev, rev->commits);
198 signal(SIGALRM, SIG_IGN);
132 - if (rev->shown_one) {
133 - rev->shown_one = 0;
134 - if (rev->commit_format != CMIT_FMT_ONELINE)
135 - putchar(rev->diffopt.line_termination);
136 - }
137 - printf("Final output:\n");
199 + show_early_header(rev, "done", n);
200 }
201
202 static int cmd_log_walk(struct rev_info *rev)
revision.c
+36 -27
@@ -1398,6 +1398,36 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
1398 commit->buffer, strlen(commit->buffer));
1399 }
1400
1401 +enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1402 +{
1403 + if (commit->object.flags & SHOWN)
1404 + return commit_ignore;
1405 + if (revs->unpacked && has_sha1_pack(commit->object.sha1, revs->ignore_packed))
1406 + return commit_ignore;
1407 + if (commit->object.flags & UNINTERESTING)
1408 + return commit_ignore;
1409 + if (revs->min_age != -1 && (commit->date > revs->min_age))
1410 + return commit_ignore;
1411 + if (revs->no_merges && commit->parents && commit->parents->next)
1412 + return commit_ignore;
1413 + if (!commit_match(commit, revs))
1414 + return commit_ignore;
1415 + if (revs->prune_fn && revs->dense) {
1416 + /* Commit without changes? */
1417 + if (!(commit->object.flags & TREECHANGE)) {
1418 + /* drop merges unless we want parenthood */
1419 + if (!revs->parents)
1420 + return commit_ignore;
1421 + /* non-merge - always ignore it */
1422 + if (!commit->parents || !commit->parents->next)
1423 + return commit_ignore;
1424 + }
1425 + if (revs->parents && rewrite_parents(revs, commit) < 0)
1426 + return commit_error;
1427 + }
1428 + return commit_show;
1429 +}
1430 +
1431 static struct commit *get_revision_1(struct rev_info *revs)
1432 {
1433 if (!revs->commits)
@@ -1425,36 +1455,15 @@ static struct commit *get_revision_1(struct rev_info *revs)
1455 if (add_parents_to_list(revs, commit, &revs->commits) < 0)
1456 return NULL;
1457 }
1428 - if (commit->object.flags & SHOWN)
1429 - continue;
1430 -
1431 - if (revs->unpacked && has_sha1_pack(commit->object.sha1,
1432 - revs->ignore_packed))
1433 - continue;
1458
1435 - if (commit->object.flags & UNINTERESTING)
1436 - continue;
1437 - if (revs->min_age != -1 && (commit->date > revs->min_age))
1438 - continue;
1439 - if (revs->no_merges &&
1440 - commit->parents && commit->parents->next)
1441 - continue;
1442 - if (!commit_match(commit, revs))
1459 + switch (simplify_commit(revs, commit)) {
1460 + case commit_ignore:
1461 continue;
1444 - if (revs->prune_fn && revs->dense) {
1445 - /* Commit without changes? */
1446 - if (!(commit->object.flags & TREECHANGE)) {
1447 - /* drop merges unless we want parenthood */
1448 - if (!revs->parents)
1449 - continue;
1450 - /* non-merge - always ignore it */
1451 - if (!commit->parents || !commit->parents->next)
1452 - continue;
1453 - }
1454 - if (revs->parents && rewrite_parents(revs, commit) < 0)
1455 - return NULL;
1462 + case commit_error:
1463 + return NULL;
1464 + default:
1465 + return commit;
1466 }
1457 - return commit;
1467 } while (revs->commits);
1468 return NULL;
1469 }
revision.h
+8
@@ -133,4 +133,12 @@ extern void add_object(struct object *obj,
133
134 extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name);
135
136 +enum commit_action {
137 + commit_ignore,
138 + commit_show,
139 + commit_error
140 +};
141 +
142 +extern enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit);
143 +
144 #endif