[issue733] hg parents foo does not work as advertised

Patrick Mézard mercurial-bugs at selenic.com
Mon Sep 10 02:33:08 CDT 2007


New submission from Patrick Mézard <pmezard at gmail.com>:

"hg parents foo" currently returns the parent of the revision the file was last
changed by, instead of the revision itself. It is not clear whether:
- This behaviour is useful in any way
- This behaviour should be fixed to match the documentation, possibly as another
command since "parent" would be misleading.
- The documentation should be fixed.

Here is a patch fixing the behaviour in place:

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1985,16 +1985,28 @@ def parents(ui, repo, file_=None, **opts
     revision or the argument to --rev if given) is printed.
     """
     rev = opts.get('rev')
+    if rev:
+        ctx = repo.changectx(rev)
+    else:
+        ctx = repo.workingctx()
+
     if file_:
         files, match, anypats = cmdutil.matchpats(repo, (file_,), opts)
         if anypats or len(files) != 1:
             raise util.Abort(_('can only specify an explicit file name'))
-        ctx = repo.filectx(files[0], changeid=rev)
-    elif rev:
-        ctx = repo.changectx(rev)
+        file_ = files[0]
+        filenodes = []
+        for cp in ctx.parents():
+            try:
+                filenodes.append(cp.filenode(file_))
+            except revlog.LookupError:
+                pass
+        if not filenodes:
+            raise util.Abort(_("'%s' not found in manifest") % file_)
+        fl = repo.file(file_)
+        p = [repo.lookup(fl.linkrev(fn)) for fn in filenodes]
     else:
-        ctx = repo.workingctx()
-    p = [cp.node() for cp in ctx.parents()]
+        p = [cp.node() for cp in ctx.parents()]
 
     displayer = cmdutil.show_changeset(ui, repo, opts)
     for n in p:

----------
messages: 3984
nosy: pmezard
priority: bug
status: unread
title: hg parents foo does not work as advertised
topic: documentation, ui

____________________________________________________
Mercurial issue tracker <mercurial-bugs at selenic.com>
<http://www.selenic.com/mercurial/bts/issue733>
____________________________________________________



More information about the Mercurial-devel mailing list