[MERGE] Patience diff

John Arbash Meinel john at arbash-meinel.com
Fri May 26 03:24:15 BST 2006

Martin Pool wrote:
> On 25 May 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:


>> By the way, in real world cases, I'm starting to think that we shouldn't
>> match single common lines with no unique lines nearby. Because there a
>> lot of times when you have large chunks that change, and it just happens
>> that you have a ''' or if statement that matches in the middle. Which
>> ends up making the diff look worse, because it is trying to synchronize
>> on something it shouldn't.
> Yes, maybe we should.  For humans having a strictly minimal diff
> is suboptimal; showing those common lines as added and deleted within
> larger chunks can be better.  
>> === modified file 'bzrlib/merge3.py'
>> --- bzrlib/merge3.py	
>> +++ bzrlib/merge3.py	
>> @@ -20,8 +20,11 @@
>>  from bzrlib.errors import CantReprocessAndShowBase
>> -from bzrlib.patiencediff import SequenceMatcher
>> +from bzrlib.patiencediff import PatienceSequenceMatcher
>>  from bzrlib.textfile import check_text_lines
>> +
>> +SequenceMatcher = PatienceSequenceMatcher
>> +
>>  def intersect(ra, rb):
>>      """Given two ranges return the range where they intersect or None.
> Point for discussion: when we have a name that's used as a callable
> factory, how should it be named?  One way is to name it like a class, as
> you have here, which makes it clear that you're meant to treat it like a
> constructor.   On the other hand it may be a bit surprising that it
> doesn't generate instances of SequenceMatcher.  It might be better to
> call it, say, sequencematcher_class, or sequencematcher_factory.  (This
> is a bit theoretical; don't let it block your merge but I wondered what
> people thought.)

Well, technically SequenceMatcher is still a class. It just happens to
generate children of the real SequenceMatcher.
I primarily did this, because I didn't want to change it everywhere else
within the code. merge3 isn't really my territory.

If we have a real factory, I probably prefer 'foo_factory', if we have a
member which expects to be a class, I prefer 'foo_class'. So something like:

class Diff(object):
	sequence_matcher_class = SequenceMatcher

	def __init__(self):
		self.sm = Diff.sequence_matcher_class()

Which lets you set the default class to be used.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060525/5f478310/attachment.pgp 

More information about the bazaar mailing list