##// END OF EJS Templates
import-checker: treat "from mercurial import XXXX" style correctly...
import-checker: treat "from mercurial import XXXX" style correctly Before this patch, "import-checker.py" assumes that the name of Mercurial module recognized by "imported_modules" doesn't have package part: for example, "util". This is reason why "import-checker.py" always builds fully qualified module name up relatively, if the given module doesn't belong to standard Python library. But in fact, modules imported in "from mercurial import XXXX" style already have fully qualified name: for example, "mercurial.util" module imported by "mercurial.parsers" is treated as "mercurial.mercurial.util" because of building module name up relatively. This prevents "import-checker.py" from correctly checking about cyclic dependency in them. This patch avoids building module name up relatively, also if module name starts with "mercurial.", to treat modules imported in "from mercurial import XXXX" style correctly.

File last commit:

r12387:4f8067c9 default
r22974:6bd43614 default
Show More
diffhelpers.py
60 lines | 1.5 KiB | text/x-python | PythonLexer
# diffhelpers.py - pure Python implementation of diffhelpers.c
#
# Copyright 2009 Matt Mackall <mpm@selenic.com> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
def addlines(fp, hunk, lena, lenb, a, b):
while True:
todoa = lena - len(a)
todob = lenb - len(b)
num = max(todoa, todob)
if num == 0:
break
for i in xrange(num):
s = fp.readline()
c = s[0]
if s == "\\ No newline at end of file\n":
fix_newline(hunk, a, b)
continue
if c == "\n":
# Some patches may be missing the control char
# on empty lines. Supply a leading space.
s = " \n"
hunk.append(s)
if c == "+":
b.append(s[1:])
elif c == "-":
a.append(s)
else:
b.append(s[1:])
a.append(s)
return 0
def fix_newline(hunk, a, b):
l = hunk[-1]
# tolerate CRLF in last line
if l.endswith('\r\n'):
hline = l[:-2]
else:
hline = l[:-1]
c = hline[0]
if c in " +":
b[-1] = hline[1:]
if c in " -":
a[-1] = hline
hunk[-1] = hline
return 0
def testhunk(a, b, bstart):
alen = len(a)
blen = len(b)
if alen > blen - bstart:
return -1
for i in xrange(alen):
if a[i][1:] != b[i + bstart]:
return -1
return 0