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

combine-diff: update --cc "uninteresting hunks" logic.

Earlier logic was discarding hunks that has difference from only one parent or the same difference from all but one parent. This changes it to check if the differences on all lines are from the same sets of parents. This discards more uninteresting hunks and seems to match expectations more naturally. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 2, 2006 at 00:12 UTC bf1c32bdec8223785c779779d0a660a099f69a63
1 file changed +33 -69
combine-diff.c
+33 -69
@@ -262,58 +262,6 @@ static int interesting(struct sline *sline, unsigned long all_mask)
262 return ((sline->flag & all_mask) != all_mask || sline->lost_head);
263 }
264
265 -static unsigned long line_common_diff(struct sline *sline, unsigned long all_mask)
266 -{
267 - /*
268 - * Look at the line and see from which parents we have the
269 - * same difference.
270 - */
271 -
272 - /* Lower bits of sline->flag records if the parent had this
273 - * line, so XOR with all_mask gives us on-bits for parents we
274 - * have differences with.
275 - */
276 - unsigned long common_adds = (sline->flag ^ all_mask) & all_mask;
277 - unsigned long common_removes = all_mask;
278 -
279 - /* If all the parents have this line, that also counts as
280 - * having the same difference.
281 - */
282 - if (!common_adds)
283 - common_adds = all_mask;
284 -
285 - if (sline->lost_head) {
286 - /* Lost head list records the lines removed from
287 - * the parents, and parent_map records from which
288 - * parent the line was removed.
289 - */
290 - struct lline *ll;
291 - for (ll = sline->lost_head; ll; ll = ll->next) {
292 - common_removes &= ll->parent_map;
293 - }
294 - }
295 - return common_adds & common_removes;
296 -}
297 -
298 -static unsigned long line_all_diff(struct sline *sline, unsigned long all_mask)
299 -{
300 - /*
301 - * Look at the line and see from which parents we have some difference.
302 - */
303 - unsigned long different = (sline->flag ^ all_mask) & all_mask;
304 - if (sline->lost_head) {
305 - /* Lost head list records the lines removed from
306 - * the parents, and parent_map records from which
307 - * parent the line was removed.
308 - */
309 - struct lline *ll;
310 - for (ll = sline->lost_head; ll; ll = ll->next) {
311 - different |= ll->parent_map;
312 - }
313 - }
314 - return different;
315 -}
316 -
265 static unsigned long adjust_hunk_tail(struct sline *sline,
266 unsigned long all_mask,
267 unsigned long hunk_begin,
@@ -417,8 +365,7 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
365 i = 0;
366 while (i < cnt) {
367 unsigned long j, hunk_begin, hunk_end;
420 - int same, diff;
421 - unsigned long same_diff, all_diff;
368 + unsigned long same_diff;
369 while (i < cnt && !(sline[i].flag & mark))
370 i++;
371 if (cnt <= i)
@@ -449,23 +396,40 @@ static int make_hunks(struct sline *sline, unsigned long cnt,
396 }
397 hunk_end = j;
398
452 - /* [i..hunk_end) are interesting. Now does it have
453 - * the same change with all but one parent?
399 + /* [i..hunk_end) are interesting. Now is it really
400 + * interesting?
401 */
455 - same_diff = all_mask;
456 - all_diff = 0;
457 - for (j = i; j < hunk_end; j++) {
458 - same_diff &= line_common_diff(sline + j, all_mask);
459 - all_diff |= line_all_diff(sline + j, all_mask);
460 - }
461 - diff = same = 0;
462 - for (j = 0; j < num_parent; j++) {
463 - if (same_diff & (1UL<<j))
464 - same++;
465 - if (all_diff & (1UL<<j))
466 - diff++;
402 + same_diff = 0;
403 + has_interesting = 0;
404 + for (j = i; j < hunk_end && !has_interesting; j++) {
405 + unsigned long this_diff = ~sline[j].flag & all_mask;
406 + struct lline *ll = sline[j].lost_head;
407 + if (this_diff) {
408 + /* This has some changes. Is it the
409 + * same as others?
410 + */
411 + if (!same_diff)
412 + same_diff = this_diff;
413 + else if (same_diff != this_diff) {
414 + has_interesting = 1;
415 + break;
416 + }
417 + }
418 + while (ll && !has_interesting) {
419 + /* Lost this line from these parents;
420 + * who are they? Are they the same?
421 + */
422 + this_diff = ll->parent_map;
423 + if (!same_diff)
424 + same_diff = this_diff;
425 + else if (same_diff != this_diff) {
426 + has_interesting = 1;
427 + }
428 + ll = ll->next;
429 + }
430 }
468 - if ((num_parent - 1 <= same) || (diff == 1)) {
431 +
432 + if (!has_interesting) {
433 /* This hunk is not that interesting after all */
434 for (j = hunk_begin; j < hunk_end; j++)
435 sline[j].flag &= ~mark;