comparison MoinMoin/action/SyncPages.py @ 1304:f103cf7c371e

Detect renamed pages. Changed the getDiff interface.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Thu, 17 Aug 2006 00:00:57 +0200
parents a0b8e78621d0
children a36c70e5f0dd
comparison
equal deleted inserted replaced
1303:a0b8e78621d0 1304:f103cf7c371e
131 return self.page.send_page(self.request, msg=msg) 131 return self.page.send_page(self.request, msg=msg)
132 132
133 def sync(self, params, local, remote): 133 def sync(self, params, local, remote):
134 """ This method does the syncronisation work. 134 """ This method does the syncronisation work.
135 Currently, it handles the case where the pages exist on both sides. 135 Currently, it handles the case where the pages exist on both sides.
136 One of the major missing parts is rename handling.
136 Now there are a few other cases left that have to be implemented: 137 Now there are a few other cases left that have to be implemented:
137 Wiki A | Wiki B | Remark 138 Wiki A | Wiki B | Remark
138 ----------+----------+------------------------------ 139 ----------+----------+------------------------------
139 exists | deleted | In this case, we do a normal merge if there 140 exists | deleted | In this case, we do a normal merge if there
140 | | are no tags. If there were changes in 141 | | are no tags. If there were changes in
157 | | gathered from tags). 158 | | gathered from tags).
158 ----------+----------+------------------------------- 159 ----------+----------+-------------------------------
159 exists | any case | Try a rename search first, then 160 exists | any case | Try a rename search first, then
160 | | do a sync without considering tags 161 | | do a sync without considering tags
161 with tags | with non | to ensure data integrity. 162 with tags | with non | to ensure data integrity.
162 | matching | 163 | matching | Hmm, how do we detect this
163 | tags | 164 | tags | case if the unmatching tags are only on the remote side?
164 ----------+----------+------------------------------- 165 ----------+----------+-------------------------------
165 exists | exists | already handled. 166 exists | exists | already handled.
166 """ 167 """
167 _ = self.request.getText 168 _ = self.request.getText
168 direction = params["direction"] 169 direction = params["direction"]
211 match_direction = None 212 match_direction = None
212 matching_tags = tags.fetch(iwid_full=remote.iwid_full,direction=match_direction) 213 matching_tags = tags.fetch(iwid_full=remote.iwid_full,direction=match_direction)
213 matching_tags.sort() 214 matching_tags.sort()
214 #print "------ TAGS: " + repr(matching_tags) + repr(tags.tags) 215 #print "------ TAGS: " + repr(matching_tags) + repr(tags.tags)
215 216
216 if not matching_tags: 217 # some default values for non matching tags
217 remote_rev = None 218 normalised_name = None
218 local_rev = rp.local_rev # merge against the newest version 219 remote_rev = None
219 old_contents = "" 220 local_rev = rp.local_rev # merge against the newest version
220 else: 221 old_contents = ""
222
223 if matching_tags:
221 newest_tag = matching_tags[-1] 224 newest_tag = matching_tags[-1]
222 # XXX check the tag.normalised_name here 225
223 local_rev = newest_tag.current_rev 226 # handle some cases where we cannot continue for this page
224 remote_rev = newest_tag.remote_rev 227 if newest_tag.remote_rev == rp.remote_rev and (direction == DOWN or newest_tag.current_rev == current_rev):
225 if remote_rev == rp.remote_rev and (direction == DOWN or local_rev == current_rev):
226 continue # no changes done, next page 228 continue # no changes done, next page
227 if rp.local_mime_type != MIMETYPE_MOIN and not (remote_rev == rp.remote_rev ^ local_rev == current_rev): 229 if rp.local_mime_type != MIMETYPE_MOIN and not (newest_tag.remote_rev == rp.remote_rev ^ newest_tag.current_rev == current_rev):
228 self.log_status(ActionClass.WARN, _("The item %(pagename)s cannot be merged but was changed in both wikis. Please delete it in one of both wikis and try again.") % {"pagename": rp.name}) 230 self.log_status(ActionClass.WARN, _("The item %(pagename)s cannot be merged but was changed in both wikis. Please delete it in one of both wikis and try again.") % {"pagename": rp.name})
229 continue 231 continue
230 if rp.local_mime_type != rp.remote_mime_type: 232 if rp.local_mime_type != rp.remote_mime_type:
231 self.log_status(ActionClass.WARN, _("The item %(pagename)s has different mime types in both wikis and cannot be merged. Please delete it in one of both wikis or unify the mime type, and try again.") % {"pagename": rp.name}) 233 self.log_status(ActionClass.WARN, _("The item %(pagename)s has different mime types in both wikis and cannot be merged. Please delete it in one of both wikis or unify the mime type, and try again.") % {"pagename": rp.name})
232 continue 234 continue
233 old_contents = Page(self.request, local_pagename, rev=local_rev).get_raw_body_str() # YYY direct access 235 if newest_tag.normalised_name != rp.name:
236 self.log_status(ActionClass.WARN, _("The item %(pagename)s was renamed locally. This is not implemented yet. Therefore all syncronisation history is lost for this page.") % {"pagename": rp.name}) # XXX implement renames
237 else:
238 normalised_name = newest_tag.normalised_name
239 local_rev = newest_tag.current_rev
240 remote_rev = newest_tag.remote_rev
241 old_contents = Page(self.request, local_pagename, rev=newest_tag.current_rev).get_raw_body_str() # YYY direct access
234 242
235 self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_name}) 243 self.log_status(ActionClass.INFO, _("Synchronising page %(pagename)s with remote page %(remotepagename)s ...") % {"pagename": local_pagename, "remotepagename": rp.remote_name})
236 244
237 if direction == DOWN: 245 if direction == DOWN:
238 remote_rev = None # always fetch the full page, ignore remote conflict check 246 remote_rev = None # always fetch the full page, ignore remote conflict check
239 patch_base_contents = "" 247 patch_base_contents = ""
240 else: 248 else:
241 patch_base_contents = old_contents 249 patch_base_contents = old_contents
242 250
243 if remote_rev != rp.remote_rev: 251 if remote_rev != rp.remote_rev:
244 diff_result = remote.get_diff(rp.remote_name, remote_rev, None) # XXX might raise ALREADY_CURRENT 252 diff_result = remote.get_diff(rp.remote_name, remote_rev, None, normalised_name)
253 if diff_result is None:
254 self.log_status(ActionClass.ERROR, _("The page %(pagename)s could not be synced. The remote page was renamed. This is not supported yet. You may want to delete one of the pages to get it synced.") % {"pagename": rp.remote_name})
255 continue
245 is_remote_conflict = diff_result["conflict"] 256 is_remote_conflict = diff_result["conflict"]
246 assert diff_result["diffversion"] == 1 257 assert diff_result["diffversion"] == 1
247 diff = diff_result["diff"] 258 diff = diff_result["diff"]
248 current_remote_rev = diff_result["current"] 259 current_remote_rev = diff_result["current"]
249 else: 260 else: