Fully detect uninteresting commits.
With the change in the previous round, we are guaranteed to come up with the list of all relevant merge bases, but sometimes we do not fully mark unintersting ones due to a horizon effect. Add a phase to postprocess, so that we mark all ancestor of "interesting" commit. This also changes the default ordering of shown commits back to chronological order, and adds --topo-order flag to show them in topological order. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 10, 2005 at 15:47 UTC
6b209d473378cc25708ab9839d0edd493afc1e8f
1 file changed
+53
-11
show-branch.c
+53
-11
@@ -199,18 +199,58 @@ static void join_revs(struct commit_list **list_p,
199
parents = parents->next;
200
if ((this_flag & flags) == flags)
201
continue;
202
- parse_commit(p);
202
+ if (!p->object.parsed)
203
+ parse_commit(p);
204
if (mark_seen(p, seen_p) && !still_interesting)
205
extra--;
206
p->object.flags |= flags;
207
insert_by_date(p, list_p);
208
}
209
}
210
+
211
+ /*
212
+ * Postprocess to complete well-poisoning.
213
+ *
214
+ * At this point we have all the commits we have seen in
215
+ * seen_p list (which happens to be sorted chronologically but
216
+ * it does not really matter). Mark anything that can be
217
+ * reached from uninteresting commits not interesting.
218
+ */
219
+ for (;;) {
220
+ int changed = 0;
221
+ struct commit_list *s;
222
+ for (s = *seen_p; s; s = s->next) {
223
+ struct commit *c = s->item;
224
+ struct commit_list *parents;
225
+
226
+ if (((c->object.flags & all_revs) != all_revs) &&
227
+ !(c->object.flags & UNINTERESTING))
228
+ continue;
229
+
230
+ /* The current commit is either a merge base or
231
+ * already uninteresting one. Mark its parents
232
+ * as uninteresting commits _only_ if they are
233
+ * already parsed. No reason to find new ones
234
+ * here.
235
+ */
236
+ parents = c->parents;
237
+ while (parents) {
238
+ struct commit *p = parents->item;
239
+ parents = parents->next;
240
+ if (!(p->object.flags & UNINTERESTING)) {
241
+ p->object.flags |= UNINTERESTING;
242
+ changed = 1;
243
+ }
244
+ }
245
+ }
246
+ if (!changed)
247
+ break;
248
+ }
249
}
250
251
static void show_one_commit(struct commit *commit, int no_name)
252
{
213
- char pretty[128], *cp;
253
+ char pretty[256], *cp;
254
struct commit_name *name = commit->object.util;
255
if (commit->object.parsed)
256
pretty_print_commit(CMIT_FMT_ONELINE, commit->buffer, ~0,
@@ -360,7 +400,7 @@ int main(int ac, char **av)
400
unsigned int rev_mask[MAX_REVS];
401
int num_rev, i, extra = 0;
402
int all_heads = 0, all_tags = 0;
363
- int all_mask, all_revs, shown_merge_point;
403
+ int all_mask, all_revs;
404
char head_path[128];
405
const char *head_path_p;
406
int head_path_len;
@@ -369,6 +409,8 @@ int main(int ac, char **av)
409
int independent = 0;
410
int no_name = 0;
411
int sha1_name = 0;
412
+ int shown_merge_point = 0;
413
+ int topo_order = 0;
414
415
setup_git_directory();
416
@@ -394,6 +436,8 @@ int main(int ac, char **av)
436
merge_base = 1;
437
else if (!strcmp(arg, "--independent"))
438
independent = 1;
439
+ else if (!strcmp(arg, "--topo-order"))
440
+ topo_order = 1;
441
else
442
usage(show_branch_usage);
443
ac--; av++;
@@ -496,7 +540,8 @@ int main(int ac, char **av)
540
exit(0);
541
542
/* Sort topologically */
499
- sort_in_topological_order(&seen);
543
+ if (topo_order)
544
+ sort_in_topological_order(&seen);
545
546
/* Give names to commits */
547
if (!sha1_name && !no_name)
@@ -504,15 +549,12 @@ int main(int ac, char **av)
549
550
all_mask = ((1u << (REV_SHIFT + num_rev)) - 1);
551
all_revs = all_mask & ~((1u << REV_SHIFT) - 1);
507
- shown_merge_point = 0;
552
553
while (seen) {
554
struct commit *commit = pop_one_commit(&seen);
555
int this_flag = commit->object.flags;
512
- int is_merge_point = (this_flag & all_revs) == all_revs;
556
514
- if (is_merge_point)
515
- shown_merge_point = 1;
557
+ shown_merge_point |= ((this_flag & all_revs) == all_revs);
558
559
if (1 < num_rev) {
560
for (i = 0; i < num_rev; i++)
@@ -521,9 +563,9 @@ int main(int ac, char **av)
563
putchar(' ');
564
}
565
show_one_commit(commit, no_name);
524
- if (shown_merge_point && is_merge_point)
525
- if (--extra < 0)
526
- break;
566
+
567
+ if (shown_merge_point && --extra < 0)
568
+ break;
569
}
570
return 0;
571
}