Commits

Brodie Rao  committed beb503c

Removing finished patches

  • Participants
  • Parent commits b9ae995

Comments (0)

Files changed (2)

File offset-regex

-# HG changeset patch
-# Parent 06f8c203bd588517217f855aef0c909812375b8a
-
-diff --git a/cram.py b/cram.py
---- a/cram.py
-+++ b/cram.py
-@@ -79,6 +79,68 @@ def _glob(el, l):
-             res += re.escape(c)
-     return _match(res, l)
- 
-+class SequenceMatcher(difflib.SequenceMatcher, object):
-+    def get_opcodes(self):
-+        if self.opcodes is not None:
-+            return self.opcodes
-+        super(SequenceMatcher, self).get_opcodes()
-+        handled = []
-+        for tag, i1, i2, j1, j2 in self.opcodes:
-+            if tag == 'replace':
-+                group = (self.a[i1:i2], self.b[j1:j2])
-+                matched = False
-+                nr = 0
-+                for n, (el, line) in enumerate(itertools.izip(*group)):
-+                    if ((el.endswith(' (re)\n') and
-+                         _match(el[:-6] + '\n', line))
-+                        or
-+                        (el.endswith(' (glob)\n') and
-+                         _glob(el[:-8] + '\n', line))):
-+                        matched = True
-+                        if nr != 0:
-+                            handled.append((tag, i1 + nr, i1 + n - 1, j1 + nr,
-+                                            j1 + n - 1))
-+                        handled.append(('equal', i1 + n, i1 + n + 1, j1 + n,
-+                                        j1 + n + 1))
-+                    else:
-+                        nr = n
-+                if matched and n != 0 and nr == n:
-+                    handled.append((tag, i1 + n, i1 + n + 1, j1 + n,
-+                                    j1 + n + 1))
-+                if not matched:
-+                    handled.append((tag, i1, i2, j1, j2))
-+            else:
-+                handled.append((tag, i1, i2, j1, j2))
-+        if not [True for o in handled if o[0] != 'equal']:
-+            handled = []
-+        self.opcodes = handled
-+        return handled
-+
-+def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
-+                 tofiledate='', n=3, lineterm='\n'):
-+    started = False
-+    for group in SequenceMatcher(None, a, b).get_grouped_opcodes(n):
-+        if not started:
-+            fromdate = '\t%s' % fromfiledate if fromfiledate else ''
-+            todate = '\t%s' % tofiledate if tofiledate else ''
-+            yield '--- %s%s%s' % (fromfile, fromdate, lineterm)
-+            yield '+++ %s%s%s' % (tofile, todate, lineterm)
-+            started = True
-+        i1, i2, j1, j2 = group[0][1], group[-1][2], group[0][3], group[-1][4]
-+        yield "@@ -%d,%d +%d,%d @@%s" % (i1 + 1, i2 - i1, j1 + 1, j2 - j1,
-+                                         lineterm)
-+        for tag, i1, i2, j1, j2 in group:
-+            if tag == 'equal':
-+                for line in a[i1:i2]:
-+                    yield ' ' + line
-+                continue
-+            if tag == 'replace' or tag == 'delete':
-+                for line in a[i1:i2]:
-+                    yield '-' + line
-+            if tag == 'replace' or tag == 'insert':
-+                for line in b[j1:j2]:
-+                    yield '+' + line
-+
- def test(path):
-     """Run test at path and return input, output, and diff.
- 
-@@ -135,16 +197,18 @@ def test(path):
- 
-             if el == line:
-                 postout.append('  ' + el)
--            elif (el and
--                  (el.endswith(" (re)\n") and _match(el[:-6] + '\n', line) or
--                   el.endswith(" (glob)\n") and _glob(el[:-8] + '\n', line))):
--                postout.append('  ' + el)
-+            # FIXME: We should be able to move this into the differ completely,
-+            #        but right now it completely blows up when commented out.
-+            #elif (el and
-+            #      (el.endswith(" (re)\n") and _match(el[:-6] + '\n', line) or
-+            #       el.endswith(" (glob)\n") and _glob(el[:-8] + '\n', line))):
-+            #    postout.append('  ' + el)
-             else:
-                 postout.append('  ' + line)
-     postout += after.pop(pos, [])
- 
-     dpath = os.path.abspath(path)
--    diff = difflib.unified_diff(refout, postout, dpath, dpath + '.err')
-+    diff = unified_diff(refout, postout, dpath, dpath + '.err')
-     for firstline in diff:
-         return refout, postout, itertools.chain([firstline], diff)
-     return refout, postout, []
-offset-regex #+offset-regex
 jobs