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