1 # -*- encoding: utf-8 -*-
3 __author__ = "Ćukasz Rekucki"
4 __date__ = "$2009-09-25 09:35:06$"
5 __doc__ = "Module documentation."
9 class MercurialDocument(wlrepo.Document):
11 def data(self, entry):
12 path = self._revision._docname + '.' + entry
13 return self._library._filectx(path, \
14 self._revision.hgrev()).data()
16 def quickwrite(self, entry, data, msg, user=None):
17 user = user or self.owner
19 raise ValueError("Can't determine user.")
22 f = l._fileopen(r(entry), "w+")
27 return self.invoke_and_commit(write, lambda d: (msg, user))
29 def invoke_and_commit(self, ops, before_commit):
30 lock = self._library._lock()
32 self._library._checkout(self._revision.hgrev())
34 def entry_path(entry):
35 return self.id + '.' + entry
37 ops(self._library, entry_path)
38 message, user = before_commit(self)
39 self._library._commit(message, user)
41 return self._library.document(docid=self.id, user=self.owner)
45 # def commit(self, message, user):
46 # """Make a new commit."""
47 # self.invoke_and_commit(message, user, lambda *a: True)
50 return self._revision.user_name() is None
55 return self._library.document(docid=self._revision.document_name())
58 fullid = self._library.fulldocid(self.id, user)
60 def take_action(library, resolve):
62 library._create_branch(fullid, parent=self._revision)
64 if not self._library.has_revision(fullid):
65 self.invoke_and_commit(take_action, \
66 lambda d: ("$AUTO$ File checkout.", user) )
68 return self._library.document_for_rev(fullid)
70 def update(self, user):
71 """Update parts of the document."""
72 lock = self.library._lock()
75 # main revision of the document
78 if self._revision.has_children():
79 # can't update non-latest revision
84 if not sv.ancestorof(self) and not self.parentof(sv):
85 self._revision.merge_with(sv._revision, user=user)
91 def share(self, message):
92 lock = self.library._lock()
95 return True # always shared
97 user = self._revision.user_name()
99 main = self.shared()._revision
100 local = self._revision
107 # * <- can also be here!
112 # The local branch has been recently updated,
113 # so we don't need to update yet again, but we need to
114 # merge down to default branch, even if there was
115 # no commit's since last update
117 if main.ancestorof(local):
119 main.merge_with(local, user=user, message=message)
129 # Default has no changes, to update from this branch
130 # since the last merge of local to default.
131 elif local.has_common_ancestor(main):
133 if not local.parentof(main):
134 main.merge_with(local, user=user, message=message)
140 # * <- this case overlaps with previos one
146 # There was a recent merge to the defaul branch and
147 # no changes to local branch recently.
149 # Use the fact, that user is prepared to see changes, to
150 # update his branch if there are any
151 elif local.ancestorof(main):
153 if not local.parentof(main):
154 local.merge_with(main, user=user, message='Local branch update.')
158 local.merge_with(main, user=user, message='Local branch update.')
160 main.merge_with(local, user=user, message=message)
162 print "no_changes: ", no_changes
168 return u"Document(%s:%s)" % (self.name, self.owner)
170 def __eq__(self, other):
171 return (self._revision == other._revision) and (self.name == other.name)