# HG changeset patch # User Sean Farley # Date 1462515049 25200 # Node ID 2f98d1e85c23a8485d9a843c98d92f0c595f1ad4 # Parent 2ae4fb5bfab90f93ebf074e382798a7d2e67137a templatekw: move to __init__ to prepare for newer mercurial diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -165,7 +165,13 @@ def extsetup(ui): help.helptable.extend(entries) - templatekw.keywords.update(util.templatekeywords) + templatekeywords = { + 'svnrev': svnrevkw, + 'svnpath': svnpathkw, + 'svnuuid': svnuuidkw, + } + + templatekw.keywords.update(templatekeywords) revset.symbols.update(util.revsets) @@ -219,3 +225,53 @@ cmdtable = { # only these methods are public __all__ = ('cmdtable', 'reposetup', 'uisetup') + +def _templatehelper(ctx, kw): + ''' + Helper function for displaying information about converted changesets. + ''' + convertinfo = util.getsvnrev(ctx, '') + + if not convertinfo or not convertinfo.startswith('svn:'): + return '' + + if kw == 'svnuuid': + return convertinfo[4:40] + elif kw == 'svnpath': + return convertinfo[40:].rsplit('@', 1)[0] + elif kw == 'svnrev': + return convertinfo[40:].rsplit('@', 1)[-1] + else: + raise hgutil.Abort('unrecognized hgsubversion keyword %s' % kw) + +def svnrevkw(**args): + """:svnrev: String. Converted subversion revision number.""" + return _templatehelper(args['ctx'], 'svnrev') + +def svnpathkw(**args): + """:svnpath: String. Converted subversion revision project path.""" + return _templatehelper(args['ctx'], 'svnpath') + +def svnuuidkw(**args): + """:svnuuid: String. Converted subversion revision repository identifier.""" + return _templatehelper(args['ctx'], 'svnuuid') + +def listsvnkeys(repo): + keys = {} + repo = repo.local() + metadir = os.path.join(repo.path, 'svn') + + if util.subversionmetaexists(repo.path): + w = repo.wlock() + try: + for key in util.pushkeyfiles: + fullpath = os.path.join(metadir, key) + if os.path.isfile(fullpath): + data = open(fullpath).read() + + # Some of the files could be large, but also quite compressible + keys[key] = base85.b85encode(zlib.compress(data)) + finally: + w.release() + + return keys diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -307,48 +307,10 @@ def issamefile(parentctx, childctx, f): # parentctx is not an ancestor of childctx, files are unrelated return False - def getsvnrev(ctx, defval=None): '''Extract SVN revision from commit metadata''' return ctx.extra().get('convert_revision', defval) - -def _templatehelper(ctx, kw): - ''' - Helper function for displaying information about converted changesets. - ''' - convertinfo = getsvnrev(ctx, '') - - if not convertinfo or not convertinfo.startswith('svn:'): - return '' - - if kw == 'svnuuid': - return convertinfo[4:40] - elif kw == 'svnpath': - return convertinfo[40:].rsplit('@', 1)[0] - elif kw == 'svnrev': - return convertinfo[40:].rsplit('@', 1)[-1] - else: - raise hgutil.Abort('unrecognized hgsubversion keyword %s' % kw) - -def svnrevkw(**args): - """:svnrev: String. Converted subversion revision number.""" - return _templatehelper(args['ctx'], 'svnrev') - -def svnpathkw(**args): - """:svnpath: String. Converted subversion revision project path.""" - return _templatehelper(args['ctx'], 'svnpath') - -def svnuuidkw(**args): - """:svnuuid: String. Converted subversion revision repository identifier.""" - return _templatehelper(args['ctx'], 'svnuuid') - -templatekeywords = { - 'svnrev': svnrevkw, - 'svnpath': svnpathkw, - 'svnuuid': svnuuidkw, -} - def revset_fromsvn(repo, subset, x): '''``fromsvn()`` Select changesets that originate from Subversion.