+ def update(self):
+ if self._cabinet.is_main():
+ return True # always up-to-date
+
+ mdoc = self.library.document(self._fileid)
+
+ mshelf = mdoc.shelf()
+ shelf = self.shelf()
+
+ if not mshelf.ancestorof(shelf) and not shelf.parentof(mshelf):
+ shelf.merge_with(mshelf)
+
+ return rc.ALL_OK
+
+ def share(self, message, user):
+ if self._cabinet.is_main():
+ return True # always shared
+
+ main = self.shared_version()
+ local = self.shelf()
+
+ no_changes = True
+
+ # Case 1:
+ # * local
+ # |
+ # * <- can also be here!
+ # /|
+ # / |
+ # main * *
+ # | |
+ # The local branch has been recently updated,
+ # so we don't need to update yet again, but we need to
+ # merge down to default branch, even if there was
+ # no commit's since last update
+
+ if main.ancestorof(local):
+ main.merge_with(local, user=user, message=message)
+ no_changes = False
+
+ # Case 2:
+ #
+ # main * * local
+ # |\ |
+ # | \|
+ # | *
+ # | |
+ #
+ # Default has no changes, to update from this branch
+ # since the last merge of local to default.
+ elif main.has_common_ancestor(local):
+ if not local.parentof(main):
+ main.merge_with(local, user=user, message=message)
+ no_changes = False
+
+ # Case 3:
+ # main *
+ # |
+ # * <- this case overlaps with previos one
+ # |\
+ # | \
+ # | * local
+ # | |
+ #
+ # There was a recent merge to the defaul branch and
+ # no changes to local branch recently.
+ #
+ # Use the fact, that user is prepared to see changes, to
+ # update his branch if there are any
+ elif local.ancestorof(main):
+ if not local.parentof(main):
+ local.merge_with(main, user=user, message='Local branch update.')
+ no_changes = False
+ else:
+ local.merge_with(main, user=user, message='Local branch update.')
+
+ self._refresh()
+ local = self.shelf()
+
+ main.merge_with(local, user=user, message=message)
+
+ def shared(self):
+ return self.library.document(self._fileid)
+
+ @property
+ def size(self):
+ return self._filectx.size()
+
+
+ def shelf(self):
+ return self._shelf
+
+ @property
+ def last_modified(self):
+ return self._filectx.date()
+
+ def __str__(self):
+ return u"Document(%s->%s)" % (self._cabinet.name, self._name)
+
+
+class MercurialShelf(wlrepo.Shelf):
+
+ def __init__(self, cabinet, changectx):
+ super(MercurialShelf, self).__init__(cabinet)
+ self._changectx = changectx
+
+ @property
+ def _rev(self):
+ return self._changectx.node()
+
+ def __str__(self):
+ return self._changectx.hex()
+
+
+ def ancestorof(self, other):
+ pass