ZyX_I avatar ZyX_I committed 39c9dc8

@%aurum/drivers/git: Made rf-status also use pygit2 if available
Fixed order of checks in aurum.augit.get_status
Made it sort files as well
Fixed addition of clean files in case files were not specified
Added support for repo.revparse (!!! untested, nobody knows whether it works because I have release versions of pygit2 and libgit2)
Ref #81

Comments (0)

Files changed (3)

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',
             \'as2nimp': 'Can only get current status',
+            \
+            \ 'norepo': 'Repository %s not found',
+            \  'norev': 'Revision %s not found in repository %s',
+            \'uresrev': 'Don’t know how to resolve %s into a commit object. '.
+            \           'Occured when resolving %s in the repository %s',
+            \ 'nohead': 'Failed to obtain HEAD revision in the repository %s',
         \}
 let s:git={}
 let s:_options={
     let a:cs[a:prop]=r
     return r
 endfunction
-"▶1 git.status :: repo[, rev1[, rev2[, files[, clean]]]]
+"▶1 get_status :: repo, files, clean, ignored -> status
+if s:usepythondriver "▶2
+    function s:F.get_status(repo, files, clean, ignored)
+        let d={}
+        try
+            execute s:pya.'get_status(vim.eval("a:repo.path"), '.
+                        \             (empty(a:files)?
+                        \                'None':
+                        \                'vim.eval("a:files")').', '.
+                        \             (a:clean   ? 'True' : 'False').', '.
+                        \             (a:ignored ? 'True' : 'False').', '.
+                        \           ')'
+        endtry
+        return d
+    endfunction
+else "▶2
+    function s:F.get_status(repo, files, clean, ignored)
+        let r=deepcopy(s:_r.utils.emptystatdct)
+        let kwargs={'porcelain': 1, 'z': 1}
+        let args=empty(a:files)?[]:['--']+a:files
+        let s=s:_r.utils.nullnl(
+                    \s:F.git(a:repo, 'status', args, kwargs, 2, 'statusf'))[:-2]
+        let files={}
+        while !empty(s)
+            let line=remove(s, 0)
+            let status=line[:1]
+            let file=line[3:]
+            if has_key(files, file)
+                continue
+            endif
+            let files[file]=1
+            if status[0] is# 'R'
+                let r.added+=[file]
+                let old=remove(s, 0)
+                if (empty(a:files)) ? 1 : (index(a:files, old)!=-1)
+                    let r.removed+=[old]
+                endif
+            elseif status[0] is# 'C'
+                let r.added+=[file]
+                call remove(s, 0)
+            elseif status[0] is# 'D'
+                let r.removed+=[file]
+            elseif status[1] is# 'D'
+                let r.deleted+=[file]
+            elseif status[0] is# 'A'
+                let r.added+=[file]
+            elseif stridx(status, 'M')!=-1
+                let r.modified+=[file]
+            elseif status is# '??'
+                let r.unknown+=[file]
+            endif
+        endwhile
+        if a:clean
+            let allfiles=copy(a:repo.functions.getcsprop(a:repo,
+                        \                                'HEAD', 'allfiles'))
+            if !empty(a:files)
+                call filter(allfiles, 'index(a:files, v:val)!=-1')
+            endif
+            let r.clean=filter(allfiles, '!has_key(files, v:val)')
+        endif
+        if a:ignored
+            let r.ignored=s:_r.utils.nullnl(
+                        \ s:F.git(a:repo, 'ls-files', args,
+                        \                 {'ignored': 1, 'z': 1,
+                        \                  'exclude-standard': 1,
+                        \                  'others': 1}, 2,
+                        \                 'lsignf', a:repo))[:-2]
+        endif
+        return r
+    endfunction
+endif
+"▶1 git.status :: repo[, rev1[, rev2[, files[, clean[, ignored]]]]]
 let s:statchars={
             \'A': 'added',
             \'M': 'modified',
             \'D': 'removed',
         \}
 function s:git.status(repo, ...)
-    let r=deepcopy(s:_r.utils.emptystatdct)
     let requiresclean=(a:0>3 && a:4)
-    let args=((a:0>2 && !empty(a:3))?(['--']+a:3):([]))
     if a:0 && (a:1 isnot 0 || (a:0>1 && a:2 isnot 0))
+        let r=deepcopy(s:_r.utils.emptystatdct)
+        let args=((a:0>2 && !empty(a:3))?(['--']+a:3):([]))
         let rspec=[]
         let reverse=0
         if a:1 is 0
         endif
         if requiresclean
             let allfiles=a:repo.functions.getcsprop(a:repo,rspec[0],'allfiles')
+            if a:0>2 && !empty(a:3)
+                let allfiles=filter(copy(allfiles), 'index(a:3, v:val)!=-1')
+            endif
+            let r.clean=filter(copy(allfiles), '!has_key(files, v:val)')
         endif
     else
-        let kwargs={'porcelain': 1, 'z': 1}
-        let s=s:_r.utils.nullnl(
-                    \s:F.git(a:repo, 'status', args, kwargs, 2, 'statusf'))[:-2]
-        let files={}
-        while !empty(s)
-            let line=remove(s, 0)
-            let status=line[:1]
-            let file=line[3:]
-            let files[file]=1
-            if status[0] is# 'R'
-                let r.added+=[file]
-                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]
-                call remove(s, 0)
-            elseif status[0] is# 'D'
-                let r.removed+=[file]
-            elseif status[1] is# 'D'
-                let r.deleted+=[file]
-            elseif status[0] is# 'A'
-                let r.added+=[file]
-            elseif stridx(status, 'M')!=-1
-                let r.modified+=[file]
-            elseif status is# '??'
-                let r.unknown+=[file]
-            endif
-        endwhile
-        if requiresclean
-            let allfiles=a:repo.functions.getcsprop(a:repo, 'HEAD', 'allfiles')
-        endif
-        if a:0>4 && a:5
-            let r.ignored=s:_r.utils.nullnl(
-                        \ s:F.git(a:repo, 'ls-files', args,
-                        \                 {'ignored': 1, 'z': 1,
-                        \                  'exclude-standard': 1,
-                        \                  'others': 1}, 2,
-                        \                 'lsignf', a:repo))[:-2]
-        endif
-    endif
-    if exists('allfiles')
-        if a:0>2 && !empty(a:3)
-            let allfiles=filter(copy(allfiles), 'index(a:3, v:val)!=-1')
-        endif
-        let r.clean=filter(copy(allfiles), '!has_key(files, v:val)')
+        return s:F.get_status(a:repo, (a:0>2 ? a:3 : 0), requiresclean,
+                    \         (a:0>4 && a:5))
     endif
     return r
 endfunction

python/aurum/augit.py

 outermethod      = outermethodgen(g_repo, flush)
 autoexportmethod = autoexportmethodgen(g_repo, globals())
 
-# XXX Does not support references like HEAD^. Must be used after getrevhex using normal git was run.
-# FIXME libgit2 does support HEAD^, make pygit2 and this code use this support
 def g_cs(repo, rev):
-    try:
-        ref = repo.lookup_reference(rev)
-        r = repo[ref.resolve().oid]
-    except KeyError:
+    if hasattr(repo, 'revparse_single'):
         try:
-            r = repo[unicode(rev, 'utf-8')]
+            # TODO Check this. Currently it works only in development branch
+            r = repo.revparse_single(rev)
+        except Exception: # FIXME be more specific
+            vim_throw('norev', rev, repo.path)
+    else:
+        try:
+            ref = repo.lookup_reference(rev)
+            r = repo[ref.resolve().oid]
         except KeyError:
-            vim_throw('norev', rev, repo.path)
+            try:
+                r = repo[unicode(rev, 'utf-8')]
+            except KeyError:
+                vim_throw('norev', rev, repo.path)
 
     while not isinstance(r, git.Commit):
         if isinstance(r, git.Tag):
         status = repo.status()
         statuses = status.iteritems()
         if clean:
-            r['clean'] = [fname for fname in list_tree_files(g_cs('HEAD').tree)
+            r['clean'] = [fname for fname in list_tree_files(g_cs(repo, 'HEAD').tree)
                           if fname not in status]
     while True:
         try:
             continue
         if status == git.GIT_STATUS_CURRENT:
             r['clean'].append(fname)
-        elif status & (git.GIT_STATUS_INDEX_MODIFIED | git.GIT_STATUS_WT_MODIFIED):
-            r['modified'].append(fname)
-        elif status & git.GIT_STATUS_IGNORED:
-            r['ignored'].append(fname)
         elif status & git.GIT_STATUS_INDEX_DELETED:
             r['removed'].append(fname)
         elif status & git.GIT_STATUS_WT_DELETED:
             r['added'].append(fname)
         elif status & git.GIT_STATUS_WT_NEW:
             r['unknown'].append(fname)
+        elif status & (git.GIT_STATUS_INDEX_MODIFIED | git.GIT_STATUS_WT_MODIFIED):
+            r['modified'].append(fname)
+        elif status & git.GIT_STATUS_IGNORED:
+            r['ignored'].append(fname)
+    for v in r.itervalues():
+        v.sort()
     return r
 
 def set_rev_dict(cs, cs_vim):

Binary file modified.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.