1 # -*- encoding: utf-8 -*-
4 log = logging.getLogger('ral.mercurial')
6 __author__= "Łukasz Rekucki"
7 __date__ = "$2009-09-25 09:20:22$"
8 __doc__ = "Module documentation."
11 from mercurial.node import nullid
13 from mercurial import encoding
14 encoding.encoding = 'utf-8'
16 class MercurialRevision(wlrepo.Revision):
18 def __init__(self, lib, changectx):
19 super(MercurialRevision, self).__init__(lib)
20 self._changectx = changectx
22 branchname = self._changectx.branch()
23 if branchname.startswith("$doc:"):
24 self._docname = branchname[5:]
26 elif branchname.startswith("$user:"):
27 idx = branchname.find("$doc:")
29 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
30 self._username = branchname[6:idx]
31 self._docname = branchname[idx+5:]
33 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
36 def document_name(self):
37 return self._docname and self._docname.decode('utf-8')
41 return self._username and self._username.decode('utf-8')
44 return self._changectx.node()
47 return self._changectx
50 return self._changectx.branch()
54 return self._changectx.date()[0]
56 def __unicode__(self):
57 return u"%s" % self._changectx.hex()
60 return self.__unicode__().encode('utf-8')
63 return "%s" % self._changectx.hex()
65 def ancestorof(self, other):
66 nodes = list(other._changectx._parents)
67 while nodes[0].node() != nullid:
69 if v == self._changectx:
71 nodes.extend( v._parents )
74 def parentof(self, other):
75 return self._changectx in other._changectx._parents
77 def has_common_ancestor(self, other):
78 a = self._changectx.ancestor(other._changectx)
79 return (a.branch() == self._changectx.branch())
81 def has_children(self):
82 return bool(self._library._hgrepo.changelog.children(self.hgrev()))
84 def merge_with(self, other, user, message):
85 message = self._library._sanitize_string(message)
86 lock = self._library.lock(True)
88 self._library._checkout(self._changectx.node())
89 status = self._library._merge(other._changectx.node())
91 self._library._commit(user=user, message=message)
98 def __eq__(self, other):
99 return self._changectx.node() == other._changectx.node()
102 from wlrepo.mercurial_backend.library import MercurialLibrary