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