comparison rhodecode/lib/diffs.py @ 2362:3c4afb8894bd codereview

Improved cross repos diffs - added logging - fixed branch issues and empty bundle case
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 30 May 2012 22:23:23 +0200
parents 948c16bb9476
children 9d61aad859bc
comparison
equal deleted inserted replaced
2361:948c16bb9476 2362:3c4afb8894bd
544 Returns tuple of added, and removed lines for this instance 544 Returns tuple of added, and removed lines for this instance
545 """ 545 """
546 return self.adds, self.removes 546 return self.adds, self.removes
547 547
548 548
549 class InMemoryBundleRepo(bundlerepository):
550 def __init__(self, ui, path, bundlestream):
551 self._tempparent = None
552 localrepo.localrepository.__init__(self, ui, path)
553 self.ui.setconfig('phases', 'publish', False)
554
555 self.bundle = bundlestream
556
557 # dict with the mapping 'filename' -> position in the bundle
558 self.bundlefilespos = {}
559
560
549 def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None): 561 def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None):
550 """ 562 """
551 General differ between branches, bookmarks or separate but releated 563 General differ between branches, bookmarks or separate but releated
552 repositories 564 repositories
553 565
559 :type other_repo: 571 :type other_repo:
560 :param other_ref: 572 :param other_ref:
561 :type other_ref: 573 :type other_ref:
562 """ 574 """
563 575
564 ignore_whitespace = False 576 bundlerepo = ignore_whitespace = False
565 context = 3 577 context = 3
566 org_repo = org_repo.scm_instance._repo 578 org_repo = org_repo.scm_instance._repo
567 other_repo = other_repo.scm_instance._repo 579 other_repo = other_repo.scm_instance._repo
568 opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) 580 opts = diffopts(git=True, ignorews=ignore_whitespace, context=context)
569 org_ref = org_ref[1] 581 org_ref = org_ref[1]
570 other_ref = other_ref[1] 582 other_ref = other_ref[1]
571 583
572 if org_repo != other_repo: 584 if org_repo != other_repo:
573 585
574 common, incoming, rheads = discovery_data 586 common, incoming, rheads = discovery_data
587
575 # create a bundle (uncompressed if other repo is not local) 588 # create a bundle (uncompressed if other repo is not local)
576 if other_repo.capable('getbundle'): 589 if other_repo.capable('getbundle') and incoming:
577 # disable repo hooks here since it's just bundle ! 590 # disable repo hooks here since it's just bundle !
578 # patch and reset hooks section of UI config to not run any 591 # patch and reset hooks section of UI config to not run any
579 # hooks on fetching archives with subrepos 592 # hooks on fetching archives with subrepos
580 for k, _ in other_repo.ui.configitems('hooks'): 593 for k, _ in other_repo.ui.configitems('hooks'):
581 other_repo.ui.setconfig('hooks', k, None) 594 other_repo.ui.setconfig('hooks', k, None)
591 buf.write(chunk) 604 buf.write(chunk)
592 605
593 buf.seek(0) 606 buf.seek(0)
594 unbundle._stream = buf 607 unbundle._stream = buf
595 608
596 class InMemoryBundleRepo(bundlerepository): 609 ui = make_ui('db')
597 def __init__(self, ui, path, bundlestream): 610 bundlerepo = InMemoryBundleRepo(ui, path=org_repo.root,
598 self._tempparent = None 611 bundlestream=unbundle)
599 localrepo.localrepository.__init__(self, ui, path) 612 return ''.join(patch.diff(bundlerepo or org_repo, node2=other_ref, opts=opts))
600 self.ui.setconfig('phases', 'publish', False)
601
602 self.bundle = bundlestream
603
604 # dict with the mapping 'filename' -> position in the bundle
605 self.bundlefilespos = {}
606
607 ui = make_ui('db')
608 bundlerepo = InMemoryBundleRepo(ui, path=other_repo.root,
609 bundlestream=unbundle)
610 return ''.join(patch.diff(bundlerepo, node1=org_ref, node2=other_ref,
611 opts=opts))
612 else: 613 else:
613 return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, 614 return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref,
614 opts=opts)) 615 opts=opts))