# HG changeset patch # User Augie Fackler # Date 1392214743 18000 # Node ID cb4dccc90ff1ef75017be49daf8bc85dcb7214ef # Parent 99c503cfcc9c6f1399b47d4a67bcdce6a1785ead# Parent bab98093051b32095ae20663adf507dc859af77b Merge with stable. diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -9,3 +9,4 @@ 0cbf9fd89672e73165e1bb4db1ec8f7f65b95c94 07234759a3f750029ccaa001837d42fa12dd33ee 1.4 77b22e5b4ea6c248e079afd0f1e544cb5690ce20 1.5 d0f3a5c2cb56ce65d9ef1c611c8bfbebdc3bef34 1.5.1 +7d47a0f731354505ed9ae8d60d2a6996e8c3294f 1.6 diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -33,27 +33,9 @@ demandimport.ignore.extend([ 'svn.ra', ]) -try: - from mercurial import templatekw - # force demandimport to load templatekw - templatekw.keywords -except ImportError: - templatekw = None - -try: - from mercurial import revset - # force demandimport to load revset - revset.methods -except ImportError: - revset = None - -try: - from mercurial import subrepo - # require svnsubrepo and hg >= 1.7.1 - subrepo.svnsubrepo - hgutil.checknlink -except (ImportError, AttributeError), e: - subrepo = None +from mercurial import templatekw +from mercurial import revset +from mercurial import subrepo import svncommands import util @@ -124,9 +106,8 @@ except AttributeError: except ImportError: pass -def extsetup(): +def extsetup(ui): """insert command wrappers for a bunch of commands""" - # add the ui argument to this function once we drop support for 1.3 docvals = {'extension': 'hgsubversion'} for cmd, (generic, target, fixdoc, ppopts, opts) in wrapcmds.iteritems(): @@ -163,20 +144,13 @@ def extsetup(): lambda: open(os.path.join(helpdir, 'subversion.rst')).read()), ) - # in 1.6 and earler the help table is a tuple - if getattr(help.helptable, 'extend', None): - help.helptable.extend(entries) - else: - help.helptable = help.helptable + entries + help.helptable.extend(entries) - if templatekw: - templatekw.keywords.update(util.templatekeywords) + templatekw.keywords.update(util.templatekeywords) - if revset: - revset.symbols.update(util.revsets) + revset.symbols.update(util.revsets) - if subrepo: - subrepo.types['hgsubversion'] = svnexternals.svnsubrepo + subrepo.types['hgsubversion'] = svnexternals.svnsubrepo def reposetup(ui, repo): if repo.local(): @@ -184,7 +158,7 @@ def reposetup(ui, repo): for tunnel in ui.configlist('hgsubversion', 'tunnels'): hg.schemes['svn+' + tunnel] = svnrepo - if revset and ui.configbool('hgsubversion', 'nativerevs'): + if ui.configbool('hgsubversion', 'nativerevs'): extensions.wrapfunction(revset, 'stringset', util.revset_stringset) _old_local = hg.schemes['file'] diff --git a/hgsubversion/help/subversion.rst b/hgsubversion/help/subversion.rst --- a/hgsubversion/help/subversion.rst +++ b/hgsubversion/help/subversion.rst @@ -45,8 +45,8 @@ issue ``hg clone http://python-nose.goog works with any directory with a Subversion repository, and is known as a single directory clone. Normally, converted changesets will be marked as belonging to the ``default`` branch, but this can be changed by using the ``-b/--branch`` -option when using Mercurial 1.5 or later. To force single directory clone, use -hgsubversion.layout option (see below for detailed help) :: +option. To force single directory clone, use hgsubversion.layout option (see +below for detailed help) :: $ hg clone --layout single svn+http://python-nose.googlecode.com/svn nose-hg @@ -85,8 +85,6 @@ An example:: $ hg log --template='{rev}:{node|short} {author|user}\nsvn: {svnrev}\n' -The template keywords are available when using Mercurial 1.5 or later. - For finding changesets from Subversion, hgsubversion extends revsets to provide two new selectors: @@ -100,9 +98,7 @@ For example:: $ hg log -r 'fromsvn()' $ hg log -r 'svnrev(500)' -Revsets are available when using Mercurial 1.6 or later and are -accepted by several Mercurial commands for specifying revisions. See -``hg help revsets`` for details. +See ``hg help revsets`` for details. Support for externals --------------------- @@ -146,7 +142,7 @@ related Subversion repository. Alternatively, one can use the ``hgsubversion.externals`` in hgrc to specify ``subrepos`` as the externals mode. In this mode, ``.hgsub`` and ``.hgsubstate`` files will be used instead of -``.hgsvnexternals``. This feature requires Mercurial 1.7.1 or later. +``.hgsvnexternals``. Using Subrepositories @@ -183,8 +179,6 @@ with the revision identifier replaced wi This mode has the following limitations: -* Require Mercurial >= 1.7.1 to work correctly on all platforms. - * "hgsubversion" subrepositories require hgsubversion extension to be available. To operate transparently on ``svn:externals`` we have to stay as close as possible to their original property @@ -365,10 +359,10 @@ settings: when necessary. ``hgsubversion.externals`` - Set to ``subrepos`` to switch to subrepos-based externals support - (requires Mercurial 1.7.1 or later.) Default is ``svnexternals``, - which uses a custom hgsubversion-specific format and works on - older versions of Mercurial. Use ``ignore`` to avoid converting externals. + Set to ``subrepos`` to switch to subrepos-based externals support. Default + is ``svnexternals``, which uses a custom hgsubversion-specific format and + works on older versions of Mercurial. Use ``ignore`` to avoid converting + externals. The following options only have an effect on the initial clone of a repository: diff --git a/hgsubversion/stupid.py b/hgsubversion/stupid.py --- a/hgsubversion/stupid.py +++ b/hgsubversion/stupid.py @@ -158,27 +158,8 @@ def filteriterhunks(meta): applycurrent = False # Passing False instead of textmode because we should never # be ignoring EOL type. - if iterhunks.func_code.co_argcount == 1: - # Since 1.9 (28762bb767dc) - fp = args[0] - gen = iterhunks(fp) - else: - ui, fp = args[:2] - if len(args) > 2: - sourcefile = args[2] - else: - sourcefile = kwargs.get('sourcefile', None) - if len(args) > 3: - textmode = args[3] - else: - textmode = kwargs.get('textmode', False) - if not iterhunks.func_defaults: - # Since 1.7 (cfedc529e4a1) - gen = iterhunks(ui, fp) - elif len(iterhunks.func_defaults) == 1: - gen = iterhunks(ui, fp, sourcefile) - else: - gen = iterhunks(ui, fp, sourcefile, textmode) + fp = args[0] + gen = iterhunks(fp) for data in gen: if data[0] == 'file': if data[1][1] in meta.filemap: diff --git a/hgsubversion/svnexternals.py b/hgsubversion/svnexternals.py --- a/hgsubversion/svnexternals.py +++ b/hgsubversion/svnexternals.py @@ -3,26 +3,14 @@ import cStringIO import os, re, shutil, stat, subprocess from mercurial import util as hgutil from mercurial.i18n import _ +from mercurial import subrepo try: - from mercurial import subrepo - # require svnsubrepo and hg >= 1.7.1 - subrepo.svnsubrepo - hgutil.checknlink -except (ImportError, AttributeError), e: - subrepo = None - -passpegrev = True # see svnsubrepo below -try: - canonpath = hgutil.canonpath + from mercurial import scmutil + canonpath = scmutil.canonpath except (ImportError, AttributeError): - passpegrev = False - try: - from mercurial import scmutil - canonpath = scmutil.canonpath - except (ImportError, AttributeError): - from mercurial import pathutil - canonpath = pathutil.canonpath + from mercurial import pathutil + canonpath = pathutil.canonpath import util @@ -398,58 +386,53 @@ def parse(ui, ctx): raise hgutil.Abort(_('unknown externals modes: %s') % mode) return external -if subrepo: - class svnsubrepo(subrepo.svnsubrepo): - def __init__(self, ctx, path, state): - state = (state[0].split(':', 1)[1], state[1]) - super(svnsubrepo, self).__init__(ctx, path, state) - - def get(self, state, *args, **kwargs): - # Resolve source first - line = state[0].split(':', 1)[1] - source, pegrev = parsedefinition(line)[2:4] - try: - # Getting the root SVN repository URL is expensive. - # Assume the externals is absolute. - source = resolvesource(self._ui, None, source) - except RelativeSourceError: - svnurl = self._ctx._repo.ui.expandpath('default') - svnroot = getsvninfo(util.normalize_url(svnurl))[1] - source = resolvesource(self._ui, svnroot, source) - # hg < 1.9 svnsubrepo calls "svn checkout" with --rev - # only, so peg revisions are correctly used. 1.9 and - # higher, append the rev as a peg revision to the source - # URL, so we cannot add our own. We assume that "-r10 - # url@2" will be similar to "url@10" most of the time. - if pegrev is not None and passpegrev: - source = source + '@' + pegrev - state = (source, state[1]) - # hg-1.7.4-c19b9282d3a7 introduced the overwrite argument - return super(svnsubrepo, self).get(state, *args, **kwargs) - - def dirty(self, ignoreupdate=False): - # You cannot compare anything with HEAD. Just accept it - # can be anything. - if hasattr(self, '_wcrevs'): - wcrevs = self._wcrevs() - else: - wcrev = self._wcrev() - wcrevs = (wcrev, wcrev) - if (('HEAD' in wcrevs or self._state[1] == 'HEAD' or - self._state[1] in wcrevs or ignoreupdate) - and not self._wcchanged()[0]): - return False - return True - - def commit(self, text, user, date): - rev = super(svnsubrepo, self).commit(text, user, date) - # Keep unversioned externals unversioned - if self._state[1] == 'HEAD': - rev = 'HEAD' - return rev - - def basestate(self): - # basestate() was introduced by bcb973abcc0b in 2.2 - if self._state[1] == 'HEAD': - return 'HEAD' - return super(svnsubrepo, self).basestate() +class svnsubrepo(subrepo.svnsubrepo): + def __init__(self, ctx, path, state): + state = (state[0].split(':', 1)[1], state[1]) + super(svnsubrepo, self).__init__(ctx, path, state) + + def get(self, state, *args, **kwargs): + # Resolve source first + line = state[0].split(':', 1)[1] + source, pegrev = parsedefinition(line)[2:4] + try: + # Getting the root SVN repository URL is expensive. + # Assume the externals is absolute. + source = resolvesource(self._ui, None, source) + except RelativeSourceError: + svnurl = self._ctx._repo.ui.expandpath('default') + svnroot = getsvninfo(util.normalize_url(svnurl))[1] + source = resolvesource(self._ui, svnroot, source) + # hg 1.9 and higher, append the rev as a peg revision to + # the source URL, so we cannot add our own. We assume + # that "-r10 url@2" will be similar to "url@10" most of + # the time. + state = (source, state[1]) + return super(svnsubrepo, self).get(state, *args, **kwargs) + + def dirty(self, ignoreupdate=False): + # You cannot compare anything with HEAD. Just accept it + # can be anything. + if hasattr(self, '_wcrevs'): + wcrevs = self._wcrevs() + else: + wcrev = self._wcrev() + wcrevs = (wcrev, wcrev) + if (('HEAD' in wcrevs or self._state[1] == 'HEAD' or + self._state[1] in wcrevs or ignoreupdate) + and not self._wcchanged()[0]): + return False + return True + + def commit(self, text, user, date): + rev = super(svnsubrepo, self).commit(text, user, date) + # Keep unversioned externals unversioned + if self._state[1] == 'HEAD': + rev = 'HEAD' + return rev + + def basestate(self): + # basestate() was introduced by bcb973abcc0b in 2.2 + if self._state[1] == 'HEAD': + return 'HEAD' + return super(svnsubrepo, self).basestate() diff --git a/hgsubversion/svnrepo.py b/hgsubversion/svnrepo.py --- a/hgsubversion/svnrepo.py +++ b/hgsubversion/svnrepo.py @@ -71,10 +71,6 @@ def generate_repo_class(ui, repo): """ original = getattr(repo, fn.__name__, None) - # remove when dropping support for hg < 1.6. - if original is None and fn.__name__ == 'findoutgoing': - return - def wrapper(self, *args, **opts): capable = getattr(args[0], 'capable', lambda x: False) if capable('subversion'): diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -150,27 +150,13 @@ def pickle_atomic(data, file_path): """ f = hgutil.atomictempfile(file_path, 'w+b', 0644) pickle.dump(data, f) - # Older versions of hg have .rename() instead of .close on - # atomictempfile. - if getattr(hgutil.atomictempfile, 'rename', False): - f.rename() - else: - f.close() + f.close() def parseurl(url, heads=[]): - parsed = hg.parseurl(url, heads) - if len(parsed) == 3: - # old hg, remove when we can be 1.5-only - svn_url, heads, checkout = parsed - else: - svn_url, heads = parsed - if isinstance(heads, tuple) and len(heads) == 2: - # hg 1.6 or later - _junk, heads = heads - if heads: - checkout = heads[0] - else: - checkout = None + checkout = None + svn_url, (_junk, heads) = hg.parseurl(url, heads) + if heads: + checkout = heads[0] return svn_url, heads, checkout diff --git a/hgsubversion/wrappers.py b/hgsubversion/wrappers.py --- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -563,11 +563,7 @@ def clone(orig, ui, source, dest=None, * data = {} def hgclonewrapper(orig, ui, *args, **opts): - if getattr(hg, 'peer', None): - # Since 1.9 (d976542986d2) - origsource = args[1] - else: - origsource = args[0] + origsource = args[1] if isinstance(origsource, str): source, branch, checkout = util.parseurl(ui.expandpath(origsource), @@ -602,14 +598,11 @@ def clone(orig, ui, source, dest=None, * dstrepo = data.get('dstrepo') srcrepo = data.get('srcrepo') + dst = dstrepo.local() if dstrepo.local() and srcrepo.capable('subversion'): dst = dstrepo.local() - if isinstance(dst, bool): - # Apparently <= hg@1.9 - fd = dstrepo.opener("hgrc", "a", text=True) - else: - fd = dst.opener("hgrc", "a", text=True) + fd = dst.opener("hgrc", "a", text=True) preservesections = set(s for s, v in optionmap.itervalues()) preservesections |= extrasections for section in preservesections: