Commits

ZyX_I committed 0d6b5ee

Added repo.functions.dirty (checks whether file can be commited)
Made `type' :AuCommit option accept :AuStatus-like abbreviations
Made :AuCommit ignore unknown and deleted files by default (like mercurial without --addremove)
Fixed :AuCommit file/pattern
Fixed commit buffer insert mode mappings

Comments (0)

Files changed (4)

     let buf=get(a:000, 0, bufnr('%'))
     let bvar=s:bufvars[buf]
     if a:action is# 'commit'
-        let message=join(getline(1, '$'), "\n")
+        let message=join(filter(getline(1, '$'), 'v:val[0] isnot# "#"'), "\n")
         call bvar.repo.functions.commit(bvar.repo, message, bvar.files,
                     \                   bvar.user, bvar.date, bvar.closebranch)
         if !a:0
     elseif a:action is# 'discard'
         if !a:0
             bwipeout!
+            stopinsert
         endif
     endif
     if has_key(bvar, 'sbvar')
         call s:_f.throw('nrepo')
     endif
     "▶4 Get file list
-    if has_key(a:opts, 'type')
-        let types=s:_r.status.parseshow(a:opts.type)
-    endif
-    if a:0
+    if a:0 && index(a:000, ':')!=-1
+        let files=[]
+    elseif a:0
+        if has_key(a:opts, 'type')
+            let types=s:_r.status.parseshow(a:opts.type)
+        endif
         let filepats=map(copy(a:000), 's:F.comm.globtopattern('.
                     \                 'repo.functions.reltorepo(repo, v:val))')
         let status=repo.functions.status(repo)
         let files=[]
+        let statfiles={}
         for [type, sfiles] in items(status)
-            if type is# 'clean' || (exists('types') && index(types, type)==-1)
+            if type is# 'clean' || type is# 'ignored' ||
+                        \(exists('types')?(index(types, type)==-1):
+                        \                 (type is# 'unknown' ||
+                        \                  type is# 'deleted'))
                 continue
             endif
+            let curfiles=[]
             for pattern in filepats
-                let files+=filter(copy(sfiles), 'v:val=~#pattern')
+                let curfiles+=filter(copy(sfiles), 'v:val=~#pattern')
             endfor
+            if !empty(curfiles)
+                let statfiles[type]=curfiles
+                let files+=curfiles
+            endif
         endfor
     elseif filereadable(expand('%'))
-        let files=[join(s:_r.os.path.split(s:_r.os.path.relpath(expand('%'),
-                    \                                          repo.path))[1:],
-                    \  '/')]
+        let files=[repo.functions.reltorepo(repo, expand('%'))]
+        if !repo.functions.dirty(repo, files[0])
+            call s:_f.throw('nocfile')
+        endif
     else
         call s:_f.throw('nocfile')
     endif
 let s:comfunc['@FWC']=['-onlystrings '.
             \          '{  repo '.s:repoarg.
             \          ' *?type      (either (in [modified added removed '.
-            \                                    'deleted uknown ignored] '.
-            \                                    '~start, '.
-            \                                'match /\v^[MARDUI?!]+$/)'.
+            \                                    'deleted uknown] ~start, '.
+            \                                'match /\v^[MARDU?!]+$/))'.
             \          '  ?message   (type "")'.
             \          '  ?user      (type "")'.
             \          '  ?date      match /\v%(^%(\d*\d\d-)?'.
             \'\V+ type ""', '+ (path)', ''))
 "▶3 AuCommitMessage mapping group
 function s:F.comm.gmc(...)
-    return ':<C-u>call call(<SID>Eval("s:F.com.runcommap"),'.string(a:000).','.
-                \          '{})<CR>'
+    return '<C-\><C-n>'.
+                \':call call(<SID>Eval("s:F.com.runcommap"),'.string(a:000).','.
+                \           '{})<CR>'
 endfunction
 call s:_f.mapgroup.add('AuCommitMessage', {
             \ 'commit': {'lhs': 'C', 'rhs': s:F.comm.gmc('commit') },
             \'discard': {'lhs': 'X', 'rhs': s:F.comm.gmc('discard')},
         \}, {'mode': 'in', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶2 comm
+"▶3 comm.dirty :: repo, file -> Bool
+function s:F.comm.dirty(repo, file)
+    let status=a:repo.functions.status(a:repo)
+    for [type, files] in items(status)
+        if type is# 'ignored' || type is# 'clean'
+            continue
+        endif
+        if index(files, a:file)!=-1
+            return 1
+        endif
+    endfor
+    return 0
+endfunction
 "▶3 comm.setlines
 function s:F.comm.setlines(lines, read)
     let d={'set': function((a:read)?('append'):('setline'))}
         elseif has_key(s:bufvars, buf) && s:bufvars[buf].command is# 'copy'
             let path=s:_r.os.path.dirname(
                         \s:_r.os.path.realpath(s:bufvars[buf].file))
-        elseif isdirectory(expand('%:p:h'))
+        elseif empty(&buftype) && isdirectory(expand('%:p:h'))
             let path=s:_r.os.path.realpath(expand('%:p:h'))
         else
             let path=s:_r.os.path.realpath('.')
     if !has_key(repo.functions, 'reltorepo')
         let repo.functions.reltorepo=s:F.comm.reltorepo
     endif
+    if !has_key(repo.functions, 'dirty')
+        let repo.functions.dirty=s:F.comm.dirty
+    endif
     return repo
 endfunction
 "▶3 comm.globtopattern :: glob → pattern
     try:
         repo=g_repo(path)
         args=[ui.ui(), repo]
+        kwargs={'close_branch': close_branch, 'message': text}
         if files:
             args.extend(files)
-        kwargs={'addremove': True, 'close_branch': close_branch, 'message': text}
+            kwargs['addremove']=True
         if date:
             kwargs['date']=date
         if user:
 :W{{{1
 :R silent edit nohglinesrev.lst
-:AuCommit
+:silent AuCommit
 Abc:silent write
 :WT
+:W{{{1 ,C mapping
+:call append('$', 'Brand new text')
+:silent write
+:silent AuCommit
+Jkl,C:WT
+:W{{{1 ,X mapping
+:call append('$', 'Brand new text 2')
+:silent write
+:silent AuCommit
+Mno,X:WT
 :W{{{1 message
 :call append('$', 'New text')
 :silent write
-:AuCommit message Def\ ghi
+:silent AuCommit message Def\ ghi
 :WT
 :W{{{1 message+user+date
 :call append('$', 'New text 2')
 :silent write
-:AuCommit message Def\ ghi user A\ <a@example.com> date 2007-08-11_6:00
+:silent AuCommit message Def\ ghi user A\ <a@example.com> date 2007-08-11_6:00
 :WT!
+:W{{{1 files
+:call append('$', 'New text 3')
+:silent write
+:bwipeout!
+:R silent AuCommit **
+Pqr,C:WT
+:source addmessages.vim
 @  Changeset 23
 |  Tag: tip
 |    Abc
+{{{1 ,C mapping
+@  Changeset 24
+|  Tag: tip
+|    Jkl
+{{{1 ,X mapping
+@  Changeset 24
+|  Tag: tip
+|    Jkl
 {{{1 message
-@  Changeset 24
+@  Changeset 25
 |  Tag: tip
 |    Def ghi
 {{{1 message+user+date
-@  Changeset 25
+@  Changeset 26
 |  Commited 11 Aug 2007 06:00 by A <a@example.com>
 |  Tag: tip
 |    Def ghi
+{{{1 files
+@  Changeset 27
+|  Tag: tip
+|    Pqr
+>>> Messages:
+
+
+<<< Messages^
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.