Source

aurum / autoload / aurum / drivers / bazaar.vim

Diff from to

File autoload/aurum/drivers/bazaar.vim

 "▶1
 scriptencoding utf-8
+let s:pp='aurum.aubazaar'
 execute frawor#Setup('0.0', {'@%aurum/drivers/common/hypsites': '0.0',
             \                                   '@%aurum/repo': '5.0',
-            \                   '@%aurum/drivers/common/utils': '1.1',
+            \                   '@%aurum/drivers/common/utils': '1.2',
             \                                           '@/os': '0.1',
             \                                      '@/options': '0.0',})
 let s:_messages={
     let indent=stridx(remove(a:csdata, 0), '-')
     " FIXME children:[]
     let cs={'parents': [], 'copies': {}, 'children': [], 'phase': 'unknown',
-                \'bookmarks': [], 'tags': []}
+                \'bookmarks': [], 'tags': [], 'branch': 'default'}
     while !empty(a:csdata) && a:csdata[0]!~#'\v^\s*\-{60}$'
         let line=remove(a:csdata, 0)[(indent):]
         if line is# 'message:'
 function s:bzr.gettiphex(repo)
     return a:repo.functions.getrevhex(a:repo, '-1')
 endfunction
-"▶1 getstatdict :: repo, kwargs → statdict
+"▶1 getstatdict :: repo, args, kwargs → statdict
+let s:emptystatdict=extend({'renamed': []}, deepcopy(s:_r.utils.emptystatdct))
 function s:F.getstatdict(repo, args, kwargs)
-    let status=s:F.bzr(a:repo, 'status', a:args,
-                \      extend({'no-classify': 1, 'no-pending': 1}, a:kwargs),
+    let lines=s:F.bzr(a:repo, 'status', a:args,
+                \      extend({'no-classify': 1, 'no-pending': 1, 'short': 1},
+                \             a:kwargs),
                 \      0)[:-2]
     let curstatus=0
-    let statdict={}
-    while !empty(status)
-        let line=remove(status, 0)
-        if line[:1] is# '  '
-            " XXX File name is not expected to contain " => "
-            let statdict[curstatus]+=[line[2:]]
-        elseif line =~# '\v^[a-z]+%(\ [a-z]+)*\:$'
-            let curstatus=line[:-2]
-            let statdict[curstatus]=[]
-        elseif !empty(get(statdict, curstatus, 0))
-            " XXX Support for file with newlines is very limited here: it 
-            "     does not expect them containing "\n  " or "\nabc:". Bazaar 
-            "     crashes when trying to commit file with newline in its 
-            "     name, though it is probably not a problem
-            let statdict[curstatus][-1].="\n".line
+    let statdict=deepcopy(s:emptystatdict)
+    while !empty(lines)
+        let line=remove(lines, 0)
+        let status=line[:2]
+        if (status!~#'^[ +\-?RIXCP][ KNMD!][ *]$' || line[3] isnot# ' ')
+                    \&& curstatus isnot 0
+            let statdict[curstatus][-1].=line
+        endif
+        let file=line[4:]
+        if status[0] is# 'R'
+            let statdict.renamed+=[file]
+            let curstatus='renamed'
+        elseif status[0] is# ' '
+            if status[1] is# 'N'
+                let statdict.added    += [file]
+                let curstatus='added'
+            elseif stridx('D!', status[1])!=-1
+                let statdict.deleted  += [file]
+                let curstatus='deleted'
+            elseif status[2] is# '*' || stridx('KM', status[1])!=-1
+                let statdict.modified += [file]
+                let curstatus='modified'
+            else
+                let statdict.clean    += [file]
+                let curstatus='clean'
+            endif
+        elseif status[0] is# '-'
+            let statdict.removed+=[file]
+            let curstatus='removed'
+        elseif status[0] is# '+'
+            if status[1] is# '!'
+                let statdict.deleted  += [file]
+                let curstatus='deleted'
+            else
+                let statdict.added    += [file]
+                let curstatus='added'
+            endif
+        elseif status[0] is# '?'
+            let statdict.unknown+=[file]
+            let curstatus='unknown'
+        elseif status[0] is# 'I'
+            let statdict.ignored+=[file]
+            let curstatus='ignored'
+        " elseif status[0] is# 'X'
+            " Nonexistent file
         endif
     endwhile
     return statdict
     elseif       a:prop is# 'renames' || a:prop is# 'changes' ||
                 \a:prop is# 'files'   || a:prop is# 'removes'
         let statdict=s:F.getstatdict(a:repo, [], {'change': 'revid:'.a:cs.hex})
-        let a:cs.removes=[]
-        let a:cs.files=[]
-        call map(['added', 'modified', 'kind changed'],
-                    \'extend(a:cs.files, get(statdict, v:val, []))')
-        if has_key(statdict, 'removed')
-            let a:cs.removes+=statdict.removed
-        endif
-        let a:cs.renames=s:F.getrenames(statdict)
-        let a:cs.removes+=sort(values(a:cs.renames))
-        let a:cs.files  +=sort(keys(  a:cs.renames))
-        let a:cs.changes=a:cs.removes+a:cs.files
+        let a:cs.removes  = copy(statdict.removed)
+        let a:cs.files    = statdict.added+statdict.modified
+        let a:cs.renames  = s:F.getrenames(statdict)
+        let a:cs.removes += sort(values(a:cs.renames))
+        let a:cs.files   += sort(keys(  a:cs.renames))
+        let a:cs.changes  = a:cs.removes+a:cs.files
         return a:cs[a:prop]
     endif
     let a:cs[a:prop]=r
     return r
 endfunction
 "▶1 bzr.status :: repo[, rev1[, rev2[, files[, clean[, ign]]]]] → {type:[file]}
-let s:statstats={'added': 'added', 'removed': 'removed', 'modified': 'modified',
-            \    'kind changed': 'modified', 'unknown': 'unknown',
-            \    'missing': 'deleted', 'ignored': 'ignored',
-            \    'nonexistent': 'unknown', 'conflicts': 'modified',}
+if s:usepythondriver "▶2
+let s:revargsexpr='v:val is 0? '.
+                \       '"None":'.
+                \ 'v:key>=3?'.
+                \       '(empty(v:val)?"False":"True"):'.
+                \       '"vim.eval(''a:".(v:key+1)."'')"'
+function s:bzr.status(repo, ...)
+    let revargs=join(map(copy(a:000), s:revargsexpr), ',')
+    let d={}
+    try
+        execute s:pya.'get_status(vim.eval("a:repo.path"), '.revargs.')'
+    endtry
+    return d
+endfunction
+else "▶2
 function s:bzr.status(repo, ...)
     let args=['--']+((a:0>2 && a:3 isnot 0)?(a:3):([]))
     let statdict=s:F.getstatdict(a:repo, args,
                 \                ((a:0>1 && a:2 isnot 0)?
                 \                   ({'revision': a:2.'..'}):
                 \                   ({})))))
-    let r=deepcopy(s:_r.utils.emptystatdct)
-    " XXX There cannot be deleted files similar to mercurial, but there can be 
-    "     files that have 2 statuses
-    "     (missing is a bit different: it is shown after deleting added file)
-    for [sdkey, skey] in items(filter(copy(s:statstats),
-                \                     'has_key(statdict, v:key)'))
-        let r[skey]+=statdict[sdkey]
-    endfor
+    let r=deepcopy(statdict)
     let renames=s:F.getrenames(statdict)
+    call remove(r, 'renamed')
     call filter(r.modified, '!has_key(renames, v:val)')
     if a:0>2 && !empty(a:3)
         let r.added   += sort(filter(keys(renames),   'index(a:3, v:val)!=-1'))
     endif
     return r
 endfunction
+endif
 "▶1 bzr.commit :: repo, message[, files[, user[, date[, _]]]]
 function s:bzr.commit(repo, message, ...)
     let kwargs={}