Commits

ZyX_I  committed da3cc84

Added :AuUpdate

  • Participants
  • Parent commits f5f55a2

Comments (0)

Files changed (6)

File ftplugin/aurumgraphlog.vim

 "▶1
 scriptencoding utf-8
 setlocal textwidth=0
-setlocal nolist nowrap
+setlocal nolist
 if has('conceal')
     setlocal concealcursor+=n conceallevel=2
 endif

File plugin/aurum.vim

     call FraworLoad('@/commands')
     call FraworLoad('@/functions')
     " TODO revision completion
+    " TODO improve files completion
     " TODO U (update), K and J mappings for aurum://file and aurum://diff
     let s:glogfunc={}
     let s:glogcomp=[]
     let s:comcomp=[]
     call s:_f.command.add('AuCommit', s:comfunc, {'nargs': '*',
                 \                              'complete': s:comcomp})
+    let s:upfunc={}
+    let s:upcomp=[]
+    call s:_f.command.add('AuUpdate', s:upfunc, {'nargs': '*',
+                \                                 'bang': 1,
+                \                             'complete': s:upcomp,})
     "▶2 Autocommands
     call FraworLoad('@/autocommands')
     let s:auefunc={}
     endfor
 endfunction
 "▶3 hg.update
-function s:F.hg.update(repo)
+function s:F.hg.updatechangesets(repo)
     let d={}
     let start=len(a:repo.cslist)-2
     if start<0
             let repo.tip_hex=repo.functions.getrevhex(repo, 'tip')
             let repo.work_hex=repo.functions.getrevhex(repo, '.')
         else
-            call repo.functions.update(repo)
+            call repo.functions.updatechangesets(repo)
         endif
         return repo
     endif
 endfunction
 "▶3 hg.getchangesets :: repo → changesets + repo.changesets
 function s:F.hg.getchangesets(repo)
-    call a:repo.functions.update(a:repo)
+    call a:repo.functions.updatechangesets(a:repo)
     return a:repo.changesets
 endfunction
 "▶3 hg.getrevhex :: repo, rev → rev(hex)
         execute s:_r.py.cmd 'aurum.commit(vim.eval("a:repo.path"), '.args.')'
     endtry
 endfunction
+"▶3 hg.update :: repo, rev, force
+function s:F.hg.update(repo, rev, force)
+    try
+        execute s:_r.py.cmd 'aurum.update(vim.eval("a:repo.path"), '.
+                    \                    'vim.eval("a:rev"), '.
+                    \                    'int(vim.eval("a:force")))'
+    endtry
+endfunction
 "▶2 rec
 "▶3 rec.curundo :: () -> UInt
 if exists('*undotree')
                 \ fnameescape('aurum://file:'.epath.':'.rev.':'.file)
 endfunction
 let s:filefunc['@FWC']=['-onlystrings '.
-            \           '[:=(".") type "" '.
+            \           '[:"."    type "" '.
             \           '[:=(0)   either (match /\L/, path fr)]]'.
             \           '{ repo '.s:nogetrepocarg.
             \           ' ?cmd    type ""}', 'filter']
             \substitute(substitute(s:filefunc['@FWC'][0],
             \'\V:=(0)\v\s+type\s*\V""', 'path', ''),
             \'\Vcmd\s\+type ""',    'cmd first (in cmds, idof command)', ''))
+"▶2 upfunc
+function s:upfunc.function(bang, rev, repo)
+    if type(a:repo)!=type({})
+        call s:_f.throw('nrepo')
+    endif
+    let rev=a:repo.functions.getrevhex(a:repo, a:rev)
+    return a:repo.functions.update(a:repo, rev, a:bang)
+endfunction
+let s:upfunc['@FWC']=['-onlystrings _ '.
+            \         '[:"tip" type ""'.
+            \         '['.s:repoarg.']]', 'filter']
+call add(s:upcomp,
+            \substitute(s:upfunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''))
 "▶2 aubwfunc
 function s:aubwfunc.function()
     let buf=+expand('<abuf>')

File python/aurum.py

     except FindError:
         pass
 
+def run_in_dir(dir, func, *args, **kwargs):
+    workdir=os.path.abspath('.')
+    try:
+        os.chdir(dir)
+    except AttributeError:
+        pass
+    except OSError:
+        pass
+    func(*args, **kwargs)
+    os.chdir(workdir)
+
 def dodiff(ui, path, rev1, rev2, files, opts):
     repo=g_repo(path)
     args=[ui, repo]+files
         kwargs["rev"]=[rev2]
     else:
         kwargs["rev"]=[rev1, rev2]
-    workdir=os.path.abspath('.')
-    try:
-        os.chdir(repo.root)
-    except AttributeError:
-        pass
-    except OSError:
-        pass
-    commands.diff(*args, **kwargs)
-    os.chdir(workdir)
+    run_in_dir(repo.root, commands.diff, *args, **kwargs)
 
 def diff(*args, **kwargs):
     try:
             kwargs['user']=user
         if force:
             kwargs['force']=True
-        workdir=os.path.abspath('.')
-        try:
-            os.chdir(repo.root)
-        except AttributeError:
-            pass
-        except OSError:
-            pass
-        commands.commit(*args, **kwargs)
-        os.chdir(workdir)
+        run_in_dir(repo.root, commands.commit, *args, **kwargs)
     except FindError:
         pass
 
+def update(path, rev='tip', force=False):
+    try:
+        repo=g_repo(path)
+        rev=g_cs(repo, rev).hex()
+        args=[ui.ui(), repo, rev]
+        kwargs={'clean': not not force}
+        run_in_dir(repo.root, commands.update, *args, **kwargs)
+    except FindError:
+        pass

File test/gentests-setuptestrepos.zsh

 emulate -L zsh
 tar xJf testrepo.tar.xz
 
-for test in annotate-buffers commit record stat statmaps vimdiff diff ; do
+for test in annotate-buffers commit record stat statmaps vimdiff diff update
+do
     mkdir ${test}repo
     tar c -C testrepo . | (cd ${test}repo && tar x)
 done

File test/update.in

+:W{{{1 Modified: fail
+:R silent AuUpdate
+:R call WriteFile(filereadable('nohglinesrev.lst'))
+:R call WriteFile(readfile('nohglinesrev.lst', 'b'))
+:W{{{1 Modified: force
+:R silent AuUpdate!
+:R call WriteFile(filereadable('nohglinesrev.lst'))
+:R call WriteFile(readfile('nohglinesrev.lst', 'b'))
+:W{{{1 Rev
+:R silent AuUpdate 2
+:R call WriteFile(filereadable('nohglinesrev.lst'))
+:R call WriteFile(readfile('crepo.zsh', 'b'))
+:W{{{1 Rev + repo
+:silent AuUpdate 1 updaterepo
+:R call WriteFile(filereadable('nohglinesrev.lst'))
+:R call WriteFile(readfile('crepo.zsh', 'b'))
+:source addmessages.vim

File test/update.ok

+{{{1 Modified: fail
+1
+hsz/nib/!#
+hsz L- etalume
+e- tes
+'>moc.elpmaxe@a< A'=A lacol
+'>gro.elpmaxe@b< B'=B lacol
+'>vog.elpmaxe@c< C'=C lacol
+{
+e- tes    
+opertset dc    
+. hsz.operetaerc/.. pc    
+9902 llit ylno krow lliw tset etaD XXX #    
+A$ resu-- '02:5 20-10-9991' etad--        
+A$ resu-- '03:7 50-10-0002' etad--        
+hsz.operc '/}{/}{/rt' e- i- p- lrep    
+B$ resu-- '00:51 51-10-0002' etad--        
+B$ resu-- '00:41 10-20-0002' etad--        
+tsl.senilgh > '/ gh    ^/ sselnu _$ fednu' e- i- p- lrep | hsz.operghc tac    
+tsl.seniletad > '/ gh    ^/ sselnu _$ fednu' e- i- p- lrep | hsz.operghc tac    
+A$ resu-- '32:4 01-50-0002' etad--        
+tsl.senild > 'd' perg | hsz.operghc tac    
+B$ resu-- '42:31 10-11-0002' etad--        
+tsl.senila > 'a' perg | hsz.operghc tac    
+A$ resu-- '44:5 20-11-0002' etad--        
+tsl.senilba > 'b' perg | tsl.senila tac    
+B$ resu-- '31:41 20-11-0002' etad--        
+B$ resu-- '41:41 20-11-0002' etad--        
+C$ resu-- '00:00 10-10-1002' etad--        
+tsl.senilb > 'b' perg | hsz.operghc tac    
+A$ resu-- '81:50 10-20-1002' etad--        
+A$ resu-- '91:50 10-20-1002' etad--        
+tsl.senilc > 'c' perg | tros | hsz.operghc tac    
+B$ resu-- '65:41 10-20-1002' etad--        
+B$ resu-- '25:65:41 10-20-1002' etad--        
+C$ resu-- '00:00 10-10-2002' etad--        
+C$ resu-- '51:00:00 10-10-2002' etad--        
+C$ resu-- '03:00:00 10-10-2002' etad--        
+C$ resu-- '54:00:00 10-10-2002' etad--        
+A$ resu-- '00:50 01-20-2002' etad--        
+tsl.senilghon > '/ gh    ^/ fi _$ fednu' e- i- p- lrep | hsz.operghc tac    
+B$ resu-- '33:51 01-20-2002' etad--        
+tsl.versenilghon > ver | tsl.senilghon tac    
+B$ resu-- '10:61 01-20-2002' etad--        
+tsl.01derongi > 'n\'$ ' ' rt | 01 1 qes    
+A$ resu-- '51:30 11-20-2002' etad--        
+erongigh. > '*derongin\bolg :xatnys'$ ohce    
+A$ resu-- '34:50 11-20-2002' etad--        
+tsl.versenilghon >> cba ohce    
+feddedda dda gh && feddedda > 'feD' ohce    
+tsl.senilghon mr    
+tsl.versenilgh > ver | tsl.senilgh tac    
+cbaderongi > 'cbA' ohce    
+}
+opertset zx.rat.opertset fJc rat
+abc
+{{{1 Modified: force
+1
+hsz/nib/!#
+hsz L- etalume
+e- tes
+'>moc.elpmaxe@a< A'=A lacol
+'>gro.elpmaxe@b< B'=B lacol
+'>vog.elpmaxe@c< C'=C lacol
+{
+e- tes    
+opertset dc    
+. hsz.operetaerc/.. pc    
+9902 llit ylno krow lliw tset etaD XXX #    
+A$ resu-- '02:5 20-10-9991' etad--        
+A$ resu-- '03:7 50-10-0002' etad--        
+hsz.operc '/}{/}{/rt' e- i- p- lrep    
+B$ resu-- '00:51 51-10-0002' etad--        
+B$ resu-- '00:41 10-20-0002' etad--        
+tsl.senilgh > '/ gh    ^/ sselnu _$ fednu' e- i- p- lrep | hsz.operghc tac    
+tsl.seniletad > '/ gh    ^/ sselnu _$ fednu' e- i- p- lrep | hsz.operghc tac    
+A$ resu-- '32:4 01-50-0002' etad--        
+tsl.senild > 'd' perg | hsz.operghc tac    
+B$ resu-- '42:31 10-11-0002' etad--        
+tsl.senila > 'a' perg | hsz.operghc tac    
+A$ resu-- '44:5 20-11-0002' etad--        
+tsl.senilba > 'b' perg | tsl.senila tac    
+B$ resu-- '31:41 20-11-0002' etad--        
+B$ resu-- '41:41 20-11-0002' etad--        
+C$ resu-- '00:00 10-10-1002' etad--        
+tsl.senilb > 'b' perg | hsz.operghc tac    
+A$ resu-- '81:50 10-20-1002' etad--        
+A$ resu-- '91:50 10-20-1002' etad--        
+tsl.senilc > 'c' perg | tros | hsz.operghc tac    
+B$ resu-- '65:41 10-20-1002' etad--        
+B$ resu-- '25:65:41 10-20-1002' etad--        
+C$ resu-- '00:00 10-10-2002' etad--        
+C$ resu-- '51:00:00 10-10-2002' etad--        
+C$ resu-- '03:00:00 10-10-2002' etad--        
+C$ resu-- '54:00:00 10-10-2002' etad--        
+A$ resu-- '00:50 01-20-2002' etad--        
+tsl.senilghon > '/ gh    ^/ fi _$ fednu' e- i- p- lrep | hsz.operghc tac    
+B$ resu-- '33:51 01-20-2002' etad--        
+tsl.versenilghon > ver | tsl.senilghon tac    
+B$ resu-- '10:61 01-20-2002' etad--        
+tsl.01derongi > 'n\'$ ' ' rt | 01 1 qes    
+A$ resu-- '51:30 11-20-2002' etad--        
+erongigh. > '*derongin\bolg :xatnys'$ ohce    
+A$ resu-- '34:50 11-20-2002' etad--        
+tsl.versenilghon >> cba ohce    
+feddedda dda gh && feddedda > 'feD' ohce    
+tsl.senilghon mr    
+tsl.versenilgh > ver | tsl.senilgh tac    
+cbaderongi > 'cbA' ohce    
+}
+opertset zx.rat.opertset fJc rat
+{{{1 Rev
+0
+#!/bin/zsh
+emulate -L zsh
+set -e
+local A='A <a@example.com>'
+local B='B <b@example.org>'
+local C='C <c@example.gov>'
+{
+    set -e
+    hg init testrepo
+    cd testrepo
+    cp ../createrepo.zsh .
+    # XXX Date test will work only till 2099
+    hg commit -A -m 'Added «createrepo.zsh»' \
+        --date '1999-01-02 5:20' --user $A
+    hg mv createrepo.zsh crepo.zsh
+    hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+        --date '2000-01-05 7:30' --user $A
+    perl -p -i -e 'tr/{}/{}/' crepo.zsh
+    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+        --date '2000-01-15 15:00' --user $B
+    hg mv crepo.zsh chgrepo.zsh
+    hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+        --date '2000-02-01 14:00' --user $B
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ unless /^    hg /' > hglines.lst
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ unless /^    hg /' > datelines.lst
+    hg commit -A -m 'Added «hglines.lst» and «datelines.lst»' \
+        --date '2000-05-10 4:23' --user $A
+    hg branch A
+    cat chgrepo.zsh | grep 'd' > dlines.lst
+    hg commit -A -m 'Added dlines.lst' \
+        --date '2000-11-01 13:24' --user $B
+    hg branch B
+    cat chgrepo.zsh | grep 'a' > alines.lst
+    hg commit -A -m 'Added alines.lst' \
+        --date '2000-11-02 5:44' --user $A
+    hg branch C
+    cat alines.lst | grep 'b' > ablines.lst
+    hg commit -A -m 'Added ablines.lst' \
+        --date '2000-11-02 14:13' --user $B
+    hg tag ablines \
+        --date '2000-11-02 14:14' --user $B
+    hg update default
+    hg merge -r ablines
+    hg commit -m 'Merge from C' \
+        --date '2001-01-01 00:00' --user $C
+    hg update C
+    cat chgrepo.zsh | grep 'b' > blines.lst
+    hg commit -A -m 'Added blines.lst' \
+        --date '2001-02-01 05:18' --user $A
+    hg tag blines \
+        --date '2001-02-01 05:19' --user $A
+    hg update -r -2
+    cat chgrepo.zsh | sort | grep 'c' > clines.lst
+    hg commit -A -m 'Added clines.lst' \
+        --date '2001-02-01 14:56' --user $B
+    hg tag clines \
+        --date '2001-02-01 14:56:52' --user $B
+    hg update A
+    hg merge -r B
+    hg commit -m 'Merge from B' \
+        --date '2002-01-01 00:00' --user $C
+    hg merge -r clines
+    hg commit -m 'Merge from C:2' \
+        --date '2002-01-01 00:00:15' --user $C
+    hg update default
+    hg merge -r blines
+    hg commit -m 'Merge from C:1' \
+        --date '2002-01-01 00:00:30' --user $C
+    hg merge -r A
+    hg commit -m 'Merge from A' \
+        --date '2002-01-01 00:00:45' --user $C
+    hg cp hglines.lst hglines2.lst
+    hg commit -A -m 'Copied “hglines.lst” to “hglines2.lst”' \
+        --date '2002-02-10 05:00' --user $A
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ if /^    hg /' > nohglines.lst
+    hg commit -A -m 'Added nohglines.lst' \
+        --date '2002-02-10 15:33' --user $B
+    cat nohglines.lst | rev > nohglinesrev.lst
+    hg commit -A -m 'Added nohglinesrev.lst' \
+        --date '2002-02-10 16:01' --user $B
+    seq 1 10 | tr ' ' $'\n' > ignored10.lst
+    hg commit -A -m 'Added ignored10.lst' \
+        --date '2002-02-11 03:15' --user $A
+    echo $'syntax: glob\nignored*' > .hgignore
+    hg commit -A -m 'Added .hgignore' \
+        --date '2002-02-11 05:43' --user $A
+    echo abc >> nohglinesrev.lst
+    echo 'Def' > addeddef && hg add addeddef
+    hg rm hglines2.lst
+    rm nohglines.lst
+    cat hglines.lst | rev > hglinesrev.lst
+    echo 'Abc' > ignoredabc
+}
+tar cJf testrepo.tar.xz testrepo
+{{{1 Rev + repo
+0
+#!/bin/zsh
+emulate -L zsh
+set -e
+local A='A <a@example.com>'
+local B='B <b@example.org>'
+local C='C <c@example.gov>'
+(
+    set -e
+    hg init testrepo
+    cd testrepo
+    cp ../createrepo.zsh .
+    # XXX Date test will work only till 2099
+    hg commit -A -m 'Added «createrepo.zsh»' \
+        --date '1999-01-02 5:20' --user $A
+    hg mv createrepo.zsh crepo.zsh
+    hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+        --date '2000-01-05 7:30' --user $A
+    perl -p -i -e 'tr/()/{}/' crepo.zsh
+    hg commit -m $'Replaced\n    (\n        ...\n    )\nwith\n    {\n        ...\n    }' \
+        --date '2000-01-15 15:00' --user $B
+    hg mv crepo.zsh chgrepo.zsh
+    hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+        --date '2000-02-01 14:00' --user $B
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ unless /^    hg /' > hglines.lst
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ unless /^    hg /' > datelines.lst
+    hg commit -A -m 'Added «hglines.lst» and «datelines.lst»' \
+        --date '2000-05-10 4:23' --user $A
+    hg branch A
+    cat chgrepo.zsh | grep 'd' > dlines.lst
+    hg commit -A -m 'Added dlines.lst' \
+        --date '2000-11-01 13:24' --user $B
+    hg branch B
+    cat chgrepo.zsh | grep 'a' > alines.lst
+    hg commit -A -m 'Added alines.lst' \
+        --date '2000-11-02 5:44' --user $A
+    hg branch C
+    cat alines.lst | grep 'b' > ablines.lst
+    hg commit -A -m 'Added ablines.lst' \
+        --date '2000-11-02 14:13' --user $B
+    hg tag ablines \
+        --date '2000-11-02 14:14' --user $B
+    hg update default
+    hg merge -r ablines
+    hg commit -m 'Merge from C' \
+        --date '2001-01-01 00:00' --user $C
+    hg update C
+    cat chgrepo.zsh | grep 'b' > blines.lst
+    hg commit -A -m 'Added blines.lst' \
+        --date '2001-02-01 05:18' --user $A
+    hg tag blines \
+        --date '2001-02-01 05:19' --user $A
+    hg update -r -2
+    cat chgrepo.zsh | sort | grep 'c' > clines.lst
+    hg commit -A -m 'Added clines.lst' \
+        --date '2001-02-01 14:56' --user $B
+    hg tag clines \
+        --date '2001-02-01 14:56:52' --user $B
+    hg update A
+    hg merge -r B
+    hg commit -m 'Merge from B' \
+        --date '2002-01-01 00:00' --user $C
+    hg merge -r clines
+    hg commit -m 'Merge from C:2' \
+        --date '2002-01-01 00:00:15' --user $C
+    hg update default
+    hg merge -r blines
+    hg commit -m 'Merge from C:1' \
+        --date '2002-01-01 00:00:30' --user $C
+    hg merge -r A
+    hg commit -m 'Merge from A' \
+        --date '2002-01-01 00:00:45' --user $C
+    hg cp hglines.lst hglines2.lst
+    hg commit -A -m 'Copied “hglines.lst” to “hglines2.lst”' \
+        --date '2002-02-10 05:00' --user $A
+    cat chgrepo.zsh | perl -p -i -e 'undef $_ if /^    hg /' > nohglines.lst
+    hg commit -A -m 'Added nohglines.lst' \
+        --date '2002-02-10 15:33' --user $B
+    cat nohglines.lst | rev > nohglinesrev.lst
+    hg commit -A -m 'Added nohglinesrev.lst' \
+        --date '2002-02-10 16:01' --user $B
+    seq 1 10 | tr ' ' $'\n' > ignored10.lst
+    hg commit -A -m 'Added ignored10.lst' \
+        --date '2002-02-11 03:15' --user $A
+    echo $'syntax: glob\nignored*' > .hgignore
+    hg commit -A -m 'Added .hgignore' \
+        --date '2002-02-11 05:43' --user $A
+    echo abc >> nohglinesrev.lst
+    echo 'Def' > addeddef && hg add addeddef
+    hg rm hglines2.lst
+    rm nohglines.lst
+    cat hglines.lst | rev > hglinesrev.lst
+    echo 'Abc' > ignoredabc
+)
+tar cJf testrepo.tar.xz testrepo