@matheusbsbs / matheus-bagliano / commits / 7dc0fe3be5
Fork 0

Fix parent rewriting in --early-output

We cannot tell a node that has been checked and found not to be interesting (which does not have the TREECHANGE flag) from a node that hasn't been checked if it is interesting or not, without relying on something else, such as object->parsed. But an object can get the "parsed" flag for other reasons. Which means that "TREECHANGE" has the wrong polarity. This changes the way how the path pruning logic marks an uninteresting commits. From now on, we consider a commit interesting by default, and explicitly mark the ones we decided to prune. The flag is renamed to "TREESAME". Then, this fixes the logic to show the early output with incomplete pruning. It basically says "a commit that has TREESAME set is kind-of-UNINTERESTING", but obviously in a different way than an outright UNINTERESTING commit. Until we parse and examine enough parents to determine if a commit becomes surely "kind-of-UNINTERESTING", we avoid rewriting the ancestry so that later rounds can fix things up. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Linus Torvalds committed Nov 12, 2007 at 23:16 UTC 7dc0fe3be5c949e83e96a1b829be0e72eafffb47
5 files changed +22 -22
builtin-fmt-merge-msg.c
+1 -1
@@ -176,7 +176,7 @@ static void shortlog(const char *name, unsigned char *sha1,
176 struct commit *commit;
177 struct object *branch;
178 struct list subjects = { NULL, NULL, 0, 0 };
179 - int flags = UNINTERESTING | TREECHANGE | SEEN | SHOWN | ADDED;
179 + int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
180
181 branch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);
182 if (!branch || branch->type != OBJ_COMMIT)
builtin-log.c
+1 -1
@@ -89,7 +89,7 @@ static int estimate_commit_count(struct rev_info *rev, struct commit_list *list)
89 struct commit *commit = list->item;
90 unsigned int flags = commit->object.flags;
91 list = list->next;
92 - if ((flags & TREECHANGE) && !(flags & UNINTERESTING))
92 + if (!(flags & (TREESAME | UNINTERESTING)))
93 n++;
94 }
95 return n;
builtin-rev-list.c
+8 -8
@@ -142,7 +142,7 @@ static int count_distance(struct commit_list *entry)
142
143 if (commit->object.flags & (UNINTERESTING | COUNTED))
144 break;
145 - if (commit->object.flags & TREECHANGE)
145 + if (!(commit->object.flags & TREESAME))
146 nr++;
147 commit->object.flags |= COUNTED;
148 p = commit->parents;
@@ -198,7 +198,7 @@ static inline int halfway(struct commit_list *p, int nr)
198 /*
199 * Don't short-cut something we are not going to return!
200 */
201 - if (!(p->item->object.flags & TREECHANGE))
201 + if (p->item->object.flags & TREESAME)
202 return 0;
203 if (DEBUG_BISECT)
204 return 0;
@@ -234,7 +234,7 @@ static void show_list(const char *debug, int counted, int nr,
234 char *ep, *sp;
235
236 fprintf(stderr, "%c%c%c ",
237 - (flags & TREECHANGE) ? 'T' : ' ',
237 + (flags & TREESAME) ? ' ' : 'T',
238 (flags & UNINTERESTING) ? 'U' : ' ',
239 (flags & COUNTED) ? 'C' : ' ');
240 if (commit->util)
@@ -268,7 +268,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr)
268 int distance;
269 unsigned flags = p->item->object.flags;
270
271 - if (!(flags & TREECHANGE))
271 + if (flags & TREESAME)
272 continue;
273 distance = weight(p);
274 if (nr - distance < distance)
@@ -308,7 +308,7 @@ static struct commit_list *best_bisection_sorted(struct commit_list *list, int n
308 int distance;
309 unsigned flags = p->item->object.flags;
310
311 - if (!(flags & TREECHANGE))
311 + if (flags & TREESAME)
312 continue;
313 distance = weight(p);
314 if (nr - distance < distance)
@@ -362,7 +362,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
362 p->item->util = &weights[n++];
363 switch (count_interesting_parents(commit)) {
364 case 0:
365 - if (flags & TREECHANGE) {
365 + if (!(flags & TREESAME)) {
366 weight_set(p, 1);
367 counted++;
368 show_list("bisection 2 count one",
@@ -435,7 +435,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list,
435 * add one for p itself if p is to be counted,
436 * otherwise inherit it from q directly.
437 */
438 - if (flags & TREECHANGE) {
438 + if (!(flags & TREESAME)) {
439 weight_set(p, weight(q)+1);
440 counted++;
441 show_list("bisection 2 count one",
@@ -482,7 +482,7 @@ static struct commit_list *find_bisection(struct commit_list *list,
482 continue;
483 p->next = last;
484 last = p;
485 - if (flags & TREECHANGE)
485 + if (!(flags & TREESAME))
486 nr++;
487 on_list++;
488 }
revision.c
+11 -11
@@ -311,17 +311,15 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
311 /*
312 * If we don't do pruning, everything is interesting
313 */
314 - if (!revs->prune) {
315 - commit->object.flags |= TREECHANGE;
314 + if (!revs->prune)
315 return;
317 - }
316
317 if (!commit->tree)
318 return;
319
320 if (!commit->parents) {
323 - if (!rev_same_tree_as_empty(revs, commit->tree))
324 - commit->object.flags |= TREECHANGE;
321 + if (rev_same_tree_as_empty(revs, commit->tree))
322 + commit->object.flags |= TREESAME;
323 return;
324 }
325
@@ -329,10 +327,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
327 * Normal non-merge commit? If we don't want to make the
328 * history dense, we consider it always to be a change..
329 */
332 - if (!revs->dense && !commit->parents->next) {
333 - commit->object.flags |= TREECHANGE;
330 + if (!revs->dense && !commit->parents->next)
331 return;
335 - }
332
333 pp = &commit->parents;
334 while ((parent = *pp) != NULL) {
@@ -357,6 +353,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
353 }
354 parent->next = NULL;
355 commit->parents = parent;
356 + commit->object.flags |= TREESAME;
357 return;
358
359 case REV_TREE_NEW:
@@ -385,7 +382,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
382 die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1));
383 }
384 if (tree_changed && !tree_same)
388 - commit->object.flags |= TREECHANGE;
385 + return;
386 + commit->object.flags |= TREESAME;
387 }
388
389 static int add_parents_to_list(struct rev_info *revs, struct commit *commit, struct commit_list **list)
@@ -1354,7 +1352,9 @@ static enum rewrite_result rewrite_one(struct rev_info *revs, struct commit **pp
1352 return rewrite_one_error;
1353 if (p->parents && p->parents->next)
1354 return rewrite_one_ok;
1357 - if (p->object.flags & (TREECHANGE | UNINTERESTING))
1355 + if (p->object.flags & UNINTERESTING)
1356 + return rewrite_one_ok;
1357 + if (!(p->object.flags & TREESAME))
1358 return rewrite_one_ok;
1359 if (!p->parents)
1360 return rewrite_one_noparents;
@@ -1427,7 +1427,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
1427 return commit_ignore;
1428 if (revs->prune && revs->dense) {
1429 /* Commit without changes? */
1430 - if (!(commit->object.flags & TREECHANGE)) {
1430 + if (commit->object.flags & TREESAME) {
1431 /* drop merges unless we want parenthood */
1432 if (!revs->parents)
1433 return commit_ignore;
revision.h
+1 -1
@@ -3,7 +3,7 @@
3
4 #define SEEN (1u<<0)
5 #define UNINTERESTING (1u<<1)
6 -#define TREECHANGE (1u<<2)
6 +#define TREESAME (1u<<2)
7 #define SHOWN (1u<<3)
8 #define TMP_MARK (1u<<4) /* for isolated cases; clean after use */
9 #define BOUNDARY (1u<<5)