Commits

ZyX_I committed 56446da

Started working on aurum://diff

Comments (0)

Files changed (1)

 endfunction
 "▶3 auefunc
 let s:bufvars={}
-"▶4 comm.reporevfilesplit :: str → (repo, rev, file)
-function s:F.comm.reporevfilesplit(str)
+"▶4 comm.repotuplesplit :: str → (repo, String, ...)
+function s:F.comm.repotuplesplit(str, num)
     let file=a:str
     let repopath=matchstr(file, '\v^(\\.|[^\\:]+)')
     let file=file[len(repopath)+1:]
     let repo=s:F.comm.getrepo(substitute(repopath,'\v\\([\\:])','\1','g'))
-    let rev=matchstr(file, '\v^(\\.|[^\\:])+')
-    let file=file[len(rev)+1:]
-    let rev=substitute(rev, '\v\\([\\:])', '\1', 'g')
-    return [repo, rev, file]
+    let r=[repo]
+    let i=0
+    while i<a:num-1
+        let chunk=matchstr(file, '\v^(\\.|[^\\:])+')
+        let file=file[len(chunk)+1:]
+        call add(r, chunk)
+        let i+=1
+    endwhile
+    call add(r, file)
+    return r
 endfunction
 "▲4
 function s:auefunc.function()
-    let file=substitute(expand('<amatch>'), '\V\^aurum://', '', '')
-    let command=matchstr(file, '\v^\w+')
-    let file=file[len(command)+1:]
+    let tail=substitute(expand('<amatch>'), '\V\^aurum://', '', '')
+    let command=matchstr(tail, '\v^\w+')
+    let tail=tail[len(command)+1:]
     if command is# 'glog'
-        let repo=s:F.comm.getrepo(file)
+        let repo=s:F.comm.getrepo(tail)
         let s:bufvars[bufnr('%')]={'repo': repo}
         setlocal buftype=nofile filetype=aurumgraphlog bufhidden=wipe
     elseif command is# 'file'
-        let [repo, rev, file]=s:F.comm.reporevfilesplit(file)
+        let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
         setlocal buftype=nofile
         call setline('.', repo.functions.readfile(repo, rev, file))
     elseif command is# 'annotate'
-        let [repo, rev, file]=s:F.comm.reporevfilesplit(file)
+        let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
         let s:bufvars[bufnr('%')]={'repo': repo, 'rev': rev, 'file': file}
         setlocal buftype=nofile filetype=aurumannotate bufhidden=wipe
+    elseif command is# 'diff'
+        let [repo, rev1, rev2, files]=s:F.comm.repotuplesplit(tail, 3)
+        if empty(rev1) && empty(rev2)
+            let rev2=repo.work_hex
+        endif
+        if !empty(rev1)
+            let rev1=repo.functions.gethex(repo, rev1)
+            let csfiles=repo.changesets[rev1].files
+        endif
+        if !empty(rev2)
+            let rev2=repo.functions.gethex(repo, rev2)
+            let csfiles=repo.changesets[rev2].files
+        endif
+        if !empty(rev1) && !empty(rev2)
+            let cs1files=repo.changesets[rev1].files
+            let cs2files=repo.changesets[rev2].files
+            let csfiles=filter(cs1files, 'index(cs2files, v:val)!=-1')
+        endif
+        let filelist=[]
+        for glob in split(files, '\v%(\\@<!\\%(\\\\)*)@<!,')
+            let pattern='\V\^'.substitute(substitute(substitute(substitute(
+                        \substitute(substitute(substitute(glob,
+                        \'\v\\(.)', '\="\\{".char2nr(submatch(1))."}"', 'g'),
+                        \'\V**',    '\.\*',    'g'),
+                        \'\V*',     '\[^/]\*', 'g'),
+                        \'\V?',     '\.',      'g'),
+                        \'\V[',     '\\[',     'g'),
+                        \'\V\\{'.char2nr('\').'}', '\\\\', 'g'),
+                        \'\V\\{\(\d\+\)}', '\=nr2char(submatch(1))', 'g').'\$'
+            let filelist+=filter(csfiles, 'v:val=~#pattern && '.
+                        \                 'index(filelist, v:val)==-1')
+        endfor
+        echom string(filelist)
+        let s:bufvars[bufnr('%')]={'repo': repo, 'rev1': rev1, 'rev2': rev2,
+                    \             'files': filelist,}
     endif
 endfunction
 "▶3 aubwfunc