##// 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:

r36669:6b1eb4c6 default
r37227:2a2ce93e default
Show More
httpconnection.py
109 lines | 3.6 KiB | text/x-python | PythonLexer
Augie Fackler
url: use new http support if requested by the user...
r14244 # httpconnection.py - urllib2 handler for new http support
#
# Copyright 2005, 2006, 2007, 2008 Matt Mackall <mpm@selenic.com>
# Copyright 2006, 2007 Alexis S. L. Carvalho <alexis@cecm.usp.br>
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
# Copyright 2011 Google, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Gregory Szorc
httpconnection: use absolute_import
r27521
from __future__ import absolute_import
import os
Augie Fackler
url: use new http support if requested by the user...
r14244
Gregory Szorc
httpconnection: use absolute_import
r27521 from .i18n import _
from . import (
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 pycompat,
Gregory Szorc
httpconnection: use absolute_import
r27521 util,
)
Augie Fackler
url: use new http support if requested by the user...
r14244
timeless
pycompat: switch to util.urlreq/util.urlerr for py3 compat
r28883 urlerr = util.urlerr
urlreq = util.urlreq
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
class httpsendfile(object):
"""This is a wrapper around the objects returned by python's "open".
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 Its purpose is to send file-like objects via HTTP.
It do however not define a __len__ attribute because the length
might be more than Py_ssize_t can handle.
Augie Fackler
url: use new http support if requested by the user...
r14244 """
def __init__(self, ui, *args, **kwargs):
self.ui = ui
self._data = open(*args, **kwargs)
self.seek = self._data.seek
self.close = self._data.close
self.write = self._data.write
Mads Kiilerich
http: handle push of bundles > 2 GB again (issue3017)...
r15152 self.length = os.fstat(self._data.fileno()).st_size
Augie Fackler
url: use new http support if requested by the user...
r14244 self._pos = 0
Martin Geisler
Use explicit integer division...
r15791 self._total = self.length // 1024 * 2
Augie Fackler
url: use new http support if requested by the user...
r14244
def read(self, *args, **kwargs):
Yuya Nishihara
httpconnection: make sure to clear progress of httpsendfile at EOF...
r31488 ret = self._data.read(*args, **kwargs)
if not ret:
Augie Fackler
url: use new http support if requested by the user...
r14244 self.ui.progress(_('sending'), None)
Yuya Nishihara
httpconnection: make sure to clear progress of httpsendfile at EOF...
r31488 return ret
Augie Fackler
url: use new http support if requested by the user...
r14244 self._pos += len(ret)
# We pass double the max for total because we currently have
# to send the bundle twice in the case of a server that
# requires authentication. Since we can't know until we try
# once whether authentication will be required, just lie to
# the user and maybe the push succeeds suddenly at 50%.
Martin Geisler
Use explicit integer division...
r15791 self.ui.progress(_('sending'), self._pos // 1024,
Augie Fackler
url: use new http support if requested by the user...
r14244 unit=_('kb'), total=self._total)
return ret
Mads Kiilerich
largefiles: use context for file closing...
r30142 def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
Augie Fackler
url: use new http support if requested by the user...
r14244 # moved here from url.py to avoid a cycle
Patrick Mezard
http: pass user to readauthforuri() (fix 4a43e23b8c55)...
r15025 def readauthforuri(ui, uri, user):
Augie Fackler
httpconnection: convert url to bytes in readauthforuri...
r36669 uri = pycompat.bytesurl(uri)
Augie Fackler
url: use new http support if requested by the user...
r14244 # Read configuration
Gregory Szorc
httpconnection: rename config to groups...
r31300 groups = {}
Augie Fackler
url: use new http support if requested by the user...
r14244 for key, val in ui.configitems('auth'):
Gregory Szorc
httpconnection: allow a global auth.cookiefile config entry...
r31935 if key in ('cookiefile',):
continue
Augie Fackler
url: use new http support if requested by the user...
r14244 if '.' not in key:
ui.warn(_("ignoring invalid [auth] key '%s'\n") % key)
continue
group, setting = key.rsplit('.', 1)
Gregory Szorc
httpconnection: rename config to groups...
r31300 gdict = groups.setdefault(group, {})
Augie Fackler
url: use new http support if requested by the user...
r14244 if setting in ('username', 'cert', 'key'):
val = util.expandpath(val)
gdict[setting] = val
# Find the best match
Pierre-Yves David
httpconnection: drop Python 2.4 specify hack...
r25206 scheme, hostpath = uri.split('://', 1)
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 bestuser = None
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = 0
bestauth = None
Gregory Szorc
httpconnection: rename config to groups...
r31300 for group, auth in groups.iteritems():
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 if user and user != auth.get('username', user):
# If a username was set in the URI, the entry username
# must either match it or be unset
continue
Augie Fackler
url: use new http support if requested by the user...
r14244 prefix = auth.get('prefix')
if not prefix:
continue
p = prefix.split('://', 1)
if len(p) > 1:
schemes, prefix = [p[0]], p[1]
else:
schemes = (auth.get('schemes') or 'https').split()
if (prefix == '*' or hostpath.startswith(prefix)) and \
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 (len(prefix) > bestlen or (len(prefix) == bestlen and \
not bestuser and 'username' in auth)) \
and scheme in schemes:
Augie Fackler
url: use new http support if requested by the user...
r14244 bestlen = len(prefix)
bestauth = group, auth
Patrick Mezard
hgweb: do not ignore [auth] if url has a username (issue2822)...
r15005 bestuser = auth.get('username')
if user and not bestuser:
auth['username'] = user
Augie Fackler
url: use new http support if requested by the user...
r14244 return bestauth