--- a/mercurial/context.py Sat Sep 30 09:39:44 2006 +0200
+++ b/mercurial/context.py Sat Sep 30 09:46:03 2006 +0200
@@ -32,9 +32,18 @@
self._node = self._repo.lookup(changeid)
self._rev = self._repo.changelog.rev(self._node)
+ def __str__(self):
+ return short(self.node())
+
def __repr__(self):
return "<changectx %s>" % short(self.node())
+ def __eq__(self, other):
+ return self._rev == other._rev
+
+ def __nonzero__(self):
+ return self._rev != -1
+
def changeset(self):
try:
return self._changeset
@@ -127,9 +136,18 @@
else:
raise AttributeError, name
+ def __nonzero__(self):
+ return self._filerev != nullid
+
+ def __str__(self):
+ return "%s@%s" % (self.path(), short(self.node()))
+
def __repr__(self):
return "<filectx %s@%s>" % (self.path(), short(self.node()))
+ def __eq__(self, other):
+ return self._path == other._path and self._changeid == other._changeid
+
def filerev(self): return self._filerev
def filenode(self): return self._filenode
def filelog(self): return self._filelog
--- a/mercurial/localrepo.py Sat Sep 30 09:39:44 2006 +0200
+++ b/mercurial/localrepo.py Sat Sep 30 09:46:03 2006 +0200
@@ -321,6 +321,19 @@
def changectx(self, changeid=None):
return context.changectx(self, changeid)
+ def parents(self, changeid=None):
+ '''
+ get list of changectxs for parents of changeid or working directory
+ '''
+ if changeid is None:
+ pl = self.dirstate.parents()
+ else:
+ n = self.changelog.lookup(changeid)
+ pl = self.changelog.parents(n)
+ if pl[1] == nullid:
+ return [self.changectx(pl[0])]
+ return [self.changectx(pl[0]), self.changectx(pl[1])]
+
def filectx(self, path, changeid=None, fileid=None):
"""changeid can be a changeset revision, node, or tag.
fileid can be a file revision or node."""
--- a/mercurial/merge.py Sat Sep 30 09:39:44 2006 +0200
+++ b/mercurial/merge.py Sat Sep 30 09:46:03 2006 +0200
@@ -320,12 +320,12 @@
### check phase
- pl = repo.dirstate.parents()
- if not overwrite and pl[1] != nullid:
+ pl = repo.parents()
+ if not overwrite and len(pl) > 1:
raise util.Abort(_("outstanding uncommitted merges"))
- p1, p2 = pl[0], node
- pa = repo.changelog.ancestor(p1, p2)
+ p1, p2 = pl[0], repo.changectx(node)
+ pa = p1.ancestor(p2)
# are we going backwards?
backwards = (pa == p2)
@@ -345,17 +345,16 @@
if modified or added or removed:
raise util.Abort(_("outstanding uncommitted changes"))
- m1 = repo.changectx(p1).manifest().copy()
- m2 = repo.changectx(p2).manifest().copy()
- ma = repo.changectx(pa).manifest()
+ m1 = p1.manifest().copy()
+ m2 = p2.manifest().copy()
+ ma = pa.manifest()
# resolve the manifest to determine which files
# we care about merging
repo.ui.note(_("resolving manifests\n"))
repo.ui.debug(_(" overwrite %s branchmerge %s partial %s\n") %
(overwrite, branchmerge, bool(partial)))
- repo.ui.debug(_(" ancestor %s local %s remote %s\n") %
- (short(p1), short(p2), short(pa)))
+ repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (p1, p2, pa))
action = []
copy = {}
@@ -369,7 +368,7 @@
if not branchmerge:
action += forgetremoved(m2, status)
if not (backwards or overwrite):
- copy = findcopies(repo, m1, m2, repo.changelog.rev(pa))
+ copy = findcopies(repo, m1, m2, pa.rev())
action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards)
del m1, m2, ma
@@ -378,10 +377,10 @@
if not branchmerge:
# we don't need to do any magic, just jump to the new rev
- p1, p2 = p2, nullid
+ p1, p2 = p2, repo.changectx(nullid)
- xp1, xp2 = hex(p1), hex(p2)
- if p2 == nullid: xp2 = ''
+ xp1, xp2 = str(p1), str(p2)
+ if not p2: xp2 = ''
repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
@@ -389,7 +388,7 @@
# update dirstate
if not partial:
- repo.dirstate.setparents(p1, p2)
+ repo.dirstate.setparents(p1.node(), p2.node())
recordupdates(repo, action, branchmerge)
if show_stats:
@@ -406,8 +405,7 @@
" you can redo the full merge using:\n"
" hg update -C %s\n"
" hg merge %s\n"
- % (repo.changelog.rev(p1),
- repo.changelog.rev(p2))))
+ % (p1.rev(), p2.rev())))
elif remind:
repo.ui.status(_("(branch merge, don't forget to commit)\n"))
elif unresolved:
--- a/tests/test-hook.out Sat Sep 30 09:39:44 2006 +0200
+++ b/tests/test-hook.out Sat Sep 30 09:46:03 2006 +0200
@@ -62,10 +62,10 @@
precommit.forbid hook
abort: precommit.forbid hook exited with status 1
4:8ea2ef7ad3e8
-preupdate hook: p1=b702efe9688826e3a91283852b328b84dbf37bc2 p2=
+preupdate hook: p1=b702efe96888 p2=
0 files updated, 0 files merged, 2 files removed, 0 files unresolved
-preupdate hook: p1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 p2=
-update hook: p1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 p2= err=0
+preupdate hook: p1=8ea2ef7ad3e8 p2=
+update hook: p1=8ea2ef7ad3e8 p2= err=0
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
3:4c52fb2e4022
prechangegroup.forbid hook