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)
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:
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)