Commits

ZyX_I  committed 87ef533

@%aurum/drivers/mercurial: Added a* functions for non-python version of driver
(only agetrepoprop(, "branch") and astatus are supported)
@%aurum/drivers/git: Added a* functions (only agetrepoprop(, "branch") and
status(, 0, 0, [fname], 1, 1) are supported)

  • Participants
  • Parent commits 9d4d6f9

Comments (0)

Files changed (4)

File autoload/aurum/drivers/git.vim

             \ 'invrng': 'Range %s..%s is invalid for the repository %s, '.
             \           'as well as reverse',
             \    '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',
         \}
 let s:git={}
 let s:_options={
             let files[file]=1
             if status[0] is# 'R'
                 let r.added+=[file]
-                let r.removed+=[remove(s, 0)]
+                let old=remove(s, 0)
+                if (a:0>2 && !empty(a:3)) ? (index(a:3, old)!=-1) : 1
+                    let r.removed+=[old]
+                endif
             elseif status[0] is# 'C'
                 let r.added+=[file]
-                let origfile=remove(s, 0)
-                " FIXME What should be done with origfile?
+                call remove(s, 0)
             elseif status[0] is# 'D'
                 let r.removed+=[file]
             elseif status[1] is# 'D'
 endfunction
 let s:iterfuncs.changesets=s:iterfuncs.revrange
 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
+        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 pyeval('aurum.repeatedcmd.new('.string(a:interval).', '.
+                        \       'aurum.rcdriverfuncs.git_status, '.
+                        \       'vim.eval("a:repo.path"), '.
+                        \       'vim.eval("a:3[0]"))')
+        endfunction
+        function s:git.agetrepoprop(repo, interval, prop)
+            if a:prop isnot# 'branch'
+                call s:_f.throw('anbnimp')
+            endif
+            return pyeval('aurum.repeatedcmd.new('.string(a:interval).', '.
+                        \       'aurum.rcdriverfuncs.git_branch, '.
+                        \       'vim.eval("a:repo.path"))')
+        endfunction
+    endif
+endif
 "▶1 Register driver
 call s:_f.regdriver('Git', s:git)
 "▶1

File autoload/aurum/drivers/mercurial.vim

             \  'nocfg': 'No such property of repository %s: %s',
             \'failcfg': 'Failed to get property %s of repository %s',
             \'nlocbms': 'Bookmarks can’t be local',
+            \'anbnimp': 'Can only get branch property using agetrepoprop',
             \'parsefail': 'Failed to parse changeset information',
             \ 'filefail': 'Failed to get file %s '.
             \             'from the repository %s: %s',
             \'I': 'ignored',
             \'C': 'clean',
         \}
-" TODO test whether zero revision may cause bugs in some commands
-function s:hg.status(repo, ...)
+function s:F.statargs(...)
     let args=[]
     let kwargs={'modified': 1,
                 \  'added': 1,
             let args+=['--']+a:3
         endif
     endif
+    return [args, kwargs, reverse]
+endfunction
+" TODO test whether zero revision may cause bugs in some commands
+function s:hg.status(repo, ...)
+    let [args, kwargs, reverse]=call(s:F.statargs, a:000, {})
     let slines=s:F.hg(a:repo, 'status', args, kwargs, 0, 'stat')[:-2]
     if !empty(filter(copy(slines), '!has_key(s:statchars, v:val[0])'))
         call s:_f.throw('statfail', a:repo.path, join(slines, "\n"))
                         \                       'vim.eval("a:repo.path"), '.
                         \                       'vim.eval("a:prop"))')
         endfunction
+    else
+        try
+            python import aurum.rcdriverfuncs
+            let s:addafuncs=1
+        catch
+            let s:addafuncs=0
+        endtry
+        if s:addafuncs
+            function s:hg.astatus(repo, interval, ...)
+                let [args, kwargs, reverse]=call(s:F.statargs, a:000, {})
+                let arglist=s:_r.utils.kwargstolst(kwargs)+args
+                return pyeval('aurum.repeatedcmd.new('.string(a:interval).', '.
+                            \       'aurum.rcdriverfuncs.hg_status, '.
+                            \       'vim.eval("a:repo.path"), '.
+                            \       'vim.eval("arglist"), '.
+                            \        (reverse ? 'True' : 'False').')')
+            endfunction
+            function s:hg.agetrepoprop(repo, interval, prop)
+                if a:prop isnot# 'branch'
+                    call s:_f.throw('anbnimp')
+                endif
+                return pyeval('aurum.repeatedcmd.new('.string(a:interval).', '.
+                            \       'aurum.rcdriverfuncs.hg_branch, '.
+                            \       'vim.eval("a:repo.path"))')
+            endfunction
+        endif
     endif
 endif
 "▶1 hg.svnrev :: repo, rev → svnrev

File python/aurum/rcdriverfuncs.py

+from aurum.utils import readlines
+from copy import deepcopy
+
+statchars={
+    'M': 'modified',
+    'A': 'added',
+    'R': 'removed',
+    '!': 'deleted',
+    '?': 'unknown',
+    'I': 'ignored',
+    'C': 'clean',
+}
+emptystatdct={
+    'modified': [],
+    'added'   : [],
+    'removed' : [],
+    'deleted' : [],
+    'unknown' : [],
+    'ignored' : [],
+    'clean'   : [],
+}
+
+def hg_status(path, args, reverse=False):
+    r=deepcopy(emptystatdct)
+    for line in readlines(['hg']+args, cwd=path):
+        r[statchars[line[0]]].append(line[2:])
+    if reverse:
+        r['deleted'], r['unknown'] = r['unknown'], r['deleted']
+        r['added'],   r['removed'] = r['removed'], r['added']
+    return r
+
+def hg_branch(path):
+    return readlines(['hg', 'branch'], cwd=path).next()
+
+def git_status(path, fname):
+    r=deepcopy(emptystatdct)
+    try:
+        line=readlines(['git', 'status', '--porcelain', '--', fname],
+                       cwd=path).next()
+        status=line[:2]
+        if status[0] in 'RC':
+            r['added'].append(fname)
+        elif status[0] == 'D':
+            r['removed'].append(fname)
+        elif status[1] == 'D':
+            r['deleted'].append(fname)
+        elif status[0] == 'A':
+            r['added'].append(fname)
+        elif 'M' in status:
+            r['modified'].append(fname)
+        elif status == '??':
+            r['unknown'].append(fname)
+    except StopIteration:
+        try:
+            readlines(['git', 'ls-files', '--ignored', '--exclude-standard',
+                       '--others', '--', fname], cwd=path).next()
+            r['ignored'].append(fname)
+        except StopIteration:
+            try:
+                readlines(['git', 'ls-files', '--', fname], cwd=path).next()
+                r['clean'].append(fname)
+            except StopIteration:
+                pass
+    return r
+
+def git_branch(path):
+    for line in readlines(['git', 'branch', '-l'], cwd=path):
+        if line[0] == '*':
+            return line[2:]
+    return ''
+
+# vim: ft=python ts=4 sw=4 sts=4 et tw=100

File python/aurum/utils.py

     exit_code=p.poll()
     stderr.write(p.stderr.read())
     return lines, exit_code
+
+def readlines(cmd, cwd=None):
+    p=Popen(cmd, shell=False, stdout=PIPE, stderr=None, cwd=cwd)
+    for line in p.stdout:
+        yield line[:-1]
+
 # vim: ft=python ts=4 sw=4 sts=4 et tw=100