changeset 1403:2f98d1e85c23 stable

templatekw: move to __init__ to prepare for newer mercurial
author Sean Farley <sean@farley.io>
date Thu, 05 May 2016 23:10:49 -0700
parents 2ae4fb5bfab9
children c5b7fb8911c0
files hgsubversion/__init__.py hgsubversion/util.py
diffstat 2 files changed, 57 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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.