Commits

ZyX_I committed e893997

@aurum/drivers/git: Added rf-grep(), rf-revrange(), rf-updatechangesets()
@aurum: Made it use rf-revrange()

Comments (0)

Files changed (3)

 |aurum-cs.tags|:
     Contains list of all references pointing to given commit, not just tags.
 |aurum-cs.rev| contains truncated hash (for use in |aurum://annotate|).
+|aurum-repo.cslist| is always empty
 |aurum-rf-status|:
     If two first optional arguments are given and are non-zero, then unknown 
     and deleted files won’t be shown (if any).
     merge_cs.changes only if git was unable to merge changes and had to ask 
     user to do this).
 |aurum-rf-getchangesets| is always returning empty list.
+|aurum-rf-grep|
+    Will either search working directory (if no revisions were given) or given 
+    revisions (mercurial driver is searching all revisions if no revisions are 
+    given). Unlike mercurial where matching line will be shown only if they 
+    were found in first revision in range or in line that was added/modified 
+    in given revision, with this function you will see all matches in all 
+    revisions (really it is calling “git grep” multiple times).
+|aurum-rf-annotate|
+    Won’t output annotation of file in working directory, it is always 
+    returning annotation of file at given revision.
 
 ==============================================================================
 11. Changelog                                                *aurum-changelog*
             endif
         else
             let css=[]
-            for r in revisions
-                if type(r)==type([])
-                    let css+=map(call('range', r),
-                                \'repo.functions.getcs(repo, v:val)')
+            for s in revisions
+                if type(s)==type([])
+                    let css+=repo.functions.revrange(a:repo, s[0], s[1])
                 else
-                    let css+=[repo.functions.getcs(repo, r)]
+                    let css+=[repo.functions.getcs(repo, s)]
                 endif
-                unlet r
+                unlet s
             endfor
         endif
         let allfiless=map(copy(css), 'repo.functions.getcsprop(repo, v:val,'.

plugin/aurum/drivers/git.vim

             \   'hexf': 'Failed to obtain hex string for revision %s '.
             \           'in the repository %s: %s',
             \   'logf': 'Failed to list all revisions in the repository %s: %s',
+            \  'rlogf': 'Failed to list revisions %s..%s '.
+            \           'in the repository %s: %s',
             \    'csf': 'Failed to obtain information about revision %s '.
             \           'in the repository %s: %s',
             \   'updf': 'Failed to checkout commit %s in the repository %s: %s',
             \           'in the repository %s: %s',
             \'branchf': 'Failed to get list of branches '.
             \           'from the repository %s: %s',
+            \  'grepf': 'Failed to search through the repository %s: %s',
             \   'tagf': 'Failed to get list of tags from the repository %s: %s',
             \ 'cbnimp': 'Git driver is not able to close branch',
             \   'nloc': 'Git driver does not suppport local tags or branches',
             \   'chbf': 'Failed to create branch %s in the repository %s: %s',
             \  'nocfg': 'Failed to get property %s of repository %s',
+            \ 'invrng': 'Range %s..%s is invalid for the repository %s, '.
+            \           'as well as reverse',
         \}
 let s:git={}
 "▶1 s:hypsites
     let cs.user=aname.' <'.aemail.'>'
     let cs.tags=split(a:csdata[line][2:-2], ', ')          | let line+=1
     let cs.bookmarks=[]
-    let cs.rev=cs.hex[:6]
+    let cs.rev=cs.hex[:5]
     "▶2 get description
     let description=[]
     while a:csdata[line][0] is# ' '
     return [cs, line]
 endfunction
 "▶1 git.getchangesets :: repo → []
-function s:git.getchangesets(repo)
-    let log=s:F.git(a:repo, 'log', [], extend({'all': 1, 'full-history': 1},
-                \                             s:logkwargs), 0, 'logf')[:-2]
+function s:git.getchangesets(repo, ...)
+    "▶2 Prepare s:F.git arguments
+    let args=[]
+    if a:0
+        let args+=[a:1.'..'.a:2]
+    endif
+    let gitargs=[a:repo, 'log', args, extend({'all': 1, 'full-history': 1},
+                \                            s:logkwargs), 0]
+    if a:0
+        let gitargs+=['rlogf', a:1, a:2]
+    else
+        let gitargs+=['logf']
+    endif
+    "▲2
+    let log=call(s:F.git, gitargs, {})[:-2]
+    "▶2 If log has shown nothing, try reversing range
+    if a:0 && empty(log)
+        let args[0]=a:2.'..'.a:1
+        let gitargs[-1]=a:1
+        let gitargs[-2]=a:2
+        let log=call(s:F.git, gitargs, {})[:-2]
+        if empty(log)
+            call s:_f.throw('invrng', a:1, a:2, a:repo.path)
+        endif
+    endif
+    "▶2 Parse changeset information
     let i=0
     let llog=len(log)
+    let cslist=[]
     while i<llog
         let [cs, i]=s:F.parsecs(log, i)
         let a:repo.changesets[cs.hex]=extend(get(a:repo.changesets, cs.hex, {}),
                     \                        cs)
+        let cslist+=[cs]
     endwhile
-    return []
+    "▲2
+    return cslist
 endfunction
+"▶1 git.updatechangesets :: repo → _
+let s:git.updatechangesets=s:git.getchangesets
+"▶1 git.revrange :: repo, rev1, rev2 → [cs]
+let s:git.revrange=s:git.getchangesets
 "▶1 git.getcs :: repo, rev → cs
 function s:git.getcs(repo, rev)
     let cs=s:F.parsecs(s:F.git(a:repo, 'log', [a:rev.'^..'.a:rev], s:logkwargs,
     return s:F.gitm(a:repo, a:type, args, kwargs, 0,
                 \   'lbf', a:type, a:label, a:rev)
 endfunction
+"▶1 git.grep :: repo, files, revisions, ignorecase, wdfiles::Bool → qflist
+function s:F.parsegrep(lines)
+    return map(a:lines, 'split(v:val, "\n", 1)')
+endfunction
+function s:git.grep(repo, pattern, files, revisions, ic, wdfiles)
+    let args=['-e', a:pattern, '--']+a:files
+    let kwargs={'full-name': 1, 'extended-regexp': 1, 'n': 1, 'z': 1}
+    let gitargs=[a:repo, 'grep', args, kwargs, 1, 0]
+    let r=[]
+    if !empty(a:revisions)
+        let revs=[]
+        for s in a:revisions
+            if type(s)==type([])
+                let revs+=map(copy(a:repo.functions.revrange(a:repo,s[0],s[1])),
+                            \ 'v:val.hex')
+            else
+                let revs+=[a:repo.functions.getrevhex(a:repo, s)]
+            endif
+            unlet s
+        endfor
+        call extend(args, revs, 2)
+        for [revfile, lnum, text] in s:F.parsegrep(call(s:F.git, gitargs, {}))
+            let cidx=stridx(revfile, ':')
+            let rev=revfile[:(cidx-1)]
+            let file=revfile[(cidx+1):]
+            let r+=[{'filename': [rev, file], 'lnum': lnum, 'text': text}]
+        endfor
+    else
+        for [file, lnum, text] in s:F.parsegrep(call(s:F.git, gitargs, {}))
+            let r+=[{'filename': file, 'lnum': lnum, 'text': text}]
+        endfor
+    endif
+    return r
+endfunction
 "▶1 git.getrepoprop :: repo, propname → a
 function s:git.getrepoprop(repo, prop)
     if a:prop is# 'url'