# HG changeset patch # User Thomas Arendsen Hein # Date 1183457665 -7200 # Node ID 8b90d763ea9032d40f4c6c72c7228224e84ae5ae # Parent 37e11c768db912f3fcbbd24b9e2f956db048f805 Add extension to provide the 'hg children' command (with tests) diff --git a/hgext/children.py b/hgext/children.py new file mode 100644 --- /dev/null +++ b/hgext/children.py @@ -0,0 +1,45 @@ +# Mercurial extension to provide the 'hg children' command +# +# Copyright 2007 by Intevation GmbH +# Author(s): +# Thomas Arendsen Hein +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + +from mercurial import cmdutil, util +from mercurial.i18n import _ +from mercurial.node import nullid + + +def children(ui, repo, file_=None, **opts): + """show the children of the given or working dir revision + + Print the children of the working directory's revisions. + If a revision is given via --rev, the children of that revision + will be printed. If a file argument is given, revision in + which the file was last changed (after the working directory + revision or the argument to --rev if given) is printed. + """ + rev = opts.get('rev') + if file_: + ctx = repo.filectx(file_, changeid=rev) + else: + ctx = repo.changectx(rev) + if ctx.node() == nullid: + raise util.Abort(_("All non-merge changesets are children of " + "the null revision!")) + + displayer = cmdutil.show_changeset(ui, repo, opts) + for node in [cp.node() for cp in ctx.children()]: + displayer.show(changenode=node) + + +cmdtable = { + "children": + (children, + [('r', 'rev', '', _('show children of the specified rev')), + ('', 'style', '', _('display using template map file')), + ('', 'template', '', _('display with template'))], + _('hg children [-r REV] [FILE]')), +} diff --git a/tests/test-children b/tests/test-children new file mode 100755 --- /dev/null +++ b/tests/test-children @@ -0,0 +1,59 @@ +#!/bin/sh +# test children command + +cat <> $HGRCPATH +[extensions] +hgext.children= +EOF + +echo "% init" +hg init t +cd t + +echo "% no working directory" +hg children + +echo % setup +echo 0 > file0 +hg ci -qAm 0 -d '0 0' + +echo 1 > file1 +hg ci -qAm 1 -d '1 0' + +echo 2 >> file0 +hg ci -qAm 2 -d '2 0' + +hg co null +echo 3 > file3 +hg ci -qAm 3 -d '3 0' + +echo "% hg children at revision 3 (tip)" +hg children + +hg co null +echo "% hg children at nullrev (should be 0 and 3)" +hg children + +hg co 1 +echo "% hg children at revision 1 (should be 2)" +hg children + +hg co 2 +echo "% hg children at revision 2 (other head)" +hg children + +for i in null 0 1 2 3; do + echo "% hg children -r $i" + hg children -r $i +done + +echo "% hg children -r 0 file0 (should be 2)" +hg children -r 0 file0 + +echo "% hg children -r 1 file0 (should be 2)" +hg children -r 1 file0 + +hg co 0 +echo "% hg children file0 at revision 0 (should be 2)" +hg children file0 + diff --git a/tests/test-children.out b/tests/test-children.out new file mode 100644 --- /dev/null +++ b/tests/test-children.out @@ -0,0 +1,52 @@ +% init +% no working directory +abort: All non-merge changesets are children of the null revision! +% setup +0 files updated, 0 files merged, 2 files removed, 0 files unresolved +% hg children at revision 3 (tip) +0 files updated, 0 files merged, 1 files removed, 0 files unresolved +% hg children at nullrev (should be 0 and 3) +2 files updated, 0 files merged, 0 files removed, 0 files unresolved +% hg children at revision 1 (should be 2) +changeset: 2:8f5eea5023c2 +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: 2 + +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +% hg children at revision 2 (other head) +% hg children -r null +abort: All non-merge changesets are children of the null revision! +% hg children -r 0 +changeset: 1:708c093edef0 +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: 1 + +% hg children -r 1 +changeset: 2:8f5eea5023c2 +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: 2 + +% hg children -r 2 +% hg children -r 3 +% hg children -r 0 file0 (should be 2) +changeset: 2:8f5eea5023c2 +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: 2 + +% hg children -r 1 file0 (should be 2) +changeset: 2:8f5eea5023c2 +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: 2 + +1 files updated, 0 files merged, 1 files removed, 0 files unresolved +% hg children file0 at revision 0 (should be 2) +changeset: 2:8f5eea5023c2 +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: 2 +