Mercurial > hg
changeset 4586:1fcc076fcb17
Make parents with a file but not a revision use working directory revision.
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Thu, 14 Jun 2007 10:58:49 -0700 |
parents | 1774c037fbd2 |
children | d8a08b92ad34 1e11e8b6acab |
files | mercurial/commands.py tests/test-parents tests/test-parents.out |
diffstat | 3 files changed, 66 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Mon Jun 04 09:16:53 2007 -0500 +++ b/mercurial/commands.py Thu Jun 14 10:58:49 2007 -0700 @@ -1863,17 +1863,20 @@ def parents(ui, repo, file_=None, **opts): """show the parents of the working dir or revision - Print the working directory's parent revisions. + Print the working directory's parent revisions. If a + revision is given via --rev, the parent of that revision + will be printed. If a file argument is given, revision in + which the file was last changed (before the working directory + revision or the argument to --rev if given) is printed. """ rev = opts.get('rev') - if rev: - if file_: - ctx = repo.filectx(file_, changeid=rev) - else: - ctx = repo.changectx(rev) - p = [cp.node() for cp in ctx.parents()] + if file_: + ctx = repo.filectx(file_, changeid=rev) + elif rev: + ctx = repo.changectx(rev) else: - p = repo.dirstate.parents() + ctx = repo.workingctx() + p = [cp.node() for cp in ctx.parents()] displayer = cmdutil.show_changeset(ui, repo, opts) for n in p:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-parents Thu Jun 14 10:58:49 2007 -0700 @@ -0,0 +1,27 @@ +#!/bin/sh +# test parents command + +hg init a +cd a +echo % no working directory +hg parents + +echo a > a +echo b > b +hg ci -Amab -d '0 0' +echo a >> a +hg ci -Ama -d '1 0' +echo b >> b +hg ci -Amb -d '2 0' + +echo % hg parents +hg parents + +echo % hg parents a +hg parents a + +echo % hg parents -r 2 +hg parents -r 2 + +echo % hg parents -r 2 a +hg parents -r 2 a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-parents.out Thu Jun 14 10:58:49 2007 -0700 @@ -0,0 +1,28 @@ +% no working directory +adding a +adding b +% hg parents +changeset: 2:6cfac479f009 +tag: tip +user: test +date: Thu Jan 01 00:00:02 1970 +0000 +summary: b + +% hg parents a +changeset: 0:b6a1406d8886 +user: test +date: Thu Jan 01 00:00:00 1970 +0000 +summary: ab + +% hg parents -r 2 +changeset: 1:d786049f033a +user: test +date: Thu Jan 01 00:00:01 1970 +0000 +summary: a + +% hg parents -r 2 a +changeset: 0:b6a1406d8886 +user: test +date: Thu Jan 01 00:00:00 1970 +0000 +summary: ab +