1 # -*- encoding: utf-8 -*-
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-10-20 12:31:48$"
5 __doc__ = "Module documentation."
8 from mercurial.node import nullid
10 class MercurialRevision(wlrepo.Revision):
11 def __init__(self, lib, changectx):
12 super(MercurialRevision, self).__init__(lib)
13 self._changectx = changectx
15 branchname = self._changectx.branch()
16 if branchname.startswith("$doc:"):
17 self._docname = branchname[5:]
19 elif branchname.startswith("$user:"):
20 idx = branchname.find("$doc:")
22 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
23 self._username = branchname[6:idx]
24 self._docname = branchname[idx+5:]
26 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
29 def document_name(self):
30 return self._docname and self._docname.decode('utf-8')
34 return self._username and self._username.decode('utf-8')
37 return self._changectx.node()
40 return self._changectx
43 return self._changectx.branch()
47 return self._changectx.date()[0]
49 def __unicode__(self):
50 return u"%s" % self._changectx.hex()
53 return self.__unicode__().encode('utf-8')
56 return "%s" % self._changectx.hex()
58 def ancestorof(self, other):
59 nodes = list(other._changectx._parents)
60 while nodes[0].node() != nullid:
62 if v == self._changectx:
64 nodes.extend( v._parents )
67 def parentof(self, other):
68 return self._changectx in other._changectx._parents
70 def has_common_ancestor(self, other):
71 a = self._changectx.ancestor(other._changectx)
72 return (a.branch() == self._changectx.branch())
74 def has_children(self, limit_branch=False):
75 for child in self._changectx.children():
76 cbranch = child.branch()
77 if (not limit_branch) or (cbranch == self.hgbranch()):
81 def has_parent_from(self, rev):
82 branch = rev.hgbranch()
83 for parent in self._changectx.parents():
84 if parent.branch() == branch:
88 def merge_with(self, other, user, message):
89 message = self._library._sanitize_string(message)
90 lock = self._library.lock(True)
92 self._library._checkout(self._changectx.node())
93 status = self._library._merge(other._changectx.node())
95 self._library._commit(user=user, message=message)
103 parents = self._changectx.parents()
105 if len(parents) == 1:
106 return self._library._revision(parents[0])
108 if parents[0].branch() == self.branch():
109 return self._library._revision(parents[0])
111 return self._library._revision(parents[1])
113 def __eq__(self, other):
114 return self._changectx.node() == other._changectx.node()