Commits

ZyX_I  committed 6f31431

@aurum/commit: Added g:aurum_bufleaveremembermessage option
@aurum/drivers/git, @aurum/drivers/common/utils: Some git fixes

  • Participants
  • Parent commits d31caf5

Comments (0)

Files changed (7)

File doc/aurum.txt

 ==============================================================================
 1. Intro                                                         *aurum-intro*
 
-This plugin provides a vim <--> VCS (currently only mercurial) integration for 
-your projects. Features:
+This plugin provides a vim <--> VCS (currently mercurial and git) integration 
+for your projects. Features:
   - Partially committing changes (|:AuRecord|).
   - Viewing file state at particular revision (|aurum://file|, |:AuFile|).
   - Viewing uncommited changes in a |vimdiff|, as well as changes between 
     Default: 1.
 
 remembermsg                                              *g:aurum_remembermsg*
-    Bool. Determines whether message typed in commit buffer should be saved in 
-    case of rollback. This message will appear in commit buffer if you do 
-    |:AuCommit| and tip revision hash is equal to hash of tip revision saved 
-    after previous |:AuCommit| run.
+    Bool. Determines whether message typed in commit buffer should be saved 
+    when commit is performed in case of rollback. This message will appear in 
+    commit buffer if you do |:AuCommit| and tip revision hash is equal to hash 
+    of tip revision saved after previous |:AuCommit| run.
+    Default: 1.
                                                    *g:AuPreviousCommitMessage*
                                       *g:AuPreviousTip* *g:AuPreviousRepoPath*
     Note that this option determines whether message should be saved, not 
          g:AuPreviousTip. It does not matter who set these variables and what 
          is the value of “remembermsg” option.
 
+bufleaveremembermsg                              *g:aurum_bufleaveremembermsg*
+    Bool. Determines whether message typed in commit buffer should be saved 
+    when message buffer is left excluding the case when buffer is left after 
+    commit is done. See note under |g:AuPreviousCommitMessage|.
+    Default: 1.
+
 usewin                                                        *g:aurum_usewin*
     Bool. Determines whether |:AuVimDiff| should use existing window. Existing 
     window will be used if it is located to the left or right ('diffopt' 
 10. Notes about various driver implementations            *aurum-driver-notes*
 
 Mercurial:
+
+|aurum-rf-label|:
+    Supported labels: tag (non-local/local), bookmark (non-local).
+
 |aurum-repo.hypsites|:
     1. When processing various git repositories checked out using hg-git 
        (http://hg-git.github.com/) it is assumed that |aurum-cs.hex| can be 
 Python driver was not tested under windows (wine) at all.
 
 Git:
+
+|aurum-rf-label|: Supported labels: tag, branch (both non-local).
+
 |aurum-cs.branch| always contains string "default".
 |aurum-cs.tags|:
     Contains list of all references pointing to given commit, not just tags.

File plugin/aurum/bufvars.vim

         unlet s:bufvars[buf]
     endif
 endfunction
+"▶1 AurumBufVars augroup
 augroup AurumBufVars
     autocmd BufWipeOut * :call s:F.bufwipeout()
 augroup END

File plugin/aurum/commit.vim

             \'nocread': 'Cannot read aurum://commit',
         \}
 let s:_options={
-            \'remembermsg': {'default': 1, 'filter': 'bool'},
+            \'remembermsg':         {'default': 1, 'filter': 'bool'},
+            \'bufleaveremembermsg': {'default': 1, 'filter': 'bool'},
         \}
 "▶1 parsedate string → [year, month, day, hour, minute, second]
 " Date must have one of the following formats (XXX it is not validated):
         return 1
     endif
 endfunction
+"▶1 savemsg :: message, bvar → + g:
+function s:F.savemsg(message, bvar)
+    let g:AuPreviousCommitMessage=a:message
+    let g:AuPreviousTip=a:bvar.repo.functions.gettiphex(a:bvar.repo)
+    let g:AuPreviousRepoPath=a:bvar.repo.path
+endfunction
 "▶1 finish :: bvar → + bvar.repo
 function s:F.finish(bvar)
     let message=join(filter(getline(1, '$'), 'v:val[0] isnot# "#"'), "\n")
         call s:_f.throw('emptmsg')
     endif
     if s:_f.getoption('remembermsg')
-        let g:AuPreviousCommitMessage=message
-        let g:AuPreviousTip=a:bvar.repo.functions.gettiphex(a:bvar.repo)
-        let g:AuPreviousRepoPath=a:bvar.repo.path
+        call s:F.savemsg(message, a:bvar)
     endif
     call a:bvar.repo.functions.commit(a:bvar.repo, message, a:bvar.files,
                 \                     a:bvar.user, a:bvar.date,
                 \                     a:bvar.closebranch)
+    let a:bvar.did_message=1
     call feedkeys("\<C-\>\<C-n>:bwipeout!\n")
 endfunction
 "▶1 commfunc
             \'modifiable': 1,
             \  'filetype': 'aurumcommit',
             \}
+function s:F.bufleave()
+    let bvar=s:_r.bufvars[+expand('<abuf>')]
+    if !bvar.did_message && s:_f.getoption('bufleaveremembermsg')
+        let message=join(filter(getline(1,'$'),'v:val[0] isnot# "#"'), "\n")
+        call s:F.savemsg(message, bvar)
+    endif
+endfunction
 function s:commit.function(read, repo, user, date, cb, files)
     if a:read
         call s:_f.throw('nocread')
     endif
+    augroup AuCommit
+        autocmd! BufLeave <buffer> :call s:F.bufleave()
+    augroup END
     return {'user': a:user, 'date': a:date, 'files': a:files,
-                \'closebranch': !!a:cb, 'write': s:F.finish,}
+                \'closebranch': !!a:cb, 'write': s:F.finish,
+                \'did_message': 0}
 endfunction
+let s:_augroups+=['AuCommit']
 function s:commit.write(lines, repo, user, date, cb, files)
     let message=join(filter(copy(a:lines), 'v:val[0] isnot# "#"'), "\n")
     call a:repo.functions.commit(a:repo, message, a:files, a:user, a:date, a:cb)

File plugin/aurum/drivers/common/utils.vim

                 \             '((v:val[1] is 1)?'.
                 \               '(repeat("-", 1+(len(v:val[0])>1)).v:val[0]):'.
                 \               '(repeat("-", 1+(len(v:val[0])>1)).v:val[0].'.
-                \                          '"=".shellescape(v:val[1],a:esc)))'))
+                \                              '" ="[len(v:val[0])>1].'.
+                \                              'shellescape(v:val[1],a:esc)))'))
     endif
     if !empty(a:args)
         let cmd.=' '.join(map(copy(a:args), 'shellescape(v:val, a:esc)'))

File plugin/aurum/drivers/git.vim

     return [cs, line]
 endfunction
 "▶1 git.getchangesets :: repo → []
+"▶2 rerev :: Either rev num → rev
+function s:F.rerev(rev)
+    if type(a:rev)==type(0)
+        if a:rev is 0
+            " XXX Ranges like ..HEAD are not working, though it is unlikely that
+            "     revrange will receive ranges like ?..0 or 0..? except 0..-1, 
+            "     thus 0..? is always taken as 0..-1
+            return ''
+        elseif a:rev is -1
+            return 'HEAD'
+        elseif a:rev
+            return 'HEAD~'.(-1-a:rev)
+        endif
+    else
+        return a:rev
+    endif
+endfunction
+"▲2
 function s:git.getchangesets(repo, ...)
     "▶2 Prepare s:F.git arguments
     let args=[]
     if a:0
-        let args+=[a:1.'..'.a:2]
+        if a:1 is 0
+        else
+            let args+=[s:F.rerev(a:1).'..'.s:F.rerev(a:2)]
+        endif
     endif
     let gitargs=[a:repo, 'log', args, extend({'all': 1, 'full-history': 1},
                 \                            s:logkwargs), 0]

File test/prevmessage.in

+:R AuCommit **
+Commiting
+everything
+,X
+:
+:R AuCommit **
+:call WriteFile(getline(1, '$'))
+:let g:aurum_bufleaveremembermsg=0
+:bw!
+:R AuCommit **
+:call WriteFile(getline(1, '$'))
+:bw!
 :R AuCommit **
 Commiting
 all

File test/prevmessage.ok

+Commiting
+everything
+
+# Added addeddef
+# Modified nohglinesrev.lst
+# Removed hglines2.lst
+
+# Added addeddef
+# Modified nohglinesrev.lst
+# Removed hglines2.lst
 @  Changeset 27
 |  Tags: tip
 |  @ Commiting
 
 
 
+
+
+
 Frawor:plugin/aurum/commit:emptmsg:Message must contain at least one non-blank character
 Frawor:plugin/aurum/commit:emptmsg:Message must contain at least one non-blank character
 <<< Messages^