Skip to content

Commit faf0156

Browse files
committed
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 <[email protected]>
1 parent 6534703 commit faf0156

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

revision.c

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,16 +1408,34 @@ static int remove_duplicate_parents(struct commit *commit)
14081408
return surviving_parents;
14091409
}
14101410

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)
14121428
{
14131429
struct commit_list *p;
1430+
struct merge_simplify_state *st, *pst;
14141431
int cnt;
14151432

1433+
st = locate_simplify_state(revs, commit);
1434+
14161435
/*
1417-
* We store which commit each one simplifies to in its util field.
14181436
* Have we handled this one?
14191437
*/
1420-
if (commit->util)
1438+
if (st->simplified)
14211439
return tail;
14221440

14231441
/*
@@ -1426,7 +1444,7 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
14261444
* anyway.
14271445
*/
14281446
if ((commit->object.flags & UNINTERESTING) || !commit->parents) {
1429-
commit->util = commit;
1447+
st->simplified = commit;
14301448
return tail;
14311449
}
14321450

@@ -1435,7 +1453,8 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
14351453
* Otherwise we are not ready to rewrite this one yet.
14361454
*/
14371455
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) {
14391458
tail = &commit_list_insert(p->item, tail)->next;
14401459
cnt++;
14411460
}
@@ -1446,8 +1465,10 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
14461465
/*
14471466
* Rewrite our list of parents.
14481467
*/
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+
}
14511472
cnt = remove_duplicate_parents(commit);
14521473

14531474
/*
@@ -1482,9 +1503,11 @@ static struct commit_list **simplify_one(struct commit *commit, struct commit_li
14821503
(commit->object.flags & UNINTERESTING) ||
14831504
!(commit->object.flags & TREESAME) ||
14841505
(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+
}
14881511
return tail;
14891512
}
14901513

@@ -1508,7 +1531,7 @@ static void simplify_merges(struct rev_info *revs)
15081531
struct commit_list *next = list->next;
15091532
free(list);
15101533
list = next;
1511-
tail = simplify_one(commit, tail);
1534+
tail = simplify_one(revs, commit, tail);
15121535
}
15131536
}
15141537

@@ -1519,9 +1542,11 @@ static void simplify_merges(struct rev_info *revs)
15191542
while (list) {
15201543
struct commit *commit = list->item;
15211544
struct commit_list *next = list->next;
1545+
struct merge_simplify_state *st;
15221546
free(list);
15231547
list = next;
1524-
if (commit->util == commit)
1548+
st = locate_simplify_state(revs, commit);
1549+
if (st->simplified == commit)
15251550
tail = &commit_list_insert(commit, tail)->next;
15261551
}
15271552
}

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct rev_info {
110110

111111
struct reflog_walk_info *reflog_info;
112112
struct decoration children;
113+
struct decoration merge_simplification;
113114
};
114115

115116
#define REV_TREE_SAME 0

0 commit comments

Comments
 (0)