2009-05-03 17:28:43 +04:00
|
|
|
''' Module for self-contained maps. '''
|
|
|
|
|
2012-05-12 16:38:34 +04:00
|
|
|
import errno
|
2009-05-03 17:28:43 +04:00
|
|
|
import os
|
|
|
|
from mercurial import util as hgutil
|
2009-06-10 17:45:20 +04:00
|
|
|
from mercurial import node
|
2009-05-03 17:28:43 +04:00
|
|
|
|
2009-07-01 23:42:46 +04:00
|
|
|
import svncommands
|
2011-09-30 20:42:27 +04:00
|
|
|
import util
|
2009-07-01 23:42:46 +04:00
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
class AuthorMap(dict):
|
|
|
|
'''A mapping from Subversion-style authors to Mercurial-style
|
|
|
|
authors, and back. The data is stored persistently on disk.
|
2009-05-09 01:11:52 +04:00
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
If the 'hgsubversion.defaultauthors' configuration option is set to false,
|
|
|
|
attempting to obtain an unknown author will fail with an Abort.
|
2014-03-24 20:20:45 +04:00
|
|
|
|
2013-01-08 13:44:38 +04:00
|
|
|
If the 'hgsubversion.caseignoreauthors' configuration option is set to true,
|
|
|
|
the userid from Subversion is always compared lowercase.
|
2009-05-03 17:28:43 +04:00
|
|
|
'''
|
|
|
|
|
2014-03-24 20:20:46 +04:00
|
|
|
def __init__(self, meta):
|
2009-05-03 17:28:43 +04:00
|
|
|
'''Initialise a new AuthorMap.
|
2009-05-09 01:11:52 +04:00
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
The ui argument is used to print diagnostic messages.
|
2009-05-09 01:11:52 +04:00
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
The path argument is the location of the backing store,
|
2012-01-20 19:06:32 +04:00
|
|
|
typically .hg/svn/authors.
|
2009-05-03 17:28:43 +04:00
|
|
|
'''
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta = meta
|
|
|
|
self.defaulthost = ''
|
|
|
|
if meta.defaulthost:
|
|
|
|
self.defaulthost = '@%s' % meta.defaulthost.lstrip('@')
|
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
self.super = super(AuthorMap, self)
|
|
|
|
self.super.__init__()
|
2014-03-24 20:20:46 +04:00
|
|
|
self.load(self.meta.authors_file)
|
2009-05-03 17:28:43 +04:00
|
|
|
|
2014-03-24 20:20:46 +04:00
|
|
|
# append authors specified from the commandline
|
2014-03-24 20:20:46 +04:00
|
|
|
clmap = util.configpath(self.meta.ui, 'authormap')
|
2014-03-24 20:20:46 +04:00
|
|
|
if clmap:
|
|
|
|
self.load(clmap)
|
|
|
|
|
2009-05-03 17:28:43 +04:00
|
|
|
def load(self, path):
|
|
|
|
''' Load mappings from a file at the specified path. '''
|
2011-07-06 16:55:14 +04:00
|
|
|
|
|
|
|
path = os.path.expandvars(path)
|
2009-05-28 11:44:08 +04:00
|
|
|
if not os.path.exists(path):
|
|
|
|
return
|
2009-06-15 18:09:27 +04:00
|
|
|
|
|
|
|
writing = False
|
2014-03-24 20:20:46 +04:00
|
|
|
if path != self.meta.authors_file:
|
|
|
|
writing = open(self.meta.authors_file, 'a')
|
2009-06-15 18:09:27 +04:00
|
|
|
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.debug('reading authormap from %s\n' % path)
|
2009-05-28 11:44:08 +04:00
|
|
|
f = open(path, 'r')
|
2011-07-24 04:33:50 +04:00
|
|
|
for number, line_org in enumerate(f):
|
2009-05-28 11:44:08 +04:00
|
|
|
|
2011-07-24 04:33:50 +04:00
|
|
|
line = line_org.split('#')[0]
|
2009-05-28 11:44:08 +04:00
|
|
|
if not line.strip():
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
src, dst = line.split('=', 1)
|
|
|
|
except (IndexError, ValueError):
|
|
|
|
msg = 'ignoring line %i in author map %s: %s\n'
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.status(msg % (number, path, line.rstrip()))
|
2009-05-28 11:44:08 +04:00
|
|
|
continue
|
|
|
|
|
|
|
|
src = src.strip()
|
|
|
|
dst = dst.strip()
|
2011-07-24 04:33:50 +04:00
|
|
|
|
2014-03-24 20:20:46 +04:00
|
|
|
if self.meta.caseignoreauthors:
|
2013-01-08 13:44:38 +04:00
|
|
|
src = src.lower()
|
|
|
|
|
2011-07-24 04:33:50 +04:00
|
|
|
if writing:
|
|
|
|
if not src in self:
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.debug('adding author %s to author map\n' % src)
|
2011-07-24 04:33:50 +04:00
|
|
|
elif dst != self[src]:
|
|
|
|
msg = 'overriding author: "%s" to "%s" (%s)\n'
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.status(msg % (self[src], dst, src))
|
2011-07-24 04:33:50 +04:00
|
|
|
writing.write(line_org)
|
|
|
|
|
2009-06-15 18:09:27 +04:00
|
|
|
self[src] = dst
|
2009-05-03 17:28:43 +04:00
|
|
|
|
|
|
|
f.close()
|
2009-06-15 18:09:27 +04:00
|
|
|
if writing:
|
|
|
|
writing.close()
|
2009-05-03 17:28:43 +04:00
|
|
|
|
|
|
|
def __getitem__(self, author):
|
|
|
|
''' Similar to dict.__getitem__, except in case of an unknown author.
|
|
|
|
In such cases, a new value is generated and added to the dictionary
|
|
|
|
as well as the backing store. '''
|
2010-10-10 01:20:52 +04:00
|
|
|
if author is None:
|
|
|
|
author = '(no author)'
|
2013-01-08 13:44:38 +04:00
|
|
|
|
2014-03-24 20:20:46 +04:00
|
|
|
search_author = author
|
|
|
|
if self.meta.caseignoreauthors:
|
2013-01-08 13:44:38 +04:00
|
|
|
search_author = author.lower()
|
|
|
|
|
|
|
|
if search_author in self:
|
|
|
|
result = self.super.__getitem__(search_author)
|
2014-03-24 20:20:46 +04:00
|
|
|
elif self.meta.defaultauthors:
|
2009-05-03 20:51:29 +04:00
|
|
|
self[author] = result = '%s%s' % (author, self.defaulthost)
|
2009-05-28 11:44:08 +04:00
|
|
|
msg = 'substituting author "%s" for default "%s"\n'
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.debug(msg % (author, result))
|
2009-05-03 17:28:43 +04:00
|
|
|
else:
|
2009-05-28 11:44:08 +04:00
|
|
|
msg = 'author %s has no entry in the author map!'
|
|
|
|
raise hgutil.Abort(msg % author)
|
2014-03-24 20:20:46 +04:00
|
|
|
self.meta.ui.debug('mapping author "%s" to "%s"\n' % (author, result))
|
2009-05-03 17:28:43 +04:00
|
|
|
return result
|
|
|
|
|
|
|
|
def reverselookup(self, author):
|
|
|
|
for svnauthor, hgauthor in self.iteritems():
|
|
|
|
if author == hgauthor:
|
|
|
|
return svnauthor
|
|
|
|
else:
|
|
|
|
# Mercurial incorrectly splits at e.g. '.', so we roll our own.
|
|
|
|
return author.rsplit('@', 1)[0]
|
2009-06-10 17:45:20 +04:00
|
|
|
|
|
|
|
|
2010-10-06 18:50:10 +04:00
|
|
|
class Tags(dict):
|
2010-01-18 23:40:29 +03:00
|
|
|
"""Map tags to converted node identifier.
|
2009-06-24 06:33:40 +04:00
|
|
|
|
2010-10-08 21:07:04 +04:00
|
|
|
tag names are non-empty strings. Tags are saved in a file
|
|
|
|
called tagmap, for backwards compatibility reasons.
|
2010-01-18 23:40:29 +03:00
|
|
|
"""
|
2009-07-01 23:42:46 +04:00
|
|
|
VERSION = 2
|
2009-06-24 06:33:40 +04:00
|
|
|
|
2014-03-24 20:20:45 +04:00
|
|
|
def __init__(self, meta, endrev=None):
|
2009-06-24 06:33:40 +04:00
|
|
|
dict.__init__(self)
|
2014-03-24 20:20:45 +04:00
|
|
|
self.meta = meta
|
2010-10-06 17:18:15 +04:00
|
|
|
self.endrev = endrev
|
2014-03-24 20:20:45 +04:00
|
|
|
if os.path.isfile(self.meta.tagfile):
|
|
|
|
self._load()
|
2009-06-24 06:33:40 +04:00
|
|
|
else:
|
|
|
|
self._write()
|
|
|
|
|
2014-03-24 20:20:45 +04:00
|
|
|
def _load(self):
|
|
|
|
f = open(self.meta.tagfile)
|
2009-06-24 06:33:40 +04:00
|
|
|
ver = int(f.readline())
|
2009-07-01 23:42:46 +04:00
|
|
|
if ver < self.VERSION:
|
2014-03-24 20:20:45 +04:00
|
|
|
self.meta.ui.status('tag map outdated, running rebuildmeta...\n')
|
2009-07-01 23:42:46 +04:00
|
|
|
f.close()
|
2014-03-24 20:20:45 +04:00
|
|
|
os.unlink(self.meta.tagfile)
|
|
|
|
svncommands.rebuildmeta(self.meta.ui, self.meta.repo, ())
|
2009-07-01 23:42:46 +04:00
|
|
|
return
|
|
|
|
elif ver != self.VERSION:
|
2012-05-12 17:41:21 +04:00
|
|
|
raise hgutil.Abort('tagmap too new -- please upgrade')
|
2009-06-24 06:33:40 +04:00
|
|
|
for l in f:
|
2011-09-30 20:50:10 +04:00
|
|
|
ha, revision, tag = l.split(' ', 2)
|
2009-07-01 23:42:46 +04:00
|
|
|
revision = int(revision)
|
2009-06-24 06:33:40 +04:00
|
|
|
tag = tag[:-1]
|
2009-07-01 23:42:46 +04:00
|
|
|
if self.endrev is not None and revision > self.endrev:
|
|
|
|
break
|
2010-01-18 23:40:29 +03:00
|
|
|
if not tag:
|
|
|
|
continue
|
2011-09-30 20:50:10 +04:00
|
|
|
dict.__setitem__(self, tag, node.bin(ha))
|
2009-06-24 06:33:40 +04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
def _write(self):
|
2009-07-01 23:42:46 +04:00
|
|
|
assert self.endrev is None
|
2014-03-24 20:20:45 +04:00
|
|
|
f = open(self.meta.tagfile, 'w')
|
2009-06-24 06:33:40 +04:00
|
|
|
f.write('%s\n' % self.VERSION)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def update(self, other):
|
2010-10-06 17:18:15 +04:00
|
|
|
for k, v in other.iteritems():
|
2009-06-24 06:33:40 +04:00
|
|
|
self[k] = v
|
|
|
|
|
|
|
|
def __contains__(self, tag):
|
2010-03-28 03:42:47 +04:00
|
|
|
return (tag and dict.__contains__(self, tag)
|
2010-01-18 23:40:29 +03:00
|
|
|
and dict.__getitem__(self, tag) != node.nullid)
|
2009-06-24 06:33:40 +04:00
|
|
|
|
|
|
|
def __getitem__(self, tag):
|
2010-01-18 23:40:29 +03:00
|
|
|
if tag and tag in self:
|
2009-06-24 06:33:40 +04:00
|
|
|
return dict.__getitem__(self, tag)
|
|
|
|
raise KeyError()
|
|
|
|
|
2009-07-01 23:42:46 +04:00
|
|
|
def __setitem__(self, tag, info):
|
2010-01-18 23:40:29 +03:00
|
|
|
if not tag:
|
|
|
|
raise hgutil.Abort('tag cannot be empty')
|
2011-09-30 20:50:10 +04:00
|
|
|
ha, revision = info
|
2014-03-24 20:20:45 +04:00
|
|
|
f = open(self.meta.tagfile, 'a')
|
2011-09-30 20:50:10 +04:00
|
|
|
f.write('%s %s %s\n' % (node.hex(ha), revision, tag))
|
2009-06-24 06:33:40 +04:00
|
|
|
f.close()
|
2011-09-30 20:50:10 +04:00
|
|
|
dict.__setitem__(self, tag, ha)
|
2009-06-24 06:33:40 +04:00
|
|
|
|
|
|
|
|
2009-06-10 17:45:20 +04:00
|
|
|
class RevMap(dict):
|
|
|
|
|
|
|
|
VERSION = 1
|
|
|
|
|
2014-03-24 20:20:44 +04:00
|
|
|
def __init__(self, meta):
|
2009-06-10 17:45:20 +04:00
|
|
|
dict.__init__(self)
|
2014-03-24 20:20:44 +04:00
|
|
|
self.meta = meta
|
|
|
|
|
|
|
|
if os.path.isfile(self.meta.revmap_file):
|
2009-06-10 17:45:20 +04:00
|
|
|
self._load()
|
|
|
|
else:
|
|
|
|
self._write()
|
|
|
|
|
2009-06-11 12:32:32 +04:00
|
|
|
def hashes(self):
|
|
|
|
return dict((v, k) for (k, v) in self.iteritems())
|
|
|
|
|
|
|
|
def branchedits(self, branch, rev):
|
|
|
|
check = lambda x: x[0][1] == branch and x[0][0] < rev.revnum
|
|
|
|
return sorted(filter(check, self.iteritems()), reverse=True)
|
|
|
|
|
2012-05-12 16:38:34 +04:00
|
|
|
@classmethod
|
2014-03-24 20:20:44 +04:00
|
|
|
def readmapfile(cls, path, missingok=True):
|
2012-05-12 16:38:34 +04:00
|
|
|
try:
|
2014-03-24 20:20:44 +04:00
|
|
|
f = open(path)
|
2012-05-12 16:38:34 +04:00
|
|
|
except IOError, err:
|
|
|
|
if not missingok or err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
return iter([])
|
2009-06-10 17:45:20 +04:00
|
|
|
ver = int(f.readline())
|
2012-05-12 16:38:34 +04:00
|
|
|
if ver != cls.VERSION:
|
2012-05-12 17:41:21 +04:00
|
|
|
raise hgutil.Abort('revmap too new -- please upgrade')
|
2012-05-12 16:38:34 +04:00
|
|
|
return f
|
|
|
|
|
|
|
|
def _load(self):
|
2014-03-24 20:20:44 +04:00
|
|
|
for l in self.readmapfile(self.meta.revmap_file):
|
2011-09-30 20:50:10 +04:00
|
|
|
revnum, ha, branch = l.split(' ', 2)
|
2009-06-10 17:45:20 +04:00
|
|
|
if branch == '\n':
|
|
|
|
branch = None
|
|
|
|
else:
|
|
|
|
branch = branch[:-1]
|
2009-06-11 12:32:32 +04:00
|
|
|
revnum = int(revnum)
|
2014-03-24 20:20:44 +04:00
|
|
|
if revnum > self.meta.lastpulled or not self.meta.lastpulled:
|
|
|
|
self.meta.lastpulled = revnum
|
2014-03-24 20:20:45 +04:00
|
|
|
if revnum < self.meta.firstpulled or not self.meta.firstpulled:
|
|
|
|
self.meta.firstpulled = revnum
|
2011-09-30 20:50:10 +04:00
|
|
|
dict.__setitem__(self, (revnum, branch), node.bin(ha))
|
2009-06-10 17:45:20 +04:00
|
|
|
|
|
|
|
def _write(self):
|
2014-03-24 20:20:44 +04:00
|
|
|
f = open(self.meta.revmap_file, 'w')
|
2009-06-10 17:45:20 +04:00
|
|
|
f.write('%s\n' % self.VERSION)
|
|
|
|
f.close()
|
|
|
|
|
2011-09-30 20:50:10 +04:00
|
|
|
def __setitem__(self, key, ha):
|
2009-06-10 17:45:20 +04:00
|
|
|
revnum, branch = key
|
2014-03-24 20:20:44 +04:00
|
|
|
f = open(self.meta.revmap_file, 'a')
|
2009-06-10 17:45:20 +04:00
|
|
|
b = branch or ''
|
2011-09-30 20:50:10 +04:00
|
|
|
f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n')
|
2009-06-10 17:45:20 +04:00
|
|
|
f.close()
|
2014-03-24 20:20:44 +04:00
|
|
|
if revnum > self.meta.lastpulled or not self.meta.lastpulled:
|
|
|
|
self.meta.lastpulled = revnum
|
2014-03-24 20:20:45 +04:00
|
|
|
if revnum < self.meta.firstpulled or not self.meta.firstpulled:
|
|
|
|
self.meta.firstpulled = revnum
|
2011-09-30 20:50:10 +04:00
|
|
|
dict.__setitem__(self, (revnum, branch), ha)
|
2009-06-11 20:52:30 +04:00
|
|
|
|
|
|
|
|
|
|
|
class FileMap(object):
|
|
|
|
|
2012-01-20 19:06:32 +04:00
|
|
|
VERSION = 1
|
|
|
|
|
2014-03-24 20:20:48 +04:00
|
|
|
def __init__(self, meta):
|
2012-01-20 19:06:32 +04:00
|
|
|
'''Initialise a new FileMap.
|
|
|
|
|
|
|
|
The ui argument is used to print diagnostic messages.
|
|
|
|
|
|
|
|
The path argument is the location of the backing store,
|
|
|
|
typically .hg/svn/filemap.
|
|
|
|
'''
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta = meta
|
2009-06-11 20:52:30 +04:00
|
|
|
self.include = {}
|
|
|
|
self.exclude = {}
|
2014-03-24 20:20:48 +04:00
|
|
|
if os.path.isfile(self.meta.filemap_file):
|
2012-01-20 19:06:32 +04:00
|
|
|
self._load()
|
|
|
|
else:
|
|
|
|
self._write()
|
2009-06-11 20:52:30 +04:00
|
|
|
|
2014-03-24 20:20:48 +04:00
|
|
|
# append file mapping specified from the commandline
|
2014-03-24 20:20:48 +04:00
|
|
|
clmap = util.configpath(self.meta.ui, 'filemap')
|
2014-03-24 20:20:48 +04:00
|
|
|
if clmap:
|
|
|
|
self.load(clmap)
|
|
|
|
|
2009-06-11 20:52:30 +04:00
|
|
|
def _rpairs(self, name):
|
|
|
|
e = len(name)
|
|
|
|
while e != -1:
|
|
|
|
yield name[:e], name[e+1:]
|
|
|
|
e = name.rfind('/', 0, e)
|
2012-01-28 02:18:25 +04:00
|
|
|
yield '.', name
|
2009-06-11 20:52:30 +04:00
|
|
|
|
2011-09-30 20:50:10 +04:00
|
|
|
def check(self, m, path):
|
|
|
|
m = getattr(self, m)
|
|
|
|
for pre, _suf in self._rpairs(path):
|
2012-01-28 02:18:25 +04:00
|
|
|
if pre in m:
|
|
|
|
return m[pre]
|
|
|
|
return -1
|
2009-06-11 20:52:30 +04:00
|
|
|
|
|
|
|
def __contains__(self, path):
|
2012-01-28 02:18:25 +04:00
|
|
|
if not len(path):
|
|
|
|
return True
|
|
|
|
if len(self.include):
|
2009-06-11 20:52:30 +04:00
|
|
|
inc = self.check('include', path)
|
2012-01-28 02:18:25 +04:00
|
|
|
elif not len(self.exclude):
|
|
|
|
return True
|
2009-06-11 20:52:30 +04:00
|
|
|
else:
|
2012-01-28 02:18:25 +04:00
|
|
|
inc = 0
|
|
|
|
if len(self.exclude):
|
2009-06-11 20:52:30 +04:00
|
|
|
exc = self.check('exclude', path)
|
|
|
|
else:
|
2012-01-28 02:18:25 +04:00
|
|
|
exc = -1
|
|
|
|
# respect rule order: newer rules override older
|
|
|
|
return inc > exc
|
2009-06-11 20:52:30 +04:00
|
|
|
|
2011-10-01 02:01:35 +04:00
|
|
|
# Needed so empty filemaps are false
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.include) + len(self.exclude)
|
|
|
|
|
2011-09-30 20:50:10 +04:00
|
|
|
def add(self, fn, m, path):
|
|
|
|
mapping = getattr(self, m)
|
2009-06-11 20:52:30 +04:00
|
|
|
if path in mapping:
|
2010-03-28 03:42:47 +04:00
|
|
|
msg = 'duplicate %s entry in %s: "%s"\n'
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.status(msg % (m, fn, path))
|
2009-06-11 20:52:30 +04:00
|
|
|
return
|
2012-10-14 15:21:03 +04:00
|
|
|
bits = m.rstrip('e'), path
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.debug('%sing %s\n' % bits)
|
2012-01-28 02:18:25 +04:00
|
|
|
# respect rule order
|
|
|
|
mapping[path] = len(self)
|
2014-03-24 20:20:48 +04:00
|
|
|
if fn != self.meta.filemap_file:
|
|
|
|
f = open(self.meta.filemap_file, 'a')
|
2012-01-20 19:06:32 +04:00
|
|
|
f.write(m + ' ' + path + '\n')
|
|
|
|
f.close()
|
2009-06-11 20:52:30 +04:00
|
|
|
|
|
|
|
def load(self, fn):
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.debug('reading file map from %s\n' % fn)
|
2009-06-11 20:52:30 +04:00
|
|
|
f = open(fn, 'r')
|
2012-01-20 19:06:32 +04:00
|
|
|
self.load_fd(f, fn)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def load_fd(self, f, fn):
|
2009-06-11 20:52:30 +04:00
|
|
|
for line in f:
|
|
|
|
if line.strip() == '' or line.strip()[0] == '#':
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
cmd, path = line.split(' ', 1)
|
|
|
|
cmd = cmd.strip()
|
|
|
|
path = path.strip()
|
|
|
|
if cmd in ('include', 'exclude'):
|
|
|
|
self.add(fn, cmd, path)
|
|
|
|
continue
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.warn('unknown filemap command %s\n' % cmd)
|
2009-06-11 20:52:30 +04:00
|
|
|
except IndexError:
|
|
|
|
msg = 'ignoring bad line in filemap %s: %s\n'
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.warn(msg % (fn, line.rstrip()))
|
2012-01-20 19:06:32 +04:00
|
|
|
|
|
|
|
def _load(self):
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.debug('reading in-repo file map from %s\n' % self.meta.filemap_file)
|
|
|
|
f = open(self.meta.filemap_file)
|
2012-01-20 19:06:32 +04:00
|
|
|
ver = int(f.readline())
|
|
|
|
if ver != self.VERSION:
|
2012-05-12 17:41:21 +04:00
|
|
|
raise hgutil.Abort('filemap too new -- please upgrade')
|
2014-03-24 20:20:48 +04:00
|
|
|
self.load_fd(f, self.meta.filemap_file)
|
2012-01-20 19:06:32 +04:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
def _write(self):
|
2014-03-24 20:20:48 +04:00
|
|
|
f = open(self.meta.filemap_file, 'w')
|
2012-01-20 19:06:32 +04:00
|
|
|
f.write('%s\n' % self.VERSION)
|
2009-06-11 20:52:30 +04:00
|
|
|
f.close()
|
2010-03-02 00:10:18 +03:00
|
|
|
|
|
|
|
class BranchMap(dict):
|
|
|
|
'''Facility for controlled renaming of branch names. Example:
|
|
|
|
|
|
|
|
oldname = newname
|
|
|
|
other = default
|
|
|
|
|
|
|
|
All changes on the oldname branch will now be on the newname branch; all
|
|
|
|
changes on other will now be on default (have no branch name set).
|
|
|
|
'''
|
|
|
|
|
2014-03-24 20:20:48 +04:00
|
|
|
def __init__(self, meta):
|
|
|
|
self.meta = meta
|
2010-03-02 00:10:18 +03:00
|
|
|
self.super = super(BranchMap, self)
|
|
|
|
self.super.__init__()
|
2014-03-24 20:20:48 +04:00
|
|
|
self.load(self.meta.branchmap_file)
|
2010-03-02 00:10:18 +03:00
|
|
|
|
2014-03-24 20:20:47 +04:00
|
|
|
# append branch mapping specified from the commandline
|
2014-03-24 20:20:48 +04:00
|
|
|
clmap = util.configpath(self.meta.ui, 'branchmap')
|
2014-03-24 20:20:47 +04:00
|
|
|
if clmap:
|
|
|
|
self.load(clmap)
|
|
|
|
|
2010-03-02 00:10:18 +03:00
|
|
|
def load(self, path):
|
|
|
|
'''Load mappings from a file at the specified path.'''
|
|
|
|
if not os.path.exists(path):
|
|
|
|
return
|
|
|
|
|
|
|
|
writing = False
|
2014-03-24 20:20:48 +04:00
|
|
|
if path != self.meta.branchmap_file:
|
|
|
|
writing = open(self.meta.branchmap_file, 'a')
|
2010-03-02 00:10:18 +03:00
|
|
|
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.debug('reading branchmap from %s\n' % path)
|
2010-03-02 00:10:18 +03:00
|
|
|
f = open(path, 'r')
|
|
|
|
for number, line in enumerate(f):
|
|
|
|
|
|
|
|
if writing:
|
|
|
|
writing.write(line)
|
|
|
|
|
|
|
|
line = line.split('#')[0]
|
|
|
|
if not line.strip():
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
src, dst = line.split('=', 1)
|
|
|
|
except (IndexError, ValueError):
|
|
|
|
msg = 'ignoring line %i in branch map %s: %s\n'
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.status(msg % (number, path, line.rstrip()))
|
2010-03-02 00:10:18 +03:00
|
|
|
continue
|
|
|
|
|
|
|
|
src = src.strip()
|
|
|
|
dst = dst.strip()
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.debug('adding branch %s to branch map\n' % src)
|
2010-07-10 16:48:57 +04:00
|
|
|
|
|
|
|
if not dst:
|
|
|
|
# prevent people from assuming such lines are valid
|
|
|
|
raise hgutil.Abort('removing branches is not supported, yet\n'
|
|
|
|
'(line %i in branch map %s)'
|
|
|
|
% (number, path))
|
|
|
|
elif src in self and dst != self[src]:
|
2010-03-02 00:10:18 +03:00
|
|
|
msg = 'overriding branch: "%s" to "%s" (%s)\n'
|
2014-03-24 20:20:48 +04:00
|
|
|
self.meta.ui.status(msg % (self[src], dst, src))
|
2010-03-02 00:10:18 +03:00
|
|
|
self[src] = dst
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
if writing:
|
|
|
|
writing.close()
|
2010-10-08 21:07:04 +04:00
|
|
|
|
|
|
|
class TagMap(dict):
|
|
|
|
'''Facility for controlled renaming of tags. Example:
|
|
|
|
|
|
|
|
oldname = newname
|
|
|
|
other =
|
|
|
|
|
2011-05-25 01:07:32 +04:00
|
|
|
The oldname tag from SVN will be represented as newname in the hg tags;
|
|
|
|
the other tag will not be reflected in the hg repository.
|
2010-10-08 21:07:04 +04:00
|
|
|
'''
|
|
|
|
|
2014-03-24 20:20:47 +04:00
|
|
|
def __init__(self, meta):
|
|
|
|
self.meta = meta
|
2010-10-08 21:07:04 +04:00
|
|
|
self.super = super(TagMap, self)
|
|
|
|
self.super.__init__()
|
2014-03-24 20:20:47 +04:00
|
|
|
self.load(self.meta.tagmap_file)
|
2010-10-08 21:07:04 +04:00
|
|
|
|
2014-03-24 20:20:47 +04:00
|
|
|
# append tag mapping specified from the commandline
|
2014-03-24 20:20:47 +04:00
|
|
|
clmap = util.configpath(self.meta.ui, 'tagmap')
|
2014-03-24 20:20:47 +04:00
|
|
|
if clmap:
|
|
|
|
self.load(clmap)
|
|
|
|
|
2010-10-08 21:07:04 +04:00
|
|
|
def load(self, path):
|
|
|
|
'''Load mappings from a file at the specified path.'''
|
|
|
|
if not os.path.exists(path):
|
|
|
|
return
|
|
|
|
|
|
|
|
writing = False
|
2014-03-24 20:20:47 +04:00
|
|
|
if path != self.meta.tagmap_file:
|
|
|
|
writing = open(self.meta.tagmap_file, 'a')
|
2010-10-08 21:07:04 +04:00
|
|
|
|
2014-03-24 20:20:47 +04:00
|
|
|
self.meta.ui.debug('reading tag renames from %s\n' % path)
|
2010-10-08 21:07:04 +04:00
|
|
|
f = open(path, 'r')
|
|
|
|
for number, line in enumerate(f):
|
|
|
|
|
|
|
|
if writing:
|
|
|
|
writing.write(line)
|
|
|
|
|
|
|
|
line = line.split('#')[0]
|
|
|
|
if not line.strip():
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
src, dst = line.split('=', 1)
|
|
|
|
except (IndexError, ValueError):
|
|
|
|
msg = 'ignoring line %i in tag renames %s: %s\n'
|
2014-03-24 20:20:47 +04:00
|
|
|
self.meta.ui.status(msg % (number, path, line.rstrip()))
|
2010-10-08 21:07:04 +04:00
|
|
|
continue
|
|
|
|
|
|
|
|
src = src.strip()
|
|
|
|
dst = dst.strip()
|
2014-03-24 20:20:47 +04:00
|
|
|
self.meta.ui.debug('adding tag %s to tag renames\n' % src)
|
2010-10-08 21:07:04 +04:00
|
|
|
|
|
|
|
if src in self and dst != self[src]:
|
|
|
|
msg = 'overriding tag rename: "%s" to "%s" (%s)\n'
|
2014-03-24 20:20:47 +04:00
|
|
|
self.meta.ui.status(msg % (self[src], dst, src))
|
2010-10-08 21:07:04 +04:00
|
|
|
self[src] = dst
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
if writing:
|
|
|
|
writing.close()
|