Commits

ZyX_I committed 681042d

@aurum/drivers/mercurial: Added git sha1 support to repo.hypsites

  • Participants
  • Parent commits 9b0ec2f

Comments (0)

Files changed (3)

File doc/aurum.txt

     results.
 *aurum-rf-svnrev* exists and produces svn revision number out of repository 
     object and mercurial revision specification.
+*aurum-rf-githex* exists and produces git sha1 out of repository object and 
+    mercurial revision specification. This function is present only when using 
+    python version of driver.
 Python driver was not tested under windows (wine) at all.
 
 ------------------------------------------------------------------------------

File plugin/aurum/drivers/mercurial.vim

             \ 'stat1mis': 'You must specify first revision as well',
             \ 'nosvnrev': 'Failed to find revision in “hg svn info” output '.
             \             'in the repository %s. Output:%s',
+            \ 'nohggitc': 'It appears that hg-git is not enabled '.
+            \             '(tried options extensions.hggit and '.
+            \              'extensions.hg-git)',
+            \  'nohggit': 'It appears that hg-git is not installed '.
+            \             '(importing GitHandler threw ImportError)',
         \}
 let s:nullrev=repeat('0', 40)
 let s:_options={
 let s:hypsites=[]
 let s:bookmarks='repo.functions.getcsprop(repo, hex, "bookmarks")'
 let s:tags='repo.functions.getcsprop(repo, hex, "tags")'
-let s:gitrev='((!empty('.s:bookmarks.'))?'.
-            \      '('.s:bookmarks.'[0]):'.
-            \   '((!empty('.s:tags.'))?'.
-            \      '(matchstr(get(filter(copy('.s:tags.'), "stridx(v:val, ''/'')!=-1"), 0, '.
-            \           '"master"), "\\v[^/]+$"))'.
-            \   ':'.
-            \      '("master")))'
+if s:usepythondriver
+    let s:gitrev='repo.functions.githex(repo, hex)'
+else
+    let s:gitrev='((!empty('.s:bookmarks.'))?'.
+                \      '('.s:bookmarks.'[0]):'.
+                \   '((!empty('.s:tags.'))?'.
+                \      '(matchstr(get(filter(copy('.s:tags.'), '.
+                \                           '"stridx(v:val, ''/'')!=-1"), 0, '.
+                \           '"master"), "\\v[^/]+$"))'.
+                \   ':'.
+                \      '("master")))'
+endif
 unlet s:bookmarks s:tags
 let s:hypsites+=map(copy(s:_r.hypsites.git), '["protocol[:2] is# ''git'' && (".v:val[0].")", '.
             \                                 'map(copy(v:val[1]), '.
     endfor
     call s:_f.throw('nosvnrev', a:repo.path, "\n".join(lines, "\n"))
 endfunction
+"▶1 hg.gitrev :: repo, rev → githex
+if s:usepythondriver
+function s:hg.githex(repo, rev)
+    execute s:_r.py.cmd 'aurum.git_hash(vim.eval("a:repo.path"), '.
+                \                      'vim.eval("a:rev"))'
+endfunction
+endif
 "▶1 Register driver
 call s:_f.regdriver('Mercurial', s:hg)
 "▶1

File python/aurum.py

     except AurumError:
         pass
 
+def git_hash(path, rev):
+    try:
+        repo=g_repo(path)
+        hggitpath=None
+        for hggitname in ['hggit', 'hg-git']:
+            hggitpath=repo.ui.config('extensions', hggitname)
+            if hggitpath is not None:
+                break
+        if hggitpath is None:
+            vim_throw('nohggitc')
+        import sys
+        sys.path.append(hggitpath)
+        try:
+            try:
+                from hggit.git_handler import GitHandler
+            except ImportError:
+                vim_throw('nohggit')
+            git=GitHandler(repo, repo.ui)
+            r=git.map_git_get(g_cs(repo, rev).hex())
+            vim.command('return '+json.dumps(r))
+        finally:
+            sys.path.pop()
+    except AurumError:
+        pass