##// END OF EJS Templates
subrepo: fix a crash when archiving an svn or git subrepo...
subrepo: fix a crash when archiving an svn or git subrepo Only hgsubrepos have a repository attribute. This is pretty hacky, but probably the best we can do on stable. Pushing the lfstatus check down into the wrapper for hgsubrepo (and dropping the check for lfstatus at the top of `hgsubrepoarchive()`) resulted in various test failures because: 1) hgsubrepoarchive isn't returning the number of files archived at the bottom, resulting in an error about += NoneType 2) These copypasta archive wrappers don't use progress bars 3) Largefiles are *not* currently archived when using extdiff (68822b7cdd01), but pushing this context manager down into the subrepo resulted in it apparently doing so (as evidenced by progress bars being dropped) The other uses of `lfstatus()` are not in the substate processing loop, so they shouldn't be an issue. I initially put testcases in this test for largefiles-{on,off}, and it flagged a bunch of exit code differences for `cat` and `diff`, so I backed that off. Differential Revision: https://phab.mercurial-scm.org/D7714

File last commit:

r43347:687b865b default
r44467:7ca8aa88 stable
Show More
bdiff.py
99 lines | 2.4 KiB | text/x-python | PythonLexer
Martin Geisler
pure Python implementation of bdiff.c
r7703 # bdiff.py - Python implementation of bdiff.c
#
# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
#
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Martin Geisler
pure Python implementation of bdiff.c
r7703
Gregory Szorc
bdiff: use absolute_import
r27335 from __future__ import absolute_import
import difflib
import re
import struct
Matt Mackall
pure/bdiff: fix circular import
r7944
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
pure/bdiff: fix circular import
r7944 def splitnewlines(text):
'''like str.splitlines, but only split on newlines.'''
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 lines = [l + b'\n' for l in text.split(b'\n')]
Matt Mackall
pure/bdiff: fix circular import
r7944 if lines:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if lines[-1] == b'\n':
Matt Mackall
pure/bdiff: fix circular import
r7944 lines.pop()
else:
lines[-1] = lines[-1][:-1]
return lines
Martin Geisler
pure Python implementation of bdiff.c
r7703
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
pure Python implementation of bdiff.c
r7703 def _normalizeblocks(a, b, blocks):
prev = None
Dan Villiom Podlaski Christiansen
pure bdiff: don't use a generator...
r14066 r = []
Martin Geisler
pure Python implementation of bdiff.c
r7703 for curr in blocks:
if prev is None:
prev = curr
continue
shift = 0
a1, b1, l1 = prev
a1end = a1 + l1
b1end = b1 + l1
a2, b2, l2 = curr
a2end = a2 + l2
b2end = b2 + l2
if a1end == a2:
Augie Fackler
formatting: blacken the codebase...
r43346 while (
a1end + shift < a2end and a[a1end + shift] == b[b1end + shift]
):
Martin Geisler
pure Python implementation of bdiff.c
r7703 shift += 1
elif b1end == b2:
Augie Fackler
formatting: blacken the codebase...
r43346 while (
b1end + shift < b2end and a[a1end + shift] == b[b1end + shift]
):
Martin Geisler
pure Python implementation of bdiff.c
r7703 shift += 1
Dan Villiom Podlaski Christiansen
pure bdiff: don't use a generator...
r14066 r.append((a1, b1, l1 + shift))
Matt Mackall
many, many trivial check-code fixups
r10282 prev = a2 + shift, b2 + shift, l2 - shift
Dan Villiom Podlaski Christiansen
pure bdiff: don't use a generator...
r14066 r.append(prev)
return r
Martin Geisler
pure Python implementation of bdiff.c
r7703
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
pure Python implementation of bdiff.c
r7703 def bdiff(a, b):
Yuya Nishihara
py3: use bytes() to cast to immutable bytes in pure.bdiff.bdiff()
r31641 a = bytes(a).splitlines(True)
b = bytes(b).splitlines(True)
Martin Geisler
pure Python implementation of bdiff.c
r7703
if not a:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 s = b"".join(b)
return s and (struct.pack(b">lll", 0, 0, len(s)) + s)
Martin Geisler
pure Python implementation of bdiff.c
r7703
bin = []
p = [0]
Alex Gaynor
style: never put multiple statements on one line...
r34436 for i in a:
p.append(p[-1] + len(i))
Martin Geisler
pure Python implementation of bdiff.c
r7703
d = difflib.SequenceMatcher(None, a, b).get_matching_blocks()
d = _normalizeblocks(a, b, d)
la = 0
lb = 0
for am, bm, size in d:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 s = b"".join(b[lb:bm])
Martin Geisler
pure Python implementation of bdiff.c
r7703 if am > la or s:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bin.append(struct.pack(b">lll", p[la], p[am], len(s)) + s)
Martin Geisler
pure Python implementation of bdiff.c
r7703 la = am + size
lb = bm + size
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b"".join(bin)
Martin Geisler
pure Python implementation of bdiff.c
r7703
Augie Fackler
formatting: blacken the codebase...
r43346
Martin Geisler
pure Python implementation of bdiff.c
r7703 def blocks(a, b):
Matt Mackall
pure/bdiff: fix circular import
r7944 an = splitnewlines(a)
bn = splitnewlines(b)
Martin Geisler
pure Python implementation of bdiff.c
r7703 d = difflib.SequenceMatcher(None, an, bn).get_matching_blocks()
d = _normalizeblocks(an, bn, d)
return [(i, i + n, j, j + n) for (i, j, n) in d]
Augie Fackler
formatting: blacken the codebase...
r43346
Patrick Mezard
mdiff: replace wscleanup() regexps with C loops...
r15530 def fixws(text, allws):
if allws:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 text = re.sub(b'[ \t\r]+', b'', text)
Patrick Mezard
mdiff: replace wscleanup() regexps with C loops...
r15530 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 text = re.sub(b'[ \t\r]+', b' ', text)
text = text.replace(b' \n', b'\n')
Patrick Mezard
mdiff: replace wscleanup() regexps with C loops...
r15530 return text