##// END OF EJS Templates
contrib: add a partial-merge tool for sorted lists (such as Python imports)...
contrib: add a partial-merge tool for sorted lists (such as Python imports) This is a pretty naive tool that uses a regular expression for matching lines. It is based on a Google-internal tool that worked in a similar way. For now, the regular expression is hard-coded to attempt to match single-line Python imports. The only commit I've found in the hg core repo where the tool helped was commit 9cd6292abfdf. I think that's because we often use multiple imports per import statement. I think this tool is still a decent first step (especially once the regex is made configurable in the next patch). The merging should ideally use a proper Python parser and do the merge at the AST (or CST?) level, but that's significantly harder, especially if you want to preserve comments and whitespace. It's also less generic. Differential Revision: https://phab.mercurial-scm.org/D12380

File last commit:

r49730:6000f5b2 default
r49874:681b25ea default
Show More
casesmash.py
40 lines | 895 B | text/x-python | PythonLexer
Pulkit Goyal
casesmash: use absolute_import
r28351 import __builtin__
import os
Augie Fackler
formatting: blacken the codebase...
r43346 from mercurial import util
Matt Mackall
merge with stable
r14730
def lowerwrap(scope, funcname):
f = getattr(scope, funcname)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge with stable
r14730 def wrap(fname, *args, **kwargs):
d, base = os.path.split(fname)
try:
files = os.listdir(d or '.')
Simon Heimberg
cleanup: drop unused variables and an unused import
r19378 except OSError:
Matt Mackall
merge with stable
r14730 files = []
if base in files:
return f(fname, *args, **kwargs)
for fn in files:
if fn.lower() == base.lower():
return f(os.path.join(d, fn), *args, **kwargs)
return f(fname, *args, **kwargs)
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge with stable
r14730 scope.__dict__[funcname] = wrap
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge with stable
r14730 def normcase(path):
return path.lower()
Augie Fackler
formatting: blacken the codebase...
r43346
Matt Mackall
merge with stable
r14730 os.path.normcase = normcase
for f in 'file open'.split():
lowerwrap(__builtin__, f)
for f in "chmod chown open lstat stat remove unlink".split():
lowerwrap(os, f)
for f in "exists lexists".split():
lowerwrap(os.path, f)
lowerwrap(util, 'posixfile')