##// END OF EJS Templates
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows...
py3: proxy posixfile objects to re-add a useful 'name' attribute on Windows This file object is used in the vfs layer, so there are many errors like this: ... File "mercurial\localrepo.py", line 2569, in savecommitmessage return self.pathto(fp.name[len(self.root) + 1:]) TypeError: 'int' object is not subscriptable It looks like the 'name' value is actually the fileno() value, and the documentation says the name parameter to PyFile_FromFd() is ignored. [1] I tried just assigning the attribute after osutil.posixfile() returns, but that crashes saying that it's read-only. [1] https://docs.python.org/3.6/c-api/file.html

File last commit:

r28562:2b585677 default
r39845:68ea1f8d default
Show More
python-hook-examples.py
26 lines | 630 B | text/x-python | PythonLexer
/ contrib / python-hook-examples.py
'''
Examples of useful python hooks for Mercurial.
'''
from __future__ import absolute_import
from mercurial import (
patch,
util,
)
def diffstat(ui, repo, **kwargs):
'''Example usage:
[hooks]
commit.diffstat = python:/path/to/this/file.py:diffstat
changegroup.diffstat = python:/path/to/this/file.py:diffstat
'''
if kwargs.get('parent2'):
return
node = kwargs['node']
first = repo[node].p1().node()
if 'url' in kwargs:
last = repo['tip'].node()
else:
last = node
diff = patch.diff(repo, first, last)
ui.write(patch.diffstat(util.iterlines(diff)))