ZyX_I avatar ZyX_I committed 9736d0b

Added :AuBranch command
Added repo.label function (untested)
Some non-python driver fixes

Comments (0)

Files changed (10)

autoload/aurum.vim

 "▶1 
-execute frawor#Setup('0.0', {'@aurum/repo': '0.0',
+execute frawor#Setup('0.0', {'@aurum/repo': '1.0',
             \               '@aurum/cache': '0.0',})
 "▶1 aurum#repository
 function aurum#repository()
     Annotate rev {rev} of a file {file}. By default annotates current revision 
     of a current file (|aurum-current-file|).
 
+AuBranch {branch} [repo {repo}] [force]                            *:AuBranch*
+    Set current branch name to {branch}.
+
 AuCommit {options} [glob1 [glob2 [...]]]                           *:AuCommit*
     Commit files matching given globs (current file if no globs were given). 
     If “message” option was not specified, opens |aurum://commit| buffer. You 
     Updates data stored in repository. Is called automatically when you get 
     the repository object unless this object is obtained from cash used by 
     |aurum#repository|.
-  reltorepo :: repo, path -> path                         *aurum-rf-reltorepo*
+  reltorepo :: path -> path                               *aurum-rf-reltorepo*
     Turn absolute or relative to current directory path into relative to 
     repository root one.
+  branch :: branch, force -> _                               *aurum-rf-branch*
+    Create new branch.
+  label :: type, label, hex, force, local -> _                *aurum-rf-label*
+    Label specific revision (if rev is 0 then remove label).
 The following functions do not accept repo argument:
   repo :: path -> repo                                         *aurum-rf-repo*
     Creates new repository object using repository located at given path.
     " TODO :AuMerge ?
     " TODO :AuExplore
     let s:addargs={'Update': {'bang': 1}, 'Move': {'bang': 1}}
-    for s:cmd in ['Update', 'Move', 'Junk', 'Track', 'Hyperlink', 'Grep']
+    for s:cmd in ['Update', 'Move', 'Junk', 'Track', 'Hyperlink', 'Grep',
+                \ 'Branch']
         let s:part=tolower(s:cmd[:3])
         if len(s:cmd)>4 && stridx('aeiouy', s:part[-1:])!=-1
             let s:part=s:part[:-2]
             \'nofiles': 'No files were specified',
             \   'nogf': 'No files found',
             \  'nrepo': 'Not a repository: %s',
+            \ 'bexsts': 'Error while creating branch %s for repository %s: '.
+            \           'branch already exists',
             \'_mvheader': ['Source', 'Destination'],
         \}
 let s:utypes=['html', 'raw', 'annotate', 'filehist', 'bundle', 'changeset',
             \substitute(substitute(s:grepfunc['@FWC'][0],
             \'\Vfiles \+type ""', 'files (path)', ''),
             \'\v(rev%(ision|range))\ +\Vtype ""', '\1 '.s:_r.comp.rev, 'g'))
+"▶1 branfunc
+function s:branfunc.function(branch, opts)
+    let repo=s:_r.repo.get(a:opts.repo)
+    call s:_r.cmdutils.checkrepo(repo)
+    let force=get(a:opts, 'force', 0)
+    if !force && index(repo.functions.getrepoprop(repo, 'brancheslist'),
+                \      a:branch)!=-1
+        call s:_f.throw('bexsts', a:branch, repo.path)
+    endif
+    call repo.functions.branch(repo, a:branch, force)
+endfunction
+let s:branfunc['@FWC']=['-onlystrings '.
+            \           'type "" '.
+            \           '{  repo '.s:_r.cmdutils.nogetrepoarg.
+            \           ' ?!force'.
+            \           '}', 'filter']
+call add(s:brancomp, s:branfunc['@FWC'][0])
 "▶1
 call frawor#Lockvar(s:, '_pluginloaded,_r')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

plugin/aurum/drivers/mercurial.vim

             \ 'nhgiwr': 'File %s is either a directory or not writeable',
             \'reponwr': 'Unable to write to repository root (%s)',
             \  'nocfg': 'Failed to get property %s of repository %s ',
+            \'nlocbms': 'Bookmarks can’t be local',
         \}
 if !s:usepythondriver
     call extend(s:_messages, {
         return []
     endif
     return map(copy(lines), 'matchlist(v:val, '.
-                \                    '''\v^(.{-})\ +(\d+)\:\x{12}$'')[1:2]')
+                \                         '''\v^(.{-})\ +(\d+)\:\x{12}'')[1:2]')
 endfunction
 "▲2
 endif
 endfunction
 else "▶2
 function s:hg.repo(path)
+    " TODO remove bookmark label type if it is not available
     let repo={'path': a:path, 'changesets': {}, 'cslist': [],
                 \'local': (stridx(a:path, '://')==-1),
-                \'functions': copy(s:hg),}
+                \'labeltypes': ['tag', 'bookmark'],}
     return repo
 endfunction
 endif
                 \                      '**vim.eval("a:kwargs"))'
 endfunction
 else "▶2
-" XXX Here all args must be paths
+" XXX Here all args must be paths unless attr is listed in nopathattrs
+let s:nopathattrs=['branch', 'tag', 'bookmark']
 function s:F.runcmd(repo, attr, args, kwargs, ...)
     let cmd=a:attr
     if !empty(a:kwargs)
                 \               '("--".v:val[0]." ".shellescape(v:val[1],1)))'))
     endif
     if !empty(a:args)
-        let cmd.=' -- '.join(map(copy(a:args),
-                \                'shellescape(s:_r.os.path.join(a:repo.path, '.
-                \                                              'v:val), 1)'))
+        if index(s:nopathattrs, a:attr)==-1
+            let expr='shellescape(s:_r.os.path.join(a:repo.path, v:val), 1)'
+        else
+            let expr='shellescape(v:val, 1)'
+        endif
+        let cmd.=' -- '.join(map(copy(a:args), expr))
     endif
     let prevempty=0
     for line in s:F.hg(a:repo, cmd, a:0 && a:1, 'cmd', cmd)[:-2+(a:0 && a:1)]
 function s:hg.add(repo, ...)
     return s:F.runcmd(a:repo, 'add', a:000, {})
 endfunction
+"▶1 hg.branch :: repo, branchname, force → + FS
+function s:hg.branch(repo, branch, force)
+    return s:F.runcmd(a:repo, 'branch', [a:branch], a:force ? {'force': 1} : {})
+endfunction
+"▶1 hg.label :: repo, type, label, rev, force, local → + FS
+function s:hg.label(repo, type, label, rev, force, local)
+    let kwargs={}
+    if a:force
+        let kwargs.force=1
+    endif
+    if a:type is# 'tag'
+        if a:local
+            let kwargs.local=1
+        endif
+        if a:rev is 0
+            let kwargs.remove=1
+        else
+            let kwargs.rev=a:rev
+        endif
+    elseif a:type is# 'bookmark'
+        if a:local
+            call s:_f.throw('nlocbms')
+        endif
+        if a:rev is 0
+            let kwargs.delete=1
+        else
+            let kwargs.rev=a:rev
+        endif
+    endif
+    return s:F.runcmd(a:repo, a:type, [a:label], kwargs)
+endfunction
 "▶1 addtosection :: repo, hgignore::path, section, line → + FS(hgignore)
 function s:F.addtosection(repo, hgignore, section, line)
     let addsect=['syntax: '.a:section,

plugin/aurum/repo.vim

     endif
     let repo.type=driver.id
     let repo.path=path
-    if !has_key(repo, 'functions')
-        let repo.functions=copy(driver.functions)
-    endif
+    let repo.functions=copy(driver.functions)
     let repo.diffopts=copy(s:_f.getoption('diffopts'))
     lockvar! repo
     unlockvar! repo.cslist
 "▶1 regdriver feature
 let s:requiredfuncs=['repo', 'getcs', 'checkdir']
 let s:optfuncs=['readfile', 'annotate', 'diff', 'status', 'commit', 'update',
-            \   'dirty', 'diffre', 'getstats', 'getrepoprop', 'copy', 'forget']
+            \   'dirty', 'diffre', 'getstats', 'getrepoprop', 'copy', 'forget',
+            \   'branch', 'label']
 "▶2 regdriver :: {f}, name, funcs → + s:drivers
 function s:F.regdriver(plugdict, fdict, name, funcs)
     "▶3 Check arguments
     let driver.plid=a:plugdict.id
     let driver.id=a:name
     call extend(driver.functions, s:deffuncs, 'keep')
-    for funname in filter(copy(s:optfuncs),
-                \         '!exists("*driver.functions[v:val]")')
+    for funname in filter(copy(s:optfuncs), '!has_key(driver.functions, v:val)')
         execute      "function driver.functions.".funname."(...)\n".
                     \"    call s:_f.throw('nimp', '".funname."', ".
                     \                    "'".a:name."')\n".
                     \"endfunction"
     endfor
-    lockvar driver
+    lockvar! driver
     let a:fdict[a:name]=driver
     let s:drivers[a:name]=driver
 endfunction
 def new_repo(path):
     try:
         repo=g_repo(path)
+        # TODO remove bookmark label type if it is not available
         vim_repo={
             'changesets': {},
                 'cslist': [],
                  'local': 1 if repo.local() else 0,
+            'labeltypes': ['tag', 'bookmark'],
                  }
         if hasattr(repo, '__len__'):
             vim_repo['csnum']=len(repo)+1
+:W{{{1 D
+:R silent AuBranch D
+:R call writefile(['abc'], 'abcfile')
+:R silent AuCommit type ? message Added\ abcfile abcfile
+:WT
+:W{{{1 noforce C
+:R try | AuBranch C | catch | endtry
+:R call writefile(['def'], 'deffile')
+:R silent AuCommit type ? message Added\ deffile deffile
+:WT
+:W{{{1 force C
+:R silent AuBranch C force
+:R call writefile(['ghi'], 'ghifile')
+:R silent AuCommit type ? message Added\ ghifile ghifile
+:WT
+:W{{{1 repo E
+:execute 'silent AuBranch E repo '.g:curtest.'repo'
+:R call writefile(['jkl'], 'jklfile')
+:R silent AuCommit type ? message Added\ jklfile jklfile
+:WT
+:source addmessages.vim
+{{{1 D
+@  Changeset 27 (branch D)
+|  Tags: tip
+|  @ Added abcfile
+{{{1 noforce C
+@  Changeset 28 (branch D)
+|  Tags: tip
+|  @ Added deffile
+{{{1 force C
+@  Changeset 29 (branch C)
+|  Tags: tip
+|  @ Added ghifile
+{{{1 repo E
+@  Changeset 30 (branch E)
+|  Tags: tip
+|  @ Added jklfile
+>>> Messages:
+Frawor:plugin/aurum:bexsts:Error while creating branch C for repository %TMPDIR%/test/branchrepo: branch already exists
+<<< Messages^
     if !a:writecom
         g/Commited/delete _
     endif
-    normal! gg0f:"_d$
+    normal! gg0f:"_de
     call WriteFile(getline(1, line('$')-1))
     bwipeout!
 endfunction

test/wine/branch.ok

+{{{1 D
+@  Changeset 27 (branch D)
+|  Tags: tip
+|  @ Added abcfile
+{{{1 noforce C
+@  Changeset 28 (branch D)
+|  Tags: tip
+|  @ Added deffile
+{{{1 force C
+@  Changeset 29 (branch C)
+|  Tags: tip
+|  @ Added ghifile
+{{{1 repo E
+@  Changeset 30 (branch E)
+|  Tags: tip
+|  @ Added jklfile
+>>> Messages:
+Frawor:plugin/aurum:bexsts:Error while creating branch C for repository %TMPDIR%\test\branchrepo: branch already exists
+<<< 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.