simplify-merges: never remove all TREESAME parents
When simplifying an odd merge, such as one that used "-s ours", we may find ourselves TREESAME to apparently redundant parents. Prevent simplify_merges() from removing every TREESAME parent; if this would happen reinstate the first TREESAME parent - the one that the default log would have followed. This avoids producing a totally disjoint history from the default log when the default log is a better explanation of the end result, and aids visualisation of odd merges. Signed-off-by: Kevin Bracey <kevin@bracey.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kevin Bracey committed
May 16, 2013 at 18:32 UTC
9c129eab99f16d7bb174b35573e68ae6a5d02efe
3 files changed
+73
-3
Documentation/rev-list-options.txt
+2
-1
@@ -471,7 +471,8 @@ history according to the following rules:
471
+
472
* Replace each parent `P` of `C'` with its simplification `P'`. In
473
the process, drop parents that are ancestors of other parents, and
474
- remove duplicates.
474
+ remove duplicates, but take care to never drop all parents that
475
+ we are TREESAME to.
476
+
477
* If after this parent rewriting, `C'` is a root or merge commit (has
478
zero or >1 parents), a boundary commit, or !TREESAME, it remains.
revision.c
+69
@@ -2136,6 +2136,73 @@ static int mark_redundant_parents(struct rev_info *revs, struct commit *commit)
2136
return marked;
2137
}
2138
2139
+/*
2140
+ * Awkward naming - this means one parent we are TREESAME to.
2141
+ * cf mark_treesame_root_parents: root parents that are TREESAME (to an
2142
+ * empty tree). Better name suggestions?
2143
+ */
2144
+static int leave_one_treesame_to_parent(struct rev_info *revs, struct commit *commit)
2145
+{
2146
+ struct treesame_state *ts = lookup_decoration(&revs->treesame, &commit->object);
2147
+ struct commit *unmarked = NULL, *marked = NULL;
2148
+ struct commit_list *p;
2149
+ unsigned n;
2150
+
2151
+ for (p = commit->parents, n = 0; p; p = p->next, n++) {
2152
+ if (ts->treesame[n]) {
2153
+ if (p->item->object.flags & TMP_MARK) {
2154
+ if (!marked)
2155
+ marked = p->item;
2156
+ } else {
2157
+ if (!unmarked) {
2158
+ unmarked = p->item;
2159
+ break;
2160
+ }
2161
+ }
2162
+ }
2163
+ }
2164
+
2165
+ /*
2166
+ * If we are TREESAME to a marked-for-deletion parent, but not to any
2167
+ * unmarked parents, unmark the first TREESAME parent. This is the
2168
+ * parent that the default simplify_history==1 scan would have followed,
2169
+ * and it doesn't make sense to omit that path when asking for a
2170
+ * simplified full history. Retaining it improves the chances of
2171
+ * understanding odd missed merges that took an old version of a file.
2172
+ *
2173
+ * Example:
2174
+ *
2175
+ * I--------*X A modified the file, but mainline merge X used
2176
+ * \ / "-s ours", so took the version from I. X is
2177
+ * `-*A--' TREESAME to I and !TREESAME to A.
2178
+ *
2179
+ * Default log from X would produce "I". Without this check,
2180
+ * --full-history --simplify-merges would produce "I-A-X", showing
2181
+ * the merge commit X and that it changed A, but not making clear that
2182
+ * it had just taken the I version. With this check, the topology above
2183
+ * is retained.
2184
+ *
2185
+ * Note that it is possible that the simplification chooses a different
2186
+ * TREESAME parent from the default, in which case this test doesn't
2187
+ * activate, and we _do_ drop the default parent. Example:
2188
+ *
2189
+ * I------X A modified the file, but it was reverted in B,
2190
+ * \ / meaning mainline merge X is TREESAME to both
2191
+ * *A-*B parents.
2192
+ *
2193
+ * Default log would produce "I" by following the first parent;
2194
+ * --full-history --simplify-merges will produce "I-A-B". But this is a
2195
+ * reasonable result - it presents a logical full history leading from
2196
+ * I to X, and X is not an important merge.
2197
+ */
2198
+ if (!unmarked && marked) {
2199
+ marked->object.flags &= ~TMP_MARK;
2200
+ return 1;
2201
+ }
2202
+
2203
+ return 0;
2204
+}
2205
+
2206
static int remove_marked_parents(struct rev_info *revs, struct commit *commit)
2207
{
2208
struct commit_list **pp, *p;
@@ -2238,6 +2305,8 @@ static struct commit_list **simplify_one(struct rev_info *revs, struct commit *c
2305
*/
2306
if (1 < cnt) {
2307
int marked = mark_redundant_parents(revs, commit);
2308
+ if (marked)
2309
+ marked -= leave_one_treesame_to_parent(revs, commit);
2310
if (marked)
2311
cnt = remove_marked_parents(revs, commit);
2312
}
t/t6111-rev-list-treesame.sh
+2
-2
@@ -116,7 +116,7 @@ check_result 'M L H B A' -- file
116
check_result '(LH)M (B)L (B)H (A)B A' --parents -- file
117
check_result 'M L J I H G F D B A' --full-history -- file
118
check_result '(LH)M (K)L (GJ)K (I)J (G)I (G)H (FB)G (D)F (BA)D (A)B A' --full-history --parents -- file
119
-check_outcome failure '(LH)M (G)H (J)L (I)J (G)I (FB)G (B)F (A)B A' --simplify-merges -- file # drops parent B from G
119
+check_result '(LH)M (G)H (J)L (I)J (G)I (FB)G (B)F (A)B A' --simplify-merges -- file
120
check_result 'M L K G F D B A' --first-parent
121
check_result 'M L G F B A' --first-parent -- file
122
@@ -127,7 +127,7 @@ check_result 'M L H' F..M -- file
127
check_result '(LH)M (B)L (B)H' --parents F..M -- file
128
check_result 'M L J I H G' F..M --full-history -- file
129
check_result '(LH)M (K)L (GJ)K (I)J (G)I (G)H (FB)G' F..M --full-history --parents -- file
130
-check_outcome failure '(LH)M (G)H (J)L (I)J (G)I (FB)G' F..M --simplify-merges -- file # drops parent B from G
130
+check_result '(LH)M (G)H (J)L (I)J (G)I (FB)G' F..M --simplify-merges -- file
131
check_result 'M L K J I H G' F..M --ancestry-path
132
check_result 'M L J I H G' F..M --ancestry-path -- file
133
check_result '(LH)M (K)L (GJ)K (I)J (G)I (G)H (FE)G' F..M --ancestry-path --parents -- file