/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/mdiff.py

  • Committer: Martin Pool
  • Date: 2005-06-28 03:02:31 UTC
  • Revision ID: mbp@sourcefrog.net-20050628030231-d311e4ebcd467ef4
Merge John's import-speedup branch:

                                                                                         
  777 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:32 -0500
      revision-id: john@arbash-meinel.com-20050627032031-e82a50db3863b18e
      bzr selftest was not using the correct bzr

  776 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:20:22 -0500
      revision-id: john@arbash-meinel.com-20050627032021-c9f21fde989ddaee
      Add was using an old mutter

  775 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 22:02:33 -0500
      revision-id: john@arbash-meinel.com-20050627030233-9165cfe98fc63298
      Cleaned up to be less different

  774 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:54:53 -0500
      revision-id: john@arbash-meinel.com-20050627025452-4260d0e744edef43
      Allow BZR_PLUGIN_PATH='' to negate plugin loading.

  773 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:49:34 -0500
      revision-id: john@arbash-meinel.com-20050627024933-b7158f67b7b9eae5
      Finished the previous cleanup (allowing load_plugins to be called twice)

  772 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:45:08 -0500
      revision-id: john@arbash-meinel.com-20050627024508-723b1df510d196fc
      Work on making the tests pass. versioning.py is calling run_cmd directly, but plugins have been loaded.

  771 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:32:29 -0500
      revision-id: john@arbash-meinel.com-20050627023228-79972744d7c53e15
      Got it down a little bit more by removing import of tree and inventory.

  770 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 21:26:05 -0500
      revision-id: john@arbash-meinel.com-20050627022604-350b9773ef622f95
      Reducing the number of import from bzrlib/__init__.py and bzrlib/branch.py

  769 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:32:25 -0500
      revision-id: john@arbash-meinel.com-20050627013225-32dd044f10d23948
      Updated revision.py and xml.py to include SubElement.

  768 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:56 -0500
      revision-id: john@arbash-meinel.com-20050627010356-ee66919e1c377faf
      Minor typo

  767 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 20:03:13 -0500
      revision-id: john@arbash-meinel.com-20050627010312-40d024007eb85051
      Caching the import

  766 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:51:47 -0500
      revision-id: john@arbash-meinel.com-20050627005147-5281c99e48ed1834
      Created wrapper functions for lazy import of ElementTree

  765 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:46:37 -0500
      revision-id: john@arbash-meinel.com-20050627004636-bf432902004a94c5
      Removed all of the test imports of cElementTree

  764 John Arbash Meinel <john@arbash-meinel.com>       Sun 2005-06-26 19:43:59 -0500
      revision-id: john@arbash-meinel.com-20050627004358-d137fbe9570dd71b
      Trying to make bzr startup faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# (C) 2005 Matt Mackall
 
2
# (C) 2005 Canonical Ltd
 
3
 
 
4
# based on code by Matt Mackall, hacked by Martin Pool
 
5
 
 
6
# mm's code works line-by-line; this just works on byte strings.
 
7
# Possibly slower; possibly gives better results for code not
 
8
# regularly separated by newlines and anyhow a bit simpler.
 
9
 
 
10
 
 
11
# This program is free software; you can redistribute it and/or modify
 
12
# it under the terms of the GNU General Public License as published by
 
13
# the Free Software Foundation; either version 2 of the License, or
 
14
# (at your option) any later version.
 
15
 
 
16
# This program is distributed in the hope that it will be useful,
 
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
# GNU General Public License for more details.
 
20
 
 
21
# You should have received a copy of the GNU General Public License
 
22
# along with this program; if not, write to the Free Software
 
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 
 
25
 
 
26
# TODO: maybe work on files not strings?
 
27
 
 
28
 
 
29
import difflib, sys, struct
 
30
from cStringIO import StringIO
 
31
 
 
32
def diff(a, b):
 
33
    d = difflib.SequenceMatcher(None, a, b)
 
34
    
 
35
    ## sys.stderr.write('  ~ real_quick_ratio: %.4f\n' % d.real_quick_ratio())
 
36
    
 
37
    for o, m, n, s, t in d.get_opcodes():
 
38
        if o == 'equal': continue
 
39
        # a[m:n] should be replaced by b[s:t]
 
40
        if s == t:
 
41
            yield m, n, ''
 
42
        else:
 
43
            yield m, n, b[s:t]
 
44
 
 
45
 
 
46
def tobinary(ops):
 
47
    b = StringIO()
 
48
    for f in ops:
 
49
        b.write(struct.pack(">III", f[0], f[1], len(f[2])))
 
50
        b.write(f[2])
 
51
    return b.getvalue()
 
52
 
 
53
 
 
54
def bdiff(a, b):
 
55
    return tobinary(diff(a, b))
 
56
 
 
57
 
 
58
def patch(t, ops):
 
59
    last = 0
 
60
    b = StringIO()
 
61
 
 
62
    for m, n, r in ops:
 
63
        b.write(t[last:m])
 
64
        if r:
 
65
            b.write(r)
 
66
        last = n
 
67
        
 
68
    b.write(t[last:])
 
69
    return b.getvalue()
 
70
 
 
71
 
 
72
def frombinary(b):
 
73
    bin = StringIO(b)
 
74
    while True:
 
75
        p = bin.read(12)
 
76
        if not p:
 
77
            break
 
78
 
 
79
        m, n, l = struct.unpack(">III", p)
 
80
        
 
81
        if l == 0:
 
82
            r = ''
 
83
        else:
 
84
            r = bin.read(l)
 
85
            if len(r) != l:
 
86
                raise Exception("truncated patch data")
 
87
            
 
88
        yield m, n, r
 
89
 
 
90
 
 
91
def bpatch(t, b):
 
92
    return patch(t, frombinary(b))
 
93
 
 
94
 
 
95
 
 
96