Commits

ZyX_I committed 95f1462

@aurum/drivers/git: Added setcsprop(..., "children")
Added rf-label() and rf-branch()
Fixed rf-commit() (untested)
@aurum/repo: Improved default rf-copy() (untested)

Comments (0)

Files changed (2)

plugin/aurum/drivers/git.vim

             \    'lsf': 'Failed to list files in the changeset %s '.
             \           'of the repository %s: %s',
             \'statusf': 'Failed to obtain status of the repository %s: %s',
+            \    'rlf': 'Failed to list commits in repository %s: %s',
+            \    'lbf': 'Failed to create/remove %s %s for revision %s '.
+            \           'in 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',
         \}
 let s:git={}
 "▶1 s:hypsites
         let r=map(s:F.git(a:repo, 'ls-tree', ['--', a:cs.hex],
                     \                        {'name-only': 1, 'r': 1}, 0,
                     \     'lsf', a:cs.hex)[:-2], 's:F.refile(v:val)')
+    elseif a:propname is# 'children'
+        let lines=filter(map(s:F.git(a:repo, 'rev-list', [], {'all': 1,
+                    \                                'full-history': 1,
+                    \                                    'children': 1}, 0,
+                    \                'rlf')[:-2],
+                    \        'split(v:val)'),
+                    \    'has_key(a:repo.changesets, v:val[0])')
+        for [hex; children] in lines
+            let a:repo.changesets[hex].children=children
+        endfor
+        return a:cs.children
     endif
-    " TODO children, renames, copies
+    " TODO renames, copies
     let a:cs[a:propname]=r
     return r
 endfunction
 endfunction
 "▶1 git.commit :: message[, files[, user[, date[, _]]]]
 function s:git.commit(message, ...)
-    let kwargs={'all': 1, 'cleanup': 'verbatim'}
+    let kwargs={'cleanup': 'verbatim'}
     if a:message=~#'\v[\r\n]'
         let tmpfile=tempname()
         call writefile(split(a:message, "\n", 1), tmpfile, 'b')
     if a:0
         if !empty(a:1)
             let args+=['--']+a:1
-            " FIXME Check whether it is right option
-            let kwargs.include=1
+            for file in a:1
+                call a:repo.functions.add(a:repo, file)
+            endfor
         endif
         if a:0>1 && !empty(a:2)
             let kwargs.author=a:2
     endtry
 endfunction
 "▶1 git.update :: repo, rev, force → + FS
+" XXX This must not transform {rev} into hash: it will break rf-branch()
 function s:git.update(repo, rev, force)
     let kwargs={}
     if a:force
 function s:git.ignoreglob(repo, glob)
     return s:F.addtoignfile(s:_r.os.path.join(a:repo.path,'.gitignore'), a:glob)
 endfunction
+"▶1 git.branch :: repo, branchname, force → + FS
+function s:git.branch(repo, branch, force)
+    if a:force
+        return s:F.gitm(a:repo, 'checkout', [a:branch], {'B': 1}, 0,
+                    \   'chbf', a:branch)
+    else
+        call a:repo.functions.label(a:repo, 'branch', a:branch, 'HEAD', 0, 0)
+        call a:repo.functions.update(a:repo, a:branch, 0)
+    endif
+endfunction
+"▶1 git.label :: repo, type, label, rev, force, local → + FS
+function s:git.label(repo, type, label, rev, force, local)
+    if a:local
+        call s:_f.throw('nloc')
+    endif
+    let args=['--', a:label]
+    let kwargs={}
+    if a:force
+        let kwargs.force=1
+    endif
+    if a:rev is 0
+        let kwargs.d=1
+    else
+        lat args+=[a:rev]
+    endif
+    return s:F.gitm(a:repo, a:type, args, kwargs, 0,
+                \   'lbf', a:type, a:label, a:rev)
+endfunction
 "▶1 git.repo :: path → repo
 function s:git.repo(path)
     let repo={'path': a:path, 'changesets': {}, 'cslist': [],

plugin/aurum/repo.vim

 function s:deffuncs.copy(repo, force, source, target)
     let src=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:source))
     let tgt=s:_r.os.path.normpath(s:_r.os.path.join(a:repo.path, a:target))
-    if filereadable(tgt)
+    if filewritable(tgt)==1
         if a:force
             call delete(tgt)
         else
             call s:_f.throw('tgtex', tgt)
         endif
+    elseif s:_r.os.path.exists(tgt)
+        " Don’t try to delete directories and non-writable files.
+        call s:_f.throw('tgtex', tgt)
     endif
     let cmd=0
     if executable('cp')