comparison mercurial/localrepo.py @ 3292:764688cf51e5

merge: remember rename copies and parents properly on commit record copies in dirstate even if rename was remote this lets us record it properly at commit teach checkfilemerge about copies, including merge cases pull old copy code out of commit extend rename-merge1 test to show file index
author Matt Mackall <mpm@selenic.com>
date Sun, 08 Oct 2006 19:57:45 -0500
parents a184cd0c2db9
children 4546a5e31cb8
comparison
equal deleted inserted replaced
3291:0b5d626b354e 3292:764688cf51e5
460 return self.do_lock("wlock", wait, self.dirstate.write, 460 return self.do_lock("wlock", wait, self.dirstate.write,
461 self.wreload, 461 self.wreload,
462 desc=_('working directory of %s') % self.origroot) 462 desc=_('working directory of %s') % self.origroot)
463 463
464 def checkfilemerge(self, filename, text, filelog, manifest1, manifest2): 464 def checkfilemerge(self, filename, text, filelog, manifest1, manifest2):
465 "determine whether a new filenode is needed" 465 """
466 Determine whether a new filenode is needed and what parent
467 and rename information is needed for a file commit.
468
469 Returns (old entry, file parent 1, file parent 2, metadata)
470
471 If old entry is not None, a commit is not needed.
472 """
466 fp1 = manifest1.get(filename, nullid) 473 fp1 = manifest1.get(filename, nullid)
467 fp2 = manifest2.get(filename, nullid) 474 fp2 = manifest2.get(filename, nullid)
468 475
469 if fp2 != nullid: 476 meta = {}
477 cp = self.dirstate.copied(filename)
478 if cp:
479 meta["copy"] = cp
480 if not manifest2: # not a branch merge
481 meta["copyrev"] = hex(manifest1.get(cp, nullid))
482 fp2 = nullid
483 elif fp2 != nullid: # copied on remote side
484 meta["copyrev"] = hex(manifest1.get(cp, nullid))
485 else: # copied on local side, reversed
486 meta["copyrev"] = hex(manifest2.get(cp))
487 fp2 = nullid
488 self.ui.debug(_(" %s: copy %s:%s\n") %
489 (filename, cp, meta["copyrev"]))
490 fp1 = nullid
491 elif fp2 != nullid:
470 # is one parent an ancestor of the other? 492 # is one parent an ancestor of the other?
471 fpa = filelog.ancestor(fp1, fp2) 493 fpa = filelog.ancestor(fp1, fp2)
472 if fpa == fp1: 494 if fpa == fp1:
473 fp1, fp2 = fp2, nullid 495 fp1, fp2 = fp2, nullid
474 elif fpa == fp2: 496 elif fpa == fp2:
475 fp2 = nullid 497 fp2 = nullid
476 498
477 # is the file unmodified from the parent? report existing entry 499 # is the file unmodified from the parent? report existing entry
500 # fixme: use filelog.cmp()
478 if fp2 == nullid and text == filelog.read(fp1): 501 if fp2 == nullid and text == filelog.read(fp1):
479 return (fp1, None, None) 502 return (fp1, None, None, {})
480 503
481 return (None, fp1, fp2) 504 return (None, fp1, fp2, meta)
482 505
483 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None): 506 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None):
484 orig_parent = self.dirstate.parents()[0] or nullid 507 orig_parent = self.dirstate.parents()[0] or nullid
485 p1 = p1 or self.dirstate.parents()[0] or nullid 508 p1 = p1 or self.dirstate.parents()[0] or nullid
486 p2 = p2 or self.dirstate.parents()[1] or nullid 509 p2 = p2 or self.dirstate.parents()[1] or nullid
504 try: 527 try:
505 t = self.wread(f) 528 t = self.wread(f)
506 m1.set(f, util.is_exec(self.wjoin(f), m1.execf(f))) 529 m1.set(f, util.is_exec(self.wjoin(f), m1.execf(f)))
507 r = self.file(f) 530 r = self.file(f)
508 531
509 (entry, fp1, fp2) = self.checkfilemerge(f, t, r, m1, m2) 532 entry, fp1, fp2, meta = self.checkfilemerge(f, t, r, m1, m2)
510 if entry: 533 if entry:
511 m1[f] = entry 534 m1[f] = entry
512 continue 535 continue
513 536
514 m1[f] = r.add(t, {}, tr, linkrev, fp1, fp2) 537 m1[f] = r.add(t, meta, tr, linkrev, fp1, fp2)
515 changed.append(f) 538 changed.append(f)
516 if update_dirstate: 539 if update_dirstate:
517 self.dirstate.update([f], "n") 540 self.dirstate.update([f], "n")
518 except IOError: 541 except IOError:
519 try: 542 try:
587 self.ui.warn(_("trouble committing %s!\n") % f) 610 self.ui.warn(_("trouble committing %s!\n") % f)
588 raise 611 raise
589 612
590 r = self.file(f) 613 r = self.file(f)
591 614
592 meta = {} 615 entry, fp1, fp2, meta = self.checkfilemerge(f, t, r, m1, m2)
593 cp = self.dirstate.copied(f) 616 if entry:
594 if cp: 617 new[f] = entry
595 meta["copy"] = cp 618 continue
596 meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid)))
597 self.ui.debug(_(" %s: copy %s:%s\n") % (f, cp, meta["copyrev"]))
598 fp1, fp2 = nullid, nullid
599 else:
600 entry, fp1, fp2 = self.checkfilemerge(f, t, r, m1, m2)
601 if entry:
602 new[f] = entry
603 continue
604 619
605 new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) 620 new[f] = r.add(t, meta, tr, linkrev, fp1, fp2)
606 # remember what we've added so that we can later calculate 621 # remember what we've added so that we can later calculate
607 # the files to pull from a set of changesets 622 # the files to pull from a set of changesets
608 changed.append(f) 623 changed.append(f)