Source

aurum / autoload / aurum / drivers / git.vim

Diff from to

autoload/aurum/drivers/git.vim

             \                   '@%aurum/drivers/common/utils': '1.1',
             \                                           '@/os': '0.1',
             \                                      '@/options': '0.0',})
+let s:usepythondriver=0
+if has('python')
+    let s:py='python'
+    let s:pp='aurum.augit'
+    let s:pya=s:py.' '.s:pp.'.'
+    try
+        execute s:py 'import '.s:pp
+        let s:usepythondriver=1
+    catch
+        " s:usepythondriver stays equal to 0, errors are ignored
+    endtry
+    if s:usepythondriver
+        " FIXME Does not work in python3.
+        execute s:py 'reload('.s:pp.')'
+    endif
+endif
 let s:_messages={
             \   'hexf': 'Failed to obtain hex string for revision %s '.
             \           'in the repository %s: %s',
             \    'ppf': 'Failed to run “git %s” for the repository %s: %s',
             \'anbnimp': 'Can only get branch property using agetrepoprop',
             \'aconimp': 'Can only get current status for one file',
+            \'as2nimp': 'Can only get current status',
         \}
 let s:git={}
 let s:_options={
 let s:iterfuncs.ancestors=s:iterfuncs.revrange
 "▶1 astatus, agetcs, agetrepoprop
 if s:_r.repo.userepeatedcmd
-    try
-        python import aurum.rcdriverfuncs
-        let s:addafuncs=1
-    catch
-        let s:addafuncs=0
-    endtry
-    if s:addafuncs
+    if s:usepythondriver
         function s:git.astatus(repo, interval, ...)
-            if a:0<3 || a:1 isnot 0 || a:2 isnot 0 ||
-                        \type(a:3)!=type([]) || len(a:3)!=1
-                call s:_f.throw('aconimp')
+            if a:0<3 || a:1 isnot 0 || a:2 isnot 0
+                call s:_f.throw('as2nimp')
             endif
             return s:_r.utils.pyeval('aurum.repeatedcmd.new('.
                         \        string(a:interval).', '.
-                        \       'aurum.rcdriverfuncs.git_status, '.
+                        \        s:pp.'._get_status, '.
                         \        s:_r.utils.pystring(a:repo.path).', '.
-                        \        s:_r.utils.pystring(a:3[0]).')')
+                        \        s:_r.utils.pystring(a:3).', True, True)')
         endfunction
         function s:git.agetrepoprop(repo, interval, prop)
-            if a:prop isnot# 'branch'
-                call s:_f.throw('anbnimp')
-            endif
             return s:_r.utils.pyeval('aurum.repeatedcmd.new('.
                         \        string(a:interval).', '.
-                        \       'aurum.rcdriverfuncs.git_branch, '.
-                        \        s:_r.utils.pystring(a:repo.path).')')
+                        \       'aurum.auutils.get_one_prop, '.
+                        \        s:pp.'._get_repo_prop, '.
+                        \        s:_r.utils.pystring(a:repo.path).', '.
+                        \        string(a:prop).')')
         endfunction
+    else
+        try
+            python import aurum.rcdriverfuncs
+            let s:addafuncs=1
+        catch
+            let s:addafuncs=0
+        endtry
+        if s:addafuncs
+            function s:git.astatus(repo, interval, ...)
+                if a:0<3 || a:1 isnot 0 || a:2 isnot 0 ||
+                            \type(a:3)!=type([]) || len(a:3)!=1
+                    call s:_f.throw('aconimp')
+                endif
+                return s:_r.utils.pyeval('aurum.repeatedcmd.new('.
+                            \        string(a:interval).', '.
+                            \       'aurum.rcdriverfuncs.git_status, '.
+                            \        s:_r.utils.pystring(a:repo.path).', '.
+                            \        s:_r.utils.pystring(a:3[0]).')')
+            endfunction
+            function s:git.agetrepoprop(repo, interval, prop)
+                if a:prop isnot# 'branch'
+                    call s:_f.throw('anbnimp')
+                endif
+                return s:_r.utils.pyeval('aurum.repeatedcmd.new('.
+                            \        string(a:interval).', '.
+                            \       'aurum.rcdriverfuncs.git_branch, '.
+                            \        s:_r.utils.pystring(a:repo.path).')')
+            endfunction
+        endif
     endif
 endif
 "▶1 Register driver