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 from mercurial import encoding
11 encoding.encoding = 'utf-8'
13 class MercurialRevision(wlrepo.Revision):
15 def __init__(self, lib, changectx):
16 super(MercurialRevision, self).__init__(lib)
17 self._changectx = changectx
19 branchname = self._changectx.branch()
20 if branchname.startswith("$doc:"):
21 self._docname = branchname[5:]
23 elif branchname.startswith("$user:"):
24 idx = branchname.find("$doc:")
26 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
27 self._username = branchname[6:idx]
28 self._docname = branchname[idx+5:]
30 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
33 def document_name(self):
34 return self._docname and self._docname.decode('utf-8')
38 return self._username and self._username.decode('utf-8')
41 return self._changectx.node()
44 return self._changectx
47 return self._changectx.branch()
51 return self._changectx.date()[0]
53 def __unicode__(self):
54 return u"%s" % self._changectx.hex()
57 return self.__unicode__().encode('utf-8')
60 return "%s" % self._changectx.hex()
62 def ancestorof(self, other):
63 nodes = list(other._changectx._parents)
64 while nodes[0].node() != nullid:
66 if v == self._changectx:
68 nodes.extend( v._parents )
71 def parentof(self, other):
72 return self._changectx in other._changectx._parents
74 def has_common_ancestor(self, other):
75 a = self._changectx.ancestor(other._changectx)
76 return (a.branch() == self._changectx.branch())
78 def has_children(self):
79 return bool(self._library._hgrepo.changelog.children(self.hgrev()))
81 def merge_with(self, other, user, message):
82 message = self._library._sanitize_string(message)
83 lock = self._library.lock(True)
85 self._library._checkout(self._changectx.node())
86 status = self._library._merge(other._changectx.node())
88 self._library._commit(user=user, message=message)
95 def __eq__(self, other):
96 return self._changectx.node() == other._changectx.node()
99 from wlrepo.mercurial_backend.library import MercurialLibrary