Dodanie metody Editor.XMLModel.update.
[redakcja.git] / lib / wlrepo / mercurial_backend / __init__.py
1 # -*- encoding: utf-8 -*-
2
3 __author__= "Ɓukasz Rekucki"
4 __date__ = "$2009-09-25 09:20:22$"
5 __doc__ = "Module documentation."
6
7 import wlrepo
8 from mercurial.node import nullid
9
10 class MercurialRevision(wlrepo.Revision):
11
12     def __init__(self, lib, changectx):
13         super(MercurialRevision, self).__init__(lib)
14         self._changectx = changectx
15         
16         branchname = self._changectx.branch()
17         if branchname.startswith("$doc:"):
18             self._docname = branchname[5:]
19             self._username = None
20         elif branchname.startswith("$user:"):
21             idx = branchname.find("$doc:")
22             if(idx < 0):
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:]
26         else:
27             raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
28         
29     @property
30     def document_name(self):
31         return self._docname
32
33     @property
34     def user_name(self):
35         return self._username
36
37     def hgrev(self):
38         return self._changectx.node()
39         
40     def hgcontext(self):
41         return self._changectx
42
43     def hgbranch(self):
44         return self._changectx.branch()
45
46     def __unicode__(self):
47         return u"%s" % self._changectx.hex()
48
49     def __repr__(self):
50         return "%s" % self._changectx.hex()
51
52     def ancestorof(self, other):
53         nodes = list(other._changectx._parents)
54         while nodes[0].node() != nullid:
55             v = nodes.pop(0)
56             if v == self._changectx:
57                 return True
58             nodes.extend( v._parents )
59         return False
60
61     def parentof(self, other):
62         return self._changectx in other._changectx._parents
63
64     def has_common_ancestor(self, other):
65         a = self._changectx.ancestor(other._changectx)       
66         return (a.branch() == self._changectx.branch())
67
68     def merge_with(self, other, user, message):
69         lock = self._library.lock(True)
70         try:
71             self._library._checkout(self._changectx.node())
72             status = self._library._merge(other._changectx.node())
73             if status.isclean():
74                 self._library._commit(user=user, message=message)
75                 return (True, True)
76             else:
77                 return (False, False)
78         finally:
79             lock.release()
80
81     def __eq__(self, other):
82         return self._changectx.node() == other._changectx.node()
83
84
85 from wlrepo.mercurial_backend.library import MercurialLibrary
86
87