changeset 3:04c4cfd17ff4

commands: add several new commands tdefpath, tdiff, tlog, tparents, tsummary, ttip
author jcoomes
date Wed, 29 Dec 2010 16:30:24 -0800
parents d25e9dd2fcb6
children 579633139692
files tests/test-trees-local.t trees.py
diffstat 2 files changed, 217 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-trees-local.t	Mon Dec 20 13:27:14 2010 -0800
+++ b/tests/test-trees-local.t	Wed Dec 29 16:30:24 2010 -0800
@@ -569,10 +569,32 @@
   adding file changes
   added 2 changesets with 1 changes to 1 files
 
-  $ for sr in s2 s2/s2.2 s2/s2.2/s2.2.1
-  > do
-  >     hg -R r1/$sr tip
-  > done
+  $ hg -R r1 ttip
+  [$TESTTMP/r1]:
+  changeset:   0:8d066171e5de
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     r1
+  
+  
+  [$TESTTMP/r1/s1]:
+  changeset:   0:30b4bf8cd1c5
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     r1/s1
+  
+  
+  [$TESTTMP/r1/s1/s1.1 with spaces]:
+  changeset:   0:898fb1dda185
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     r1/s1/s1.1 with spaces
+  
+  
+  [$TESTTMP/r1/s2]:
   changeset:   3:3d0a1cb52bf2
   tag:         tip
   parent:      2:02ac722f677c
@@ -581,6 +603,16 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     merge with r1
   
+  
+  [$TESTTMP/r1/s2/s2.1]:
+  changeset:   0:ed63cc458a75
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     r1/s2/s2.1
+  
+  
+  [$TESTTMP/r1/s2/s2.2]:
   changeset:   3:76fc250030c4
   tag:         tip
   parent:      2:b9139c2dc588
@@ -589,6 +621,8 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     merge with r1
   
+  
+  [$TESTTMP/r1/s2/s2.2/s2.2.1]:
   changeset:   3:015d691fdafe
   tag:         tip
   parent:      2:c0662346bf9f
@@ -673,7 +707,7 @@
   [$TESTTMP/r135/s5]:
   default = $TESTTMP/rflat/s5
 
-Test tcommand, tstatus, ttag, tupdate.
+Test tcommand, tparents, tstatus, ttag, tupdate.
 
   $ hg tlist -R r135
   $TESTTMP/r135
@@ -693,7 +727,7 @@
   [$TESTTMP/r135/s5]:
   $TESTTMP/r135/s5
   $ hg tstat -R r135 -q
-  $ hg tcomm -R r135 -q -- touch xyz
+  $ hg tcomm -R r135 -q -- sh -c 'echo foo > xyz'
   $ hg tstat -R r135
   [$TESTTMP/r135]:
   ? xyz
@@ -719,6 +753,34 @@
   
   [$TESTTMP/r135/s5]:
   A xyz
+  $ hg tdiff -R r135 --nodates
+  [$TESTTMP/r135]:
+  diff -r cb6a7267a0e3 xyz
+  --- /dev/null
+  +++ b/xyz
+  @@ -0,0 +1,1 @@
+  +foo
+  
+  [$TESTTMP/r135/s1]:
+  diff -r 5be808557fcc xyz
+  --- /dev/null
+  +++ b/xyz
+  @@ -0,0 +1,1 @@
+  +foo
+  
+  [$TESTTMP/r135/s3]:
+  diff -r 16d0c651073b xyz
+  --- /dev/null
+  +++ b/xyz
+  @@ -0,0 +1,1 @@
+  +foo
+  
+  [$TESTTMP/r135/s5]:
+  diff -r 87710fdf686c xyz
+  --- /dev/null
+  +++ b/xyz
+  @@ -0,0 +1,1 @@
+  +foo
   $ hg tcomm -R r135 -q -- hg commit -m 'add xyz'
   $ hg tstat -R r135 -q
   $ hg ttag  -R r135 -d '0 0' xyz
@@ -729,15 +791,15 @@
   [$TESTTMP/r135/s3]:
   
   [$TESTTMP/r135/s5]:
-  $ hg tcomm -R r135 -- hg log -l 2
+  $ hg tlog  -R r135 -l 2
   [$TESTTMP/r135]:
-  changeset:   2:83290f94fb2b
+  changeset:   2:4ced22f7af69
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     Added tag xyz for changeset b0a2d2266db8
+  summary:     Added tag xyz for changeset 7daa537724f7
   
-  changeset:   1:b0a2d2266db8
+  changeset:   1:7daa537724f7
   tag:         xyz
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
@@ -745,13 +807,13 @@
   
   
   [$TESTTMP/r135/s1]:
-  changeset:   2:5e30e7223a0b
+  changeset:   2:4031d5de603a
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     Added tag xyz for changeset f1afd954409a
+  summary:     Added tag xyz for changeset 7ee3e2b9a80f
   
-  changeset:   1:f1afd954409a
+  changeset:   1:7ee3e2b9a80f
   tag:         xyz
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
@@ -759,13 +821,13 @@
   
   
   [$TESTTMP/r135/s3]:
-  changeset:   2:8c6b313fb499
+  changeset:   2:75a448015ccf
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     Added tag xyz for changeset e16257c3cacc
+  summary:     Added tag xyz for changeset e0644cb753a1
   
-  changeset:   1:e16257c3cacc
+  changeset:   1:e0644cb753a1
   tag:         xyz
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
@@ -773,40 +835,104 @@
   
   
   [$TESTTMP/r135/s5]:
-  changeset:   2:c2c28aac7653
+  changeset:   2:764efa1ac652
   tag:         tip
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
-  summary:     Added tag xyz for changeset add70ffe0e61
+  summary:     Added tag xyz for changeset 3abbfd61fcf3
+  
+  changeset:   1:3abbfd61fcf3
+  tag:         xyz
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add xyz
+  
+  $ hg tup   -R r135 1
+  [$TESTTMP/r135]:
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  
+  [$TESTTMP/r135/s1]:
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  
+  [$TESTTMP/r135/s3]:
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   
-  changeset:   1:add70ffe0e61
+  [$TESTTMP/r135/s5]:
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg tparents -R r135
+  [$TESTTMP/r135]:
+  changeset:   1:7daa537724f7
+  tag:         xyz
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add xyz
+  
+  
+  [$TESTTMP/r135/s1]:
+  changeset:   1:7ee3e2b9a80f
+  tag:         xyz
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add xyz
+  
+  
+  [$TESTTMP/r135/s3]:
+  changeset:   1:e0644cb753a1
   tag:         xyz
   user:        test
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     add xyz
   
-  $ hg tup   -R r135 null
+  
+  [$TESTTMP/r135/s5]:
+  changeset:   1:3abbfd61fcf3
+  tag:         xyz
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add xyz
+  
+  $ hg tup   -R r135
   [$TESTTMP/r135]:
-  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   
   [$TESTTMP/r135/s1]:
-  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   
   [$TESTTMP/r135/s3]:
-  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   
   [$TESTTMP/r135/s5]:
-  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
-  $ hg tup   -R r135
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg tparents -R r135
   [$TESTTMP/r135]:
-  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  changeset:   2:4ced22f7af69
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     Added tag xyz for changeset 7daa537724f7
+  
   
   [$TESTTMP/r135/s1]:
-  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  changeset:   2:4031d5de603a
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     Added tag xyz for changeset 7ee3e2b9a80f
+  
   
   [$TESTTMP/r135/s3]:
-  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  changeset:   2:75a448015ccf
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     Added tag xyz for changeset e0644cb753a1
+  
   
   [$TESTTMP/r135/s5]:
-  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  changeset:   2:764efa1ac652
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     Added tag xyz for changeset 3abbfd61fcf3
+  
 
--- a/trees.py	Mon Dec 20 13:27:14 2010 -0800
+++ b/trees.py	Wed Dec 29 16:30:24 2010 -0800
@@ -32,6 +32,7 @@
 
 from mercurial import cmdutil
 from mercurial import commands
+from mercurial import extensions
 from mercurial import hg
 from mercurial import pushkey
 from mercurial import ui
@@ -284,6 +285,20 @@
             l = _shortpaths(repo.root, _walk(ui, repo, {}))[1:]
         return _writeconfig(repo, l)
 
+def diff(ui, repo, *args, **opts):
+    '''diff repository (or selected files)'''
+    _checklocal(repo)
+    return _docmd1(_origcmd('diff'), ui, repo, *args, **opts)
+
+def heads(ui, repo, *branchrevs, **opts):
+    '''show current repository heads or show branch heads'''
+    _checklocal(repo)
+    st = opts.get('subtrees')
+    repocount = len(_list(ui, repo, st and {'subtrees': st} or {}))
+    rc = _docmd1(_origcmd('heads'), ui, repo, *branchrevs, **opts)
+    # return 0 if any of the repos have matching heads; 1 otherwise.
+    return int(rc == repocount)
+
 def incoming(ui, repo, remote="default", **opts):
     '''show new changesets found in source'''
     _checklocal(repo)
@@ -328,6 +343,11 @@
         ui.write(subtree + '\n')
     return 0
 
+def log(ui, repo, *args, **opts):
+    '''show revision history of entire repository or files'''
+    _checklocal(repo)
+    return _docmd1(_origcmd('log'), ui, repo, *args, **opts)
+
 def outgoing(ui, repo, remote=None, **opts):
     '''show changesets not found in the destination'''
     _checklocal(repo)
@@ -338,6 +358,10 @@
     # return 0 if any of the repos have outgoing changes; 1 otherwise.
     return int(rc == repocount)
 
+def parents(ui, repo, filename=None, **opts):
+    _checklocal(repo)
+    return _docmd1(_origcmd('parents'), ui, repo, filename, **opts)
+
 def _paths(cmd, ui, repo, search=None, **opts):
     ui.status('[%s]:\n' % repo.root)
     cmd(ui, repo, search)
@@ -380,11 +404,21 @@
     _checklocal(repo)
     return _docmd1(_origcmd('status'), ui, repo, *args, **opts)
 
+def summary(ui, repo, **opts):
+    """summarize working directory state"""
+    _checklocal(repo)
+    return _docmd1(_origcmd('summary'), ui, repo, **opts)
+
 def tag(ui, repo, name1, *names, **opts):
     '''add one or more tags for the current or given revision'''
     _checklocal(repo)
     return _docmd1(_origcmd('tag'), ui, repo, name1, *names, **opts)
 
+def tip(ui, repo, **opts):
+    '''show the tip revision'''
+    _checklocal(repo)
+    return _docmd1(_origcmd('tip'), ui, repo, **opts)
+
 def _update(cmd, ui, repo, node=None, rev=None, clean=False, date=None,
             check=False, **opts):
     ui.status('[%s]:\n' % repo.root)
@@ -409,6 +443,12 @@
     '''show version information'''
     ui.status('trees extension (version 0.7)\n')
 
+def defpath(ui, repo, peer=None, peer_push=None, **opts):
+    '''examine and manipulate default path settings for a tree.'''
+    def walker(r):
+        return _list(ui, r, opts)
+    return defpath_mod.defpath(ui, repo, peer, peer_push, walker, opts)
+
 def debugkeys(ui, src, **opts):
     d = hg.repository(ui, src).listkeys('trees')
     i = 0
@@ -453,28 +493,49 @@
     return (newfunc, cte[1] + extraopts, synopsis)
 
 def extsetup(ui = None):
-    global cmdtable
     # The cmdtable is initialized here to pick up options added by other
     # extensions (e.g., rebase, bookmarks).
     #
     # Commands tagged with '^' are listed by 'hg help'.
+    global defpath_mod
+    defpath_mod = None
+    defpath_opts = []
+    try:
+        defpath_mod = extensions.find('defpath')
+        defpath_opts = __builtin__.list(defpath_mod.opts)
+        defpath_doc = getattr(defpath_mod, 'common_docstring', '')
+        if defpath_doc:
+            defpath.__doc__ += defpath_doc
+    except:
+        pass
+
+    global cmdtable
     cmdtable = {
         '^tclone': _newcte('clone', clone, subtreesopt,
                            _('[OPTION]... SOURCE [DEST [SUBTREE]...]')),
         'tcommand': (command, commandopts, _('command [arg] ...')),
         'tconfig': (config, configopts, _('[OPTION]... [SUBTREE]...')),
+        'tdiff': _newcte('diff', diff, subtreesopt),
+        'theads': _newcte('heads', heads, subtreesopt),
         'tincoming': _newcte('incoming', incoming, subtreesopt),
         'toutgoing': _newcte('outgoing', outgoing, subtreesopt),
         'tlist': (list, listopts, _('[OPTION]...')),
+        '^tlog': _newcte('log', log, subtreesopt),
+        'tparents': _newcte('parents', parents, subtreesopt),
         'tpaths': _newcte('paths', paths, subtreesopt),
         '^tpull': _newcte('pull', pull, subtreesopt),
         '^tpush': _newcte('push', push, subtreesopt),
         '^tstatus': _newcte('status', status, subtreesopt),
         '^tupdate': _newcte('update', update, subtreesopt),
         'ttag': _newcte('tag', tag, subtreesopt),
+        'ttip': _newcte('tip', tip, subtreesopt),
         'tversion': (version, [], ''),
         'tdebugkeys': (debugkeys, [], '')
     }
+    if defpath_mod:
+        cmdtable['tdefpath'] = (defpath, defpath_opts, _(''))
+    if getattr(commands, 'summary', None):
+        cmdtable['tsummary'] = _newcte('summary', summary, subtreesopt)
 
 commands.norepo += ' tclone tversion tdebugkeys'