1 # -*- encoding: utf-8 -*-
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-25 09:20:22$"
5 __doc__ = "Module documentation."
8 from mercurial.node import nullid
10 class MercurialRevision(wlrepo.Revision):
12 def __init__(self, lib, changectx):
13 super(MercurialRevision, self).__init__(lib)
14 self._changectx = changectx
16 branchname = self._changectx.branch()
17 if branchname.startswith("$doc:"):
18 self._docname = branchname[5:]
20 elif branchname.startswith("$user:"):
21 idx = branchname.find("$doc:")
23 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
24 self._username = branchname[6:idx]
25 self._docname = branchname[idx+5:]
27 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
30 def document_name(self):
31 return self._docname and self._docname.decode('utf-8')
35 return self._username and self._username.decode('utf-8')
38 return self._changectx.node()
41 return self._changectx
44 return self._changectx.branch()
48 return self._changectx.date()[0]
50 def __unicode__(self):
51 return u"%s" % self._changectx.hex()
54 return self.__unicode__().encode('utf-8')
57 return "%s" % self._changectx.hex()
59 def ancestorof(self, other):
60 nodes = list(other._changectx._parents)
61 while nodes[0].node() != nullid:
63 if v == self._changectx:
65 nodes.extend( v._parents )
68 def parentof(self, other):
69 return self._changectx in other._changectx._parents
71 def has_common_ancestor(self, other):
72 a = self._changectx.ancestor(other._changectx)
73 return (a.branch() == self._changectx.branch())
75 def has_children(self):
76 return bool(self._library._hgrepo.changelog.children(self.hgrev()))
78 def merge_with(self, other, user, message):
79 lock = self._library.lock(True)
81 self._library._checkout(self._changectx.node())
82 status = self._library._merge(other._changectx.node())
84 self._library._commit(user=user, message=message)
91 def __eq__(self, other):
92 return self._changectx.node() == other._changectx.node()
95 from wlrepo.mercurial_backend.library import MercurialLibrary