mercurial/bookmarks.py
changeset 20024 059b695150c2
parent 19951 d51c4d85ec23
child 20025 e8a11791abfc
equal deleted inserted replaced
20023:2771e59afac4 20024:059b695150c2
   236             marks[key] = repo[new].node()
   236             marks[key] = repo[new].node()
   237         marks.write()
   237         marks.write()
   238         return True
   238         return True
   239     finally:
   239     finally:
   240         w.release()
   240         w.release()
       
   241 
       
   242 def compare(repo, srcmarks, dstmarks,
       
   243             srchex=None, dsthex=None, targets=None):
       
   244     '''Compare bookmarks between srcmarks and dstmarks
       
   245 
       
   246     This returns tuple "(addsrc, adddst, advsrc, advdst, diverge,
       
   247     differ, invalid)", each are list of bookmarks below:
       
   248 
       
   249     :addsrc:  added on src side (removed on dst side, perhaps)
       
   250     :adddst:  added on dst side (removed on src side, perhaps)
       
   251     :advsrc:  advanced on src side
       
   252     :advdst:  advanced on dst side
       
   253     :diverge: diverge
       
   254     :differ:  changed, but changeset referred on src is unknown on dst
       
   255     :invalid: unknown on both side
       
   256 
       
   257     Each elements of lists in result tuple is tuple "(bookmark name,
       
   258     changeset ID on source side, changeset ID on destination
       
   259     side)". Each changeset IDs are 40 hexadecimal digit string or
       
   260     None.
       
   261 
       
   262     Changeset IDs of tuples in "addsrc", "adddst", "differ" or
       
   263      "invalid" list may be unknown for repo.
       
   264 
       
   265     This function expects that "srcmarks" and "dstmarks" return
       
   266     changeset ID in 40 hexadecimal digit string for specified
       
   267     bookmark. If not so (e.g. bmstore "repo._bookmarks" returning
       
   268     binary value), "srchex" or "dsthex" should be specified to convert
       
   269     into such form.
       
   270 
       
   271     If "targets" is specified, only bookmarks listed in it are
       
   272     examined.
       
   273     '''
       
   274     if not srchex:
       
   275         srchex = lambda x: x
       
   276     if not dsthex:
       
   277         dsthex = lambda x: x
       
   278 
       
   279     if targets:
       
   280         bset = set(targets)
       
   281     else:
       
   282         srcmarkset = set(srcmarks)
       
   283         dstmarkset = set(dstmarks)
       
   284         bset = srcmarkset ^ dstmarkset
       
   285         for b in srcmarkset & dstmarkset:
       
   286             if srchex(srcmarks[b]) != dsthex(dstmarks[b]):
       
   287                 bset.add(b)
       
   288 
       
   289     results = ([], [], [], [], [], [], [])
       
   290     addsrc = results[0].append
       
   291     adddst = results[1].append
       
   292     advsrc = results[2].append
       
   293     advdst = results[3].append
       
   294     diverge = results[4].append
       
   295     differ = results[5].append
       
   296     invalid = results[6].append
       
   297 
       
   298     for b in sorted(bset):
       
   299         if b not in srcmarks:
       
   300             if b in dstmarks:
       
   301                 adddst((b, None, dsthex(dstmarks[b])))
       
   302             else:
       
   303                 invalid((b, None, None))
       
   304         elif b not in dstmarks:
       
   305             addsrc((b, srchex(srcmarks[b]), None))
       
   306         else:
       
   307             scid = srchex(srcmarks[b])
       
   308             dcid = dsthex(dstmarks[b])
       
   309             if scid in repo and dcid in repo:
       
   310                 sctx = repo[scid]
       
   311                 dctx = repo[dcid]
       
   312                 if sctx.rev() < dctx.rev():
       
   313                     if validdest(repo, sctx, dctx):
       
   314                         advdst((b, scid, dcid))
       
   315                     else:
       
   316                         diverge((b, scid, dcid))
       
   317                 else:
       
   318                     if validdest(repo, dctx, sctx):
       
   319                         advsrc((b, scid, dcid))
       
   320                     else:
       
   321                         diverge((b, scid, dcid))
       
   322             else:
       
   323                 # it is too expensive to examine in detail, in this case
       
   324                 differ((b, scid, dcid))
       
   325 
       
   326     return results
   241 
   327 
   242 def updatefromremote(ui, repo, remotemarks, path):
   328 def updatefromremote(ui, repo, remotemarks, path):
   243     ui.debug("checking for updated bookmarks\n")
   329     ui.debug("checking for updated bookmarks\n")
   244     changed = False
   330     changed = False
   245     localmarks = repo._bookmarks
   331     localmarks = repo._bookmarks