##// END OF EJS Templates
templatefuncs: add mailmap template function...
templatefuncs: add mailmap template function This commit adds a template function to support the .mailmap file in Mercurial repositories. The .mailmap file comes from git, and can be used to map new emails and names for old commits. The general use case is that someone may change their name or author commits under different emails and aliases, which would make these commits appear as though they came from different persons. The file allows you to specify the correct name that should be used in place of the author field specified in the commit. The mailmap file has 4 possible formats used to map old "commit" names to new "proper" names: 1. <proper@email.com> <commit@email.com> 2. Proper Name <commit@email.com> 3. Proper Name <proper@email.com> <commit@email.com> 4. Proper Name <proper@email.com> Commit Name <commit@email.com> Essentially there is a commit email present in each mailmap entry, that maps to either an updated name, email, or both. The final possible format allows commits authored by a person who used both an old name and an old email to map to a new name and email. To parse the file, we split by spaces and build a name out of every element that does not start with "<". Once we find an element that does start with "<" we concatenate all the name elements that preceded and add that as a parsed name. We then add the email as the first parsed email. We repeat the process until the end of the line, or a comment is found. We will be left with all parsed names in a list, and all parsed emails in a list, with the 0 index being the proper values and the 1 index being the commit values (if they were specified in the entry). The commit values are added as the keys to a dict, and with the proper fields as the values. The mapname function takes the mapping object and the commit author field and attempts to look for a corresponding entry. To do so we try (commit name, commit email) first, and if no results are returned then (None, commit email) is also looked up. This is due to format 4 from above, where someone may have a mailmap entry with both name and email, and if they don't it is possible they have an entry that uses only the commit email. Differential Revision: https://phab.mercurial-scm.org/D2904

File last commit:

r37113:e24802ea default
r37227:2a2ce93e default
Show More
scmwindows.py
61 lines | 1.9 KiB | text/x-python | PythonLexer
Gregory Szorc
scmwindows: use absolute_import
r27481 from __future__ import absolute_import
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 import os
Gregory Szorc
scmwindows: use absolute_import
r27481
from . import (
Pulkit Goyal
py3: replace os.environ with encoding.environ (part 4 of 5)
r30637 encoding,
Pulkit Goyal
py3: replace os.pathsep with pycompat.ospathsep...
r30612 pycompat,
Gregory Szorc
scmwindows: use absolute_import
r27481 util,
Yuya Nishihara
scmutil: move util.termwidth()...
r30309 win32,
Gregory Szorc
scmwindows: use absolute_import
r27481 )
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690
Pulkit Goyal
py3: conditionalize _winreg import...
r29760 try:
import _winreg as winreg
winreg.CloseKey
except ImportError:
import winreg
Yuya Nishihara
pager: use less as a fallback on Unix...
r32078 # MS-DOS 'more' is the only pager available by default on Windows.
fallbackpager = 'more'
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 def systemrcpath():
'''return default os-specific hgrc search path'''
rcpath = []
Yuya Nishihara
rcutil: directly call win32.executablepath()...
r37113 filename = win32.executablepath()
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 # Use mercurial.ini found in directory with hg.exe
progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
Mads Kiilerich
windows: read all global config files, not just the first (issue4491) (BC)...
r26625 rcpath.append(progrc)
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 # Use hgrc.d found in directory with hg.exe
progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
if os.path.isdir(progrcd):
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 for f, kind in util.listdir(progrcd):
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 if f.endswith('.rc'):
rcpath.append(os.path.join(progrcd, f))
# else look for a system rcpath in the registry
value = util.lookupreg('SOFTWARE\\Mercurial', None,
Pulkit Goyal
py3: conditionalize _winreg import...
r29760 winreg.HKEY_LOCAL_MACHINE)
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 if not isinstance(value, str) or not value:
return rcpath
value = util.localpath(value)
Pulkit Goyal
py3: replace os.pathsep with pycompat.ospathsep...
r30612 for p in value.split(pycompat.ospathsep):
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 if p.lower().endswith('mercurial.ini'):
rcpath.append(p)
elif os.path.isdir(p):
Yuya Nishihara
osutil: proxy through util (and platform) modules (API)...
r32203 for f, kind in util.listdir(p):
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 if f.endswith('.rc'):
rcpath.append(os.path.join(p, f))
return rcpath
def userrcpath():
'''return os-specific hgrc search path to the user dir'''
home = os.path.expanduser('~')
path = [os.path.join(home, 'mercurial.ini'),
os.path.join(home, '.hgrc')]
Pulkit Goyal
py3: replace os.environ with encoding.environ (part 4 of 5)
r30637 userprofile = encoding.environ.get('USERPROFILE')
Mads Kiilerich
config: don't read the same config file twice...
r22583 if userprofile and userprofile != home:
Kevin Bullock
scmutil: split platform-specific bits into their own modules...
r18690 path.append(os.path.join(userprofile, 'mercurial.ini'))
path.append(os.path.join(userprofile, '.hgrc'))
return path
Yuya Nishihara
scmutil: move util.termwidth()...
r30309
Yuya Nishihara
scmutil: extend termwidth() to return terminal height, renamed to termsize()...
r30314 def termsize(ui):
return win32.termsize()