Commits

ZyX_I committed c698d5b

@aurum/drivers/mercurial: Made decorator in python script also transform paths
into repositories

Comments (0)

Files changed (1)

 import re
 
 def outermethod(func):
-    """ Decorator used to make functions omit showing python traceback in case vim_throw was used """
-    def f(*args, **kwargs):
+    """
+        Decorator used to make functions omit showing python traceback in case vim_throw was used.
+        Also transforms first argument (which is a path) to an repository object
+    """
+    def f(path, *args, **kwargs):
         try:
-            func(*args, **kwargs)
+            repo=g_repo(path)
+            func(repo, *args, **kwargs)
         except AurumError:
             pass
         except vim.error:
     return r
 
 @outermethod
-def get_updates(path, oldtip=None):
-    repo=g_repo(path)
+def get_updates(repo, oldtip=None):
     tipcs=repo['tip']
     if oldtip is not None:
         try:
     vim.eval('extend(d, '+utf_dumps(d_vim)+')')
 
 @outermethod
-def get_cs(path, rev):
-    cs=g_cs(g_repo(path), rev)
+def get_cs(repo, rev):
+    cs=g_cs(repo, rev)
     cs_vim=set_rev_dict(cs, {'rev': cs.rev()})
     vim.eval('extend(cs, '+utf_dumps(cs_vim)+')')
 
 @outermethod
-def new_repo(path):
-    repo=g_repo(path)
+def new_repo(repo):
     # TODO remove bookmark label type if it is not available
     vim_repo={'has_octopus_merges': 0,
                    'requires_sort': 0,
     vim.eval('extend(repo, '+utf_dumps(vim_repo)+')')
 
 @outermethod
-def get_file(path, rev, filepath):
-    fctx=g_fctx(g_cs(g_repo(path), rev), filepath)
+def get_file(repo, rev, filepath):
+    fctx=g_fctx(g_cs(repo, rev), filepath)
     lines=[line.replace("\0", "\n") for line in fctx.data().split("\n")]
     vim.eval('extend(r, '+nonutf_dumps(lines)+')')
 
 @outermethod
-def annotate(path, rev, filepath):
-    ann=g_fctx(g_cs(g_repo(path), rev), filepath).annotate(follow=True,
-                                                           linenumber=True)
+def annotate(repo, rev, filepath):
+    ann=g_fctx(g_cs(repo, rev), filepath).annotate(follow=True, linenumber=True)
     ann_vim=[(line[0][0].path(), str(line[0][0].rev()), line[0][1])
                                                             for line in ann]
     vim.eval('extend(r, '+nonutf_dumps(ann_vim)+')')
     finally:
         os.chdir(workdir)
 
-def dodiff(ui, path, rev1, rev2, files, opts):
-    repo=g_repo(path)
+def dodiff(ui, repo, rev1, rev2, files, opts):
     if not hasattr(repo, '__getitem__'):
         vim_throw('diffuns', repo.path)
     args=[ui, repo]+files
                                             'copies': copies_vim})+')')
 
 @outermethod
-def get_cs_prop(path, rev, prop):
-    cs=g_cs(g_repo(path), rev)
+def get_cs_prop(repo, rev, prop):
+    cs=g_cs(repo, rev)
     if prop=='files' or prop=='removes' or prop=='changes':
         am=[]
         r=[]
     vim.eval('extend(a:cs, {"'+prop+'": '+nonutf_dumps(r)+'})')
 
 @outermethod
-def get_status(path, rev1=None, rev2=None, files=None, clean=None):
+def get_status(repo, rev1=None, rev2=None, files=None, clean=None):
     if rev1 is None and rev2 is None:
         rev1='.'
-    repo=g_repo(path)
     if hasattr(repo, 'status'):
         if not files:
             m=None
         vim_throw('statuns', repo.path)
 
 @outermethod
-def update(path, rev='tip', force=False):
-    repo=g_repo(path)
+def update(repo, rev='tip', force=False):
     if not hasattr(repo, '__getitem__'):
         vim_throw('upduns', repo.path)
     rev=g_cs(repo, rev).hex()
     run_in_dir(repo.root, commands.update, *args, **kwargs)
 
 @outermethod
-def dirty(path, filepath):
-    repo=g_repo(path)
+def dirty(repo, filepath):
     if not hasattr(repo, '__getitem__'):
         vim_throw('statuns', repo.path)
     dirty=repo[None].dirty()
         vim.command('let r=1')
 
 @outermethod
-def get_repo_prop(path, prop):
-    repo=g_repo(path)
+def get_repo_prop(repo, prop):
     r=None
     if prop=='tagslist':
         r=repo.tags().keys()
         vim.eval('extend(a:repo, {"'+prop+'": '+utf_dumps(r)+'})')
 
 @outermethod
-def call_cmd(path, attr, *args, **kwargs):
-    repo=g_repo(path)
+def call_cmd(repo, attr, *args, **kwargs):
     if 'force' in kwargs:
         kwargs['force']=bool(kwargs['force'])
     else:
                *cargs, **kwargs)
 
 @outermethod
-def grep(path, pattern, files, revisions=None, ignore_case=False, wdfiles=True):
-    repo=g_repo(path)
+def grep(repo, pattern, files, revisions=None, ignore_case=False, wdfiles=True):
     ui=CaptureUI()
     args=[ui, repo, pattern]
     args.extend(files)
     vim.eval('extend(r, '+nonutf_dumps(r_vim)+')')
 
 @outermethod
-def git_hash(path, rev):
-    repo=g_repo(path)
+def git_hash(repo, rev):
     hggitpath=None
     hggitname=None
     for hggitname in ['hggit', 'git']: