mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 08:18:15 +03:00
0daed9e7f6
Summary: Solves issues below: ``` hgext/backups.py:18:1: F811 redefinition of unused 'registrar' from line 17 hgext/catnotate.py:1:1: F811 redefinition of unused 'util' from line 1 hgext/remotenames.py:57:5: F811 redefinition of unused 'registrar' from line 34 hgsubversion/setup.py:103:5: F401 'mercurial' imported but unused hgsubversion/setup.py:109:5: F401 'hgsubversion.svnwrap.svn_swig_wrapper' imported but unused i18n/polib.py:1281:29: F841 local variable 'exc' is assigned to but never used (Python 2) i18n/polib.py:1427:13: F841 local variable 'typ' is assigned to but never used i18n/polib.py:28:1: F401 'sys' imported but unused mercurial/manifest.py:411:5: F811 redefinition of unused '_lazymanifest' from line 168 mercurial/posix.py:419:5: F811 redefinition of unused 'normcasefallback' from line 362 mercurial/posix.py:425:5: F811 redefinition of unused 'checkexec' from line 167 mercurial/posix.py:431:5: F811 redefinition of unused 'checklink' from line 234 mercurial/pycompat.py:29:5: F401 'http.cookiejar as cookielib' imported but unused mercurial/pycompat.py:30:5: F401 'http.client as httplib' imported but unused mercurial/pycompat.py:31:5: F401 'pickle' imported but unused mercurial/pycompat.py:33:5: F401 'socketserver' imported but unused mercurial/pycompat.py:34:5: F401 'xmlrpc.client as xmlrpclib' imported but unused mercurial/statprof.py:573:36: F812 list comprehension redefines 'parent' from line 562 (Python 2) mercurial/util.py:1076:5: F811 redefinition of unused 'nogc' from line 1051 mercurial/util.py:3221:5: F811 redefinition of unused 'dirs' from line 3184 tests/silenttestrunner.py:24:5: F811 redefinition of unused 'main' from line 6 tests/test-context.py:90:1: F811 redefinition of unused 'scmutil' from line 4 tests/test-fb-hgext-cstore-treemanifest.py:146:5: F811 redefinition of unused 'testDeeplyNested' from line 134 tests/test-fb-hgext-extutil.py:46:5: F811 redefinition of unused 'testbgcommandfailure' from line 37 tests/test_hgsubversion_util.py:47:1: F811 redefinition of unused 'svnwrap' from line 31 (Python 2) tests/test_hgsubversion_util.py:49:1: F811 redefinition of unused 'svnwrap' from line 47 (Python 2) ``` Reviewed By: ryanmce Differential Revision: D6934533 fbshipit-source-id: 8b51851a76fec88bb59107ed05a901d42c7326f8
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from mercurial import cmdutil, registrar, scmutil, util
|
|
from mercurial.i18n import _
|
|
import os
|
|
|
|
cmdtable = {}
|
|
command = registrar.command(cmdtable)
|
|
testedwith = 'ships-with-fb-hgext'
|
|
|
|
@command('^catnotate', [
|
|
('r', 'rev', '', _('print the given revision'), _('REV')),
|
|
('a', 'text', None, _('treat all files as text')),
|
|
], _('[OPTION]... FILE...'),
|
|
)
|
|
def catnotate(ui, repo, file1, *args, **opts):
|
|
"""output the current or given revision of files annotated with filename
|
|
and line number.
|
|
|
|
Print the specified files as they were at the given revision. If
|
|
no revision is given, the parent of the working directory is used.
|
|
|
|
Binary files are skipped unless -a/--text option is provided.
|
|
"""
|
|
ctx = scmutil.revsingle(repo, opts.get('rev'))
|
|
matcher = scmutil.match(ctx, (file1,) + args, opts)
|
|
prefix = ''
|
|
|
|
err = 1
|
|
# modified and stripped mercurial.cmdutil.cat follows
|
|
def write(path):
|
|
fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
|
|
pathname=os.path.join(prefix, path))
|
|
data = ctx[path].data()
|
|
if not opts.get('text') and util.binary(data):
|
|
fp.write("%s: binary file\n" % path)
|
|
return
|
|
|
|
for (num, line) in enumerate(data.split("\n"), start=1):
|
|
line = line + "\n"
|
|
fp.write("%s:%s: %s" % (path, num, line))
|
|
fp.close()
|
|
|
|
# Automation often uses hg cat on single files, so special case it
|
|
# for performance to avoid the cost of parsing the manifest.
|
|
if len(matcher.files()) == 1 and not matcher.anypats():
|
|
file = matcher.files()[0]
|
|
mfl = repo.manifestlog
|
|
mfnode = ctx.manifestnode()
|
|
if mfnode and mfl[mfnode].find(file)[0]:
|
|
write(file)
|
|
return 0
|
|
|
|
for abs in ctx.walk(matcher):
|
|
write(abs)
|
|
err = 0
|
|
|
|
return err
|