hgext/__init__.py
author |
Matt Mackall <mpm@selenic.com> |
|
Thu, 21 Apr 2016 21:05:26 -0500 |
branch | stable |
changeset 29013 |
9a8363d23419 |
parent 28450 |
155e3308289c
|
child 43076 |
2372284d9457 |
permissions |
-rw-r--r-- |
bdiff: deal better with duplicate lines
The longest_match code compares all the possible positions in two
files to find the best match. Given a pair of sequences, it
effectively searches a grid like this:
a b b b c . d e . f
0 1 2 3 4 5 6 7 8 9
a 1 - - - - - - - - -
b - 2 1 1 - - - - - -
b - 1 3 2 - - - - - -
b - 1 2 4 - - - - - -
. - - - - - 1 - - 1 -
Here, the 4 in the middle says "the first four lines of the
file match", which it can compute be comparing the fourth lines and
then adding one to the result found when comparing the third lines in
the entry to the upper left.
We generally avoid the quadratic worst case by only looking at lines
that match, which is precomputed. We also avoid quadratic storage by
only keeping a single column vector and then keeping track of the best
match.
Unfortunately, this can get us into trouble with the sequences above.
Because we want to reuse the '3' value when calculating the '4', we
need to be careful not to overwrite it with the '2' we calculate
immediately before. If we scan left to right, top to bottom, we're
going to have a problem: we'll overwrite our 3 before we use it and
calculate a suboptimal best match.
To address this, we can either keep two column vectors and swap
between them (which significantly complicates bookkeeping), or change
our scanning order. If we instead scan from left to right, bottom to
top, we'll avoid ever overwriting values we'll need in the future.
This unfortunately needs several changes to be made simultaneously:
- change the order we build the initial hash chains for the b sequence
- change the sentinel values from INT_MAX to -1
- change the visit order in the longest_match inner loop
- add a tie-breaker preference for earlier matches
This last is needed because we previously had an implicit tie-breaker
from our visitation order that our test suite relies on. Later matches
can also trigger a bug in the normalization code in diff().
28450
155e3308289c
hgext: officially turn 'hgext' into a namespace package
Pierre-Yves David <pierre-yves.david@fb.com>
diff
changeset
|
1 |
from __future__ import absolute_import
|
155e3308289c
hgext: officially turn 'hgext' into a namespace package
Pierre-Yves David <pierre-yves.david@fb.com>
diff
changeset
|
2 |
import pkgutil
|
155e3308289c
hgext: officially turn 'hgext' into a namespace package
Pierre-Yves David <pierre-yves.david@fb.com>
diff
changeset
|
3 |
__path__ = pkgutil.extend_path(__path__, __name__)
|