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

revision --simplify-merges: use decoration instead of commit->util field

The users of revision walking machinery may want to use the util pointer for their own use. Use decoration to hold the data needed during merge simplification instead. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 14, 2008 at 10:59 UTC faf0156b278d1a760362cda1d294a88be7608de4
2 files changed +38 -12
revision.c
+37 -12
@@ -1408,16 +1408,34 @@ static int remove_duplicate_parents(struct commit *commit)
1408 return surviving_parents;
1409 }
1410
1411 -static struct commit_list **simplify_one(struct commit *commit, struct commit_list **tail)
1411 +struct merge_simplify_state {
1412 + struct commit *simplified;
1413 +};
1414 +
1415 +static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs, struct commit *commit)
1416 +{
1417 + struct merge_simplify_state *st;
1418 +
1419 + st = lookup_decoration(&revs->merge_simplification, &commit->object);
1420 + if (!st) {
1421 + st = xcalloc(1, sizeof(*st));
1422 + add_decoration(&revs->merge_simplification, &commit->object, st);
1423 + }
1424 + return st;
1425 +}
1426 +
1427 +static struct commit_list **simplify_one(struct rev_info *revs, struct commit *commit, struct commit_list **tail)
1428 {
1429 struct commit_list *p;
1430 + struct merge_simplify_state *st, *pst;
1431 int cnt;
1432
1433 + st = locate_simplify_state(revs, commit);
1434 +
1435 /*
1417 - * We store which commit each one simplifies to in its util field.
1436 * Have we handled this one?
1437 */
1420 - if (commit->util)
1438 + if (st->simplified)
1439 return tail;
1440
1441 /*
@@ -1426,7 +1444,7 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
1444 * anyway.
1445 */
1446 if ((commit->object.flags & UNINTERESTING) || !commit->parents) {
1429 - commit->util = commit;
1447 + st->simplified = commit;
1448 return tail;
1449 }
1450
@@ -1435,7 +1453,8 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
1453 * Otherwise we are not ready to rewrite this one yet.
1454 */
1455 for (cnt = 0, p = commit->parents; p; p = p->next) {
1438 - if (!p->item->util) {
1456 + pst = locate_simplify_state(revs, p->item);
1457 + if (!pst->simplified) {
1458 tail = &commit_list_insert(p->item, tail)->next;
1459 cnt++;
1460 }
@@ -1446,8 +1465,10 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
1465 /*
1466 * Rewrite our list of parents.
1467 */
1449 - for (p = commit->parents; p; p = p->next)
1450 - p->item = p->item->util;
1468 + for (p = commit->parents; p; p = p->next) {
1469 + pst = locate_simplify_state(revs, p->item);
1470 + p->item = pst->simplified;
1471 + }
1472 cnt = remove_duplicate_parents(commit);
1473
1474 /*
@@ -1482,9 +1503,11 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
1503 (commit->object.flags & UNINTERESTING) ||
1504 !(commit->object.flags & TREESAME) ||
1505 (1 < cnt))
1485 - commit->util = commit;
1486 - else
1487 - commit->util = commit->parents->item->util;
1506 + st->simplified = commit;
1507 + else {
1508 + pst = locate_simplify_state(revs, commit->parents->item);
1509 + st->simplified = pst->simplified;
1510 + }
1511 return tail;
1512 }
1513
@@ -1508,7 +1531,7 @@ static void simplify_merges(struct rev_info *revs)
1531 struct commit_list *next = list->next;
1532 free(list);
1533 list = next;
1511 - tail = simplify_one(commit, tail);
1534 + tail = simplify_one(revs, commit, tail);
1535 }
1536 }
1537
@@ -1519,9 +1542,11 @@ static void simplify_merges(struct rev_info *revs)
1542 while (list) {
1543 struct commit *commit = list->item;
1544 struct commit_list *next = list->next;
1545 + struct merge_simplify_state *st;
1546 free(list);
1547 list = next;
1524 - if (commit->util == commit)
1548 + st = locate_simplify_state(revs, commit);
1549 + if (st->simplified == commit)
1550 tail = &commit_list_insert(commit, tail)->next;
1551 }
1552 }
revision.h
+1
@@ -110,6 +110,7 @@ struct rev_info {
110
111 struct reflog_walk_info *reflog_info;
112 struct decoration children;
113 + struct decoration merge_simplification;
114 };
115
116 #define REV_TREE_SAME 0